diff options
author | Glease <4586901+Glease@users.noreply.github.com> | 2021-12-30 19:01:17 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-30 12:01:17 +0100 |
commit | 44f934a34223dff40275e2919fa879bea0baed60 (patch) | |
tree | 8cbb6129a00024f7eff2d3a9d103e170ea8f554f /src/main/java | |
parent | c95aba0f4ea2ec26a756c2b3e2b2662f23120646 (diff) | |
download | GT5-Unofficial-44f934a34223dff40275e2919fa879bea0baed60.tar.gz GT5-Unofficial-44f934a34223dff40275e2919fa879bea0baed60.tar.bz2 GT5-Unofficial-44f934a34223dff40275e2919fa879bea0baed60.zip |
fix tank stacks getting an empty nbt tag now and then (#838)
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/gregtech/common/blocks/GT_Item_Machines.java | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/main/java/gregtech/common/blocks/GT_Item_Machines.java b/src/main/java/gregtech/common/blocks/GT_Item_Machines.java index 74a53c1743..d1e9555ba0 100644 --- a/src/main/java/gregtech/common/blocks/GT_Item_Machines.java +++ b/src/main/java/gregtech/common/blocks/GT_Item_Machines.java @@ -242,6 +242,10 @@ public class GT_Item_Machines extends ItemBlock implements IFluidContainerItem { GregTech_API.METATILEENTITIES[tDamage] instanceof GT_MetaTileEntity_QuantumTank) { NBTTagCompound tNBT = aStack.stackTagCompound; if (tNBT == null) return; + if (tNBT.hasNoTags()) { + aStack.setTagCompound(null); + return; + } if ((tNBT.hasKey("mItemCount") && tNBT.getInteger("mItemCount") > 0) || (tNBT.hasKey("mFluid") && FluidStack.loadFluidStackFromNBT(tNBT.getCompoundTag("mFluid")).amount > 64000)) { FluidStack tFluid = FluidStack.loadFluidStackFromNBT(tNBT.getCompoundTag("mFluid")); @@ -318,21 +322,25 @@ public class GT_Item_Machines extends ItemBlock implements IFluidContainerItem { @Override public FluidStack drain(ItemStack container, int maxDrain, boolean doDrain) { - if (container != null) { + if (container != null && container.hasTagCompound()) { int tDamage = container.getItemDamage(); IMetaTileEntity tMetaTile = GregTech_API.METATILEENTITIES[tDamage]; if (!(tMetaTile instanceof GT_MetaTileEntity_QuantumTank || tMetaTile instanceof GT_MetaTileEntity_SuperTank)) { return null; } - if (container.stackTagCompound == null) container.stackTagCompound = new NBTTagCompound(); FluidStack tStoredFluid = getFluid(container); if (tStoredFluid != null) { int tAmount = Math.min(maxDrain, tStoredFluid.amount); FluidStack tNewFluid = new FluidStack(tStoredFluid, tStoredFluid.amount - tAmount); FluidStack tOutputFluid = new FluidStack(tStoredFluid, tAmount); if (doDrain) { - if (tNewFluid.amount <= 0) container.stackTagCompound.removeTag("mFluid"); - else container.stackTagCompound.setTag("mFluid", tNewFluid.writeToNBT(new NBTTagCompound())); + if (tNewFluid.amount <= 0) { + container.stackTagCompound.removeTag("mFluid"); + if (container.stackTagCompound.hasNoTags()) + container.setTagCompound(null); + } else { + container.stackTagCompound.setTag("mFluid", tNewFluid.writeToNBT(new NBTTagCompound())); + } } return tOutputFluid; } |