From da8e43a8b494df393687af91415a69f8b10db227 Mon Sep 17 00:00:00 2001 From: Nicholas Ignoffo Date: Tue, 24 Apr 2018 17:06:43 -0700 Subject: [PATCH] Fix Blood Tank NBT transfer between item/tile form (#1283) --- .../bloodmagic/block/BlockBloodTank.java | 26 +++++++++---------- .../item/block/ItemBlockBloodTank.java | 5 ++-- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/main/java/WayofTime/bloodmagic/block/BlockBloodTank.java b/src/main/java/WayofTime/bloodmagic/block/BlockBloodTank.java index b9dfe15d..9140427b 100644 --- a/src/main/java/WayofTime/bloodmagic/block/BlockBloodTank.java +++ b/src/main/java/WayofTime/bloodmagic/block/BlockBloodTank.java @@ -5,7 +5,6 @@ import WayofTime.bloodmagic.block.base.BlockInteger; import WayofTime.bloodmagic.client.IVariantProvider; import WayofTime.bloodmagic.item.block.ItemBlockBloodTank; import WayofTime.bloodmagic.tile.TileBloodTank; -import com.google.common.collect.Lists; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; @@ -20,6 +19,7 @@ import net.minecraft.util.BlockRenderLayer; import net.minecraft.util.EnumBlockRenderType; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; +import net.minecraft.util.NonNullList; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; @@ -32,7 +32,6 @@ import net.minecraftforge.fml.relauncher.SideOnly; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import java.util.List; public class BlockBloodTank extends BlockInteger implements IVariantProvider, IBMBlock { public static final AxisAlignedBB BOX = new AxisAlignedBB(0.25, 0, 0.25, 0.75, 0.8, 0.75); @@ -113,23 +112,22 @@ public class BlockBloodTank extends BlockInteger implements IVariantProvider, IB } @Override - public List getDrops(IBlockAccess world, BlockPos pos, IBlockState blockState, int fortune) { - List list = Lists.newArrayList(); - + public void getDrops(NonNullList drops, IBlockAccess world, BlockPos pos, IBlockState blockState, int fortune) { TileEntity tile = world.getTileEntity(pos); if (tile instanceof TileBloodTank) { TileBloodTank bloodTank = (TileBloodTank) tile; ItemStack drop = new ItemStack(this, 1, bloodTank.getBlockMetadata()); - NBTTagCompound tag = new NBTTagCompound(); + NBTTagCompound fluidTag = new NBTTagCompound(); - if (bloodTank.getTank().getFluid() != null) - bloodTank.getTank().getFluid().writeToNBT(tag); + if (bloodTank.getTank().getFluid() != null) { + bloodTank.getTank().getFluid().writeToNBT(fluidTag); + NBTTagCompound dropTag = new NBTTagCompound(); + dropTag.setTag("Fluid", fluidTag); + drop.setTagCompound(dropTag); + } - drop.setTagCompound(tag); - list.add(drop); + drops.add(drop); } - - return list; } @Override @@ -138,8 +136,8 @@ public class BlockBloodTank extends BlockInteger implements IVariantProvider, IB if (tile instanceof TileBloodTank) { TileBloodTank bloodTank = (TileBloodTank) tile; NBTTagCompound tag = stack.getTagCompound(); - if (tag != null) { - FluidStack fluidStack = FluidStack.loadFluidStackFromNBT(tag); + if (stack.hasTagCompound() && stack.getTagCompound().hasKey("Fluid")) { + FluidStack fluidStack = FluidStack.loadFluidStackFromNBT(tag.getCompoundTag("Fluid")); bloodTank.getTank().setFluid(fluidStack); } } diff --git a/src/main/java/WayofTime/bloodmagic/item/block/ItemBlockBloodTank.java b/src/main/java/WayofTime/bloodmagic/item/block/ItemBlockBloodTank.java index 0e8bb21d..f614ed34 100644 --- a/src/main/java/WayofTime/bloodmagic/item/block/ItemBlockBloodTank.java +++ b/src/main/java/WayofTime/bloodmagic/item/block/ItemBlockBloodTank.java @@ -47,9 +47,8 @@ public class ItemBlockBloodTank extends ItemBlock { public void addInformation(ItemStack stack, World world, List tooltip, ITooltipFlag flag) { tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.tier", stack.getItemDamage() + 1)); tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.fluid.capacity", getCapacity(stack))); - if (stack.hasTagCompound()) { - NBTTagCompound tag = stack.getTagCompound(); - FluidStack fluidStack = FluidStack.loadFluidStackFromNBT(tag); + if (stack.hasTagCompound() && stack.getTagCompound().hasKey("Fluid")) { + FluidStack fluidStack = FluidStack.loadFluidStackFromNBT(stack.getTagCompound().getCompoundTag("Fluid")); if (fluidStack != null) { tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.fluid.type", fluidStack.getLocalizedName())); tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.fluid.amount", fluidStack.amount, getCapacity(stack)));