From f15ac5d100d02a763c17b37ef0ad4f56c4e4fd5b Mon Sep 17 00:00:00 2001 From: Buuz135 Date: Sun, 11 Nov 2018 17:35:51 +0100 Subject: [PATCH] Fixed black hole tanks not writing nbt fluid when placed, closes #451 --- .../tile/block/BlackHoleTankBlock.java | 22 ++++++++++++++++-- .../tile/block/BlackHoleUnitBlock.java | 23 ++++++++++++++----- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/buuz135/industrial/tile/block/BlackHoleTankBlock.java b/src/main/java/com/buuz135/industrial/tile/block/BlackHoleTankBlock.java index 9c8106dcc..66219904b 100644 --- a/src/main/java/com/buuz135/industrial/tile/block/BlackHoleTankBlock.java +++ b/src/main/java/com/buuz135/industrial/tile/block/BlackHoleTankBlock.java @@ -27,6 +27,7 @@ import com.buuz135.industrial.utils.RecipeUtils; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; import net.minecraft.item.Item; @@ -49,6 +50,7 @@ import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import net.ndrei.teslacorelib.items.MachineCaseItem; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.List; @@ -70,6 +72,11 @@ public void createRecipe() { @Override public void getDrops(NonNullList drops, IBlockAccess world, BlockPos pos, IBlockState state, int fortune) { + + } + + @Override + public void breakBlock(@NotNull World world, @NotNull BlockPos pos, @NotNull IBlockState state) { if (world.getTileEntity(pos) instanceof BlackHoleTankTile) { BlackHoleTankTile tile = (BlackHoleTankTile) world.getTileEntity(pos); ItemStack stack = new ItemStack(Item.getItemFromBlock(this), 1); @@ -79,8 +86,18 @@ public void getDrops(NonNullList drops, IBlockAccess world, BlockPos stack.setTagCompound(tile.getTank().getFluid().writeToNBT(new NBTTagCompound())); } } - drops.add(stack); + float f = 0.7F; + float d0 = world.rand.nextFloat() * f + (1.0F - f) * 0.5F; + float d1 = world.rand.nextFloat() * f + (1.0F - f) * 0.5F; + float d2 = world.rand.nextFloat() * f + (1.0F - f) * 0.5F; + EntityItem entityitem = new EntityItem(world, pos.getX() + d0, pos.getY() + d1, pos.getZ() + d2, stack); + entityitem.setDefaultPickupDelay(); + if (stack.hasTagCompound()) { + entityitem.getItem().setTagCompound(stack.getTagCompound().copy()); + } + world.spawnEntity(entityitem); } + super.breakBlock(world, pos, state); } @Override @@ -88,7 +105,8 @@ public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, Entity super.onBlockPlacedBy(world, pos, state, placer, stack); if (stack.hasTagCompound() && world.getTileEntity(pos) != null && world.getTileEntity(pos) instanceof BlackHoleTankTile && FluidRegistry.isFluidRegistered(stack.getTagCompound().getString("FluidName"))) { BlackHoleTankTile tile = (BlackHoleTankTile) world.getTileEntity(pos); - tile.getTank().fill(new FluidStack(FluidRegistry.getFluid(stack.getTagCompound().getString("FluidName")), stack.getTagCompound().getInteger("Amount")), true); + System.out.println(stack.getTagCompound()); + tile.getTank().fill(new FluidStack(FluidRegistry.getFluid(stack.getTagCompound().getString("FluidName")), stack.getTagCompound().getInteger("Amount"), stack.getTagCompound().getCompoundTag("Tag")), true); } } diff --git a/src/main/java/com/buuz135/industrial/tile/block/BlackHoleUnitBlock.java b/src/main/java/com/buuz135/industrial/tile/block/BlackHoleUnitBlock.java index 55483186d..e13966fb6 100644 --- a/src/main/java/com/buuz135/industrial/tile/block/BlackHoleUnitBlock.java +++ b/src/main/java/com/buuz135/industrial/tile/block/BlackHoleUnitBlock.java @@ -28,6 +28,7 @@ import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.item.EntityItem; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -49,11 +50,6 @@ public BlackHoleUnitBlock() { @Override public void breakBlock(World world, BlockPos pos, IBlockState state) { - world.removeTileEntity(pos); - } - - @Override - public void getDrops(NonNullList drops, IBlockAccess world, BlockPos pos, IBlockState state, int fortune) { if (world.getTileEntity(pos) instanceof BlackHoleUnitTile) { BlackHoleUnitTile tile = (BlackHoleUnitTile) world.getTileEntity(pos); ItemStack stack = new ItemStack(Item.getItemFromBlock(this), 1); @@ -65,8 +61,23 @@ public void getDrops(NonNullList drops, IBlockAccess world, BlockPos if (tile.getItemStack().hasTagCompound()) stack.getTagCompound().setTag(BlackHoleUnitTile.NBT_ITEM_NBT, tile.getItemStack().getTagCompound()); } - drops.add(stack); + float f = 0.7F; + float d0 = world.rand.nextFloat() * f + (1.0F - f) * 0.5F; + float d1 = world.rand.nextFloat() * f + (1.0F - f) * 0.5F; + float d2 = world.rand.nextFloat() * f + (1.0F - f) * 0.5F; + EntityItem entityitem = new EntityItem(world, pos.getX() + d0, pos.getY() + d1, pos.getZ() + d2, stack); + entityitem.setDefaultPickupDelay(); + if (stack.hasTagCompound()) { + entityitem.getItem().setTagCompound(stack.getTagCompound().copy()); + } + world.spawnEntity(entityitem); } + world.removeTileEntity(pos); + } + + @Override + public void getDrops(NonNullList drops, IBlockAccess world, BlockPos pos, IBlockState state, int fortune) { + } @Override