Fix Blood Tank NBT transfer between item/tile form (#1283)
This commit is contained in:
parent
6522b0fa1b
commit
da8e43a8b4
|
@ -5,7 +5,6 @@ import WayofTime.bloodmagic.block.base.BlockInteger;
|
||||||
import WayofTime.bloodmagic.client.IVariantProvider;
|
import WayofTime.bloodmagic.client.IVariantProvider;
|
||||||
import WayofTime.bloodmagic.item.block.ItemBlockBloodTank;
|
import WayofTime.bloodmagic.item.block.ItemBlockBloodTank;
|
||||||
import WayofTime.bloodmagic.tile.TileBloodTank;
|
import WayofTime.bloodmagic.tile.TileBloodTank;
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||||
import net.minecraft.block.SoundType;
|
import net.minecraft.block.SoundType;
|
||||||
import net.minecraft.block.material.Material;
|
import net.minecraft.block.material.Material;
|
||||||
|
@ -20,6 +19,7 @@ import net.minecraft.util.BlockRenderLayer;
|
||||||
import net.minecraft.util.EnumBlockRenderType;
|
import net.minecraft.util.EnumBlockRenderType;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.EnumHand;
|
import net.minecraft.util.EnumHand;
|
||||||
|
import net.minecraft.util.NonNullList;
|
||||||
import net.minecraft.util.math.AxisAlignedBB;
|
import net.minecraft.util.math.AxisAlignedBB;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.RayTraceResult;
|
import net.minecraft.util.math.RayTraceResult;
|
||||||
|
@ -32,7 +32,6 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class BlockBloodTank extends BlockInteger implements IVariantProvider, IBMBlock {
|
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);
|
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
|
@Override
|
||||||
public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState blockState, int fortune) {
|
public void getDrops(NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos, IBlockState blockState, int fortune) {
|
||||||
List<ItemStack> list = Lists.newArrayList();
|
|
||||||
|
|
||||||
TileEntity tile = world.getTileEntity(pos);
|
TileEntity tile = world.getTileEntity(pos);
|
||||||
if (tile instanceof TileBloodTank) {
|
if (tile instanceof TileBloodTank) {
|
||||||
TileBloodTank bloodTank = (TileBloodTank) tile;
|
TileBloodTank bloodTank = (TileBloodTank) tile;
|
||||||
ItemStack drop = new ItemStack(this, 1, bloodTank.getBlockMetadata());
|
ItemStack drop = new ItemStack(this, 1, bloodTank.getBlockMetadata());
|
||||||
NBTTagCompound tag = new NBTTagCompound();
|
NBTTagCompound fluidTag = new NBTTagCompound();
|
||||||
|
|
||||||
if (bloodTank.getTank().getFluid() != null)
|
if (bloodTank.getTank().getFluid() != null) {
|
||||||
bloodTank.getTank().getFluid().writeToNBT(tag);
|
bloodTank.getTank().getFluid().writeToNBT(fluidTag);
|
||||||
|
NBTTagCompound dropTag = new NBTTagCompound();
|
||||||
|
dropTag.setTag("Fluid", fluidTag);
|
||||||
|
drop.setTagCompound(dropTag);
|
||||||
|
}
|
||||||
|
|
||||||
drop.setTagCompound(tag);
|
drops.add(drop);
|
||||||
list.add(drop);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -138,8 +136,8 @@ public class BlockBloodTank extends BlockInteger implements IVariantProvider, IB
|
||||||
if (tile instanceof TileBloodTank) {
|
if (tile instanceof TileBloodTank) {
|
||||||
TileBloodTank bloodTank = (TileBloodTank) tile;
|
TileBloodTank bloodTank = (TileBloodTank) tile;
|
||||||
NBTTagCompound tag = stack.getTagCompound();
|
NBTTagCompound tag = stack.getTagCompound();
|
||||||
if (tag != null) {
|
if (stack.hasTagCompound() && stack.getTagCompound().hasKey("Fluid")) {
|
||||||
FluidStack fluidStack = FluidStack.loadFluidStackFromNBT(tag);
|
FluidStack fluidStack = FluidStack.loadFluidStackFromNBT(tag.getCompoundTag("Fluid"));
|
||||||
bloodTank.getTank().setFluid(fluidStack);
|
bloodTank.getTank().setFluid(fluidStack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,9 +47,8 @@ public class ItemBlockBloodTank extends ItemBlock {
|
||||||
public void addInformation(ItemStack stack, World world, List<String> tooltip, ITooltipFlag flag) {
|
public void addInformation(ItemStack stack, World world, List<String> tooltip, ITooltipFlag flag) {
|
||||||
tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.tier", stack.getItemDamage() + 1));
|
tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.tier", stack.getItemDamage() + 1));
|
||||||
tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.fluid.capacity", getCapacity(stack)));
|
tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.fluid.capacity", getCapacity(stack)));
|
||||||
if (stack.hasTagCompound()) {
|
if (stack.hasTagCompound() && stack.getTagCompound().hasKey("Fluid")) {
|
||||||
NBTTagCompound tag = stack.getTagCompound();
|
FluidStack fluidStack = FluidStack.loadFluidStackFromNBT(stack.getTagCompound().getCompoundTag("Fluid"));
|
||||||
FluidStack fluidStack = FluidStack.loadFluidStackFromNBT(tag);
|
|
||||||
if (fluidStack != null) {
|
if (fluidStack != null) {
|
||||||
tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.fluid.type", fluidStack.getLocalizedName()));
|
tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.fluid.type", fluidStack.getLocalizedName()));
|
||||||
tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.fluid.amount", fluidStack.amount, getCapacity(stack)));
|
tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.fluid.amount", fluidStack.amount, getCapacity(stack)));
|
||||||
|
|
Loading…
Reference in a new issue