Skip to content

Commit

Permalink
Fix crash with null fluid stack (#193)
Browse files Browse the repository at this point in the history
* fix crash with null fluid stack

* change minimum stack size in bookmarks

Co-authored-by: Serghei Borovetchi <[email protected]>
  • Loading branch information
slprime and Serghei Borovetchi authored Jan 7, 2022
1 parent 2d18dcf commit 144a37c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
14 changes: 5 additions & 9 deletions src/main/java/codechicken/nei/BookmarkPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -281,15 +281,11 @@ public void addOrRemoveItem(ItemStack stackover, String handlerName, List<Positi
for (PositionedStack stack : ingredients) {
final NBTTagCompound nbTag = StackInfo.itemStackToNBT(stack.item, saveStackSize);

if (nbTag.getInteger("Count") > 0) {

if (unique.get(nbTag) == null) {
unique.put(nbTag, 1);
sorted.add(nbTag);
} else if (saveStackSize) {
unique.put(nbTag, unique.get(nbTag) + 1);
}

if (unique.get(nbTag) == null) {
unique.put(nbTag, 1);
sorted.add(nbTag);
} else if (saveStackSize) {
unique.put(nbTag, unique.get(nbTag) + 1);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@ public class DefaultStackStringifyHandler implements IStackStringifyHandler

public NBTTagCompound convertItemStackToNBT(ItemStack stack, boolean saveStackSize)
{
final String strId = Item.itemRegistry.getNameForObject(stack.getItem());

if (strId == null) {
return null;
}

final NBTTagCompound nbTag = new NBTTagCompound();
nbTag.setString("strId", Item.itemRegistry.getNameForObject(stack.getItem()));
nbTag.setInteger("Count", saveStackSize? stack.stackSize: 1);
nbTag.setString("strId", strId);
nbTag.setInteger("Count", Math.max(saveStackSize? stack.stackSize: 1, 1));
nbTag.setShort("Damage", (short)stack.getItemDamage());

if (stack.hasTagCompound()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@ public NBTTagCompound convertItemStackToNBT(ItemStack stack, boolean saveStackSi
{

if (GTDisplayFluid != null && GTDisplayFluid.isInstance(stack.getItem())) {
final NBTTagCompound nbTag = new NBTTagCompound();
final FluidStack fluidStack = getFluid(stack);

nbTag.setString("gtFluidName", fluidStack.getFluid().getName());
nbTag.setInteger("Count", saveStackSize? fluidStack.amount: 1);
return nbTag;
if (fluidStack != null) {
final NBTTagCompound nbTag = new NBTTagCompound();
nbTag.setString("gtFluidName", fluidStack.getFluid().getName());
nbTag.setInteger("Count", saveStackSize? fluidStack.amount: 1);
return nbTag;
}

}

return null;
Expand Down

0 comments on commit 144a37c

Please sign in to comment.