From fbd4854f300a63ab628e8c846b2b8810a9c02871 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Thu, 12 Apr 2018 13:42:55 +0100 Subject: [PATCH] Fixes #1480 --- .../blocks/storage/BlockEnergyStorage.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/main/java/techreborn/blocks/storage/BlockEnergyStorage.java b/src/main/java/techreborn/blocks/storage/BlockEnergyStorage.java index 1af104a25..9ed14cdce 100644 --- a/src/main/java/techreborn/blocks/storage/BlockEnergyStorage.java +++ b/src/main/java/techreborn/blocks/storage/BlockEnergyStorage.java @@ -26,6 +26,8 @@ package techreborn.blocks.storage; import com.google.common.base.Predicate; import com.google.common.collect.Iterators; +import net.minecraft.block.BlockDynamicLiquid; +import net.minecraft.block.BlockStaticLiquid; import net.minecraft.block.material.Material; import net.minecraft.block.properties.PropertyDirection; import net.minecraft.block.state.BlockStateContainer; @@ -33,6 +35,8 @@ import net.minecraft.block.state.IBlockState; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; @@ -40,17 +44,22 @@ import net.minecraft.util.EnumHand; import net.minecraft.util.SoundCategory; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import net.minecraftforge.fluids.BlockFluidBase; import prospector.shootingstar.ShootingStar; import prospector.shootingstar.model.ModelCompound; import reborncore.api.IToolDrop; import reborncore.api.ToolManager; +import reborncore.api.tile.IUpgradeable; import reborncore.common.BaseTileBlock; +import reborncore.common.util.WorldUtils; import techreborn.Core; import techreborn.client.TechRebornCreativeTab; import techreborn.init.ModSounds; import techreborn.lib.ModInfo; +import java.util.ArrayList; import java.util.Iterator; +import java.util.List; import java.util.Random; /** @@ -80,6 +89,7 @@ public abstract class BlockEnergyStorage extends BaseTileBlock { if (player.isSneaking()) { TileEntity tileEntity = world.getTileEntity(pos); if (tileEntity instanceof IToolDrop) { + dropInventory(world, pos); ItemStack drop = ((IToolDrop) tileEntity).getToolDrop(player); if (drop == null) { return false; @@ -113,6 +123,45 @@ public abstract class BlockEnergyStorage extends BaseTileBlock { return super.onBlockActivated(world, pos, state, player, hand, side, hitX, hitY, hitZ); } + protected void dropInventory(World world, BlockPos pos) { + TileEntity tileEntity = world.getTileEntity(pos); + + if (tileEntity == null) { + return; + } + if (!(tileEntity instanceof IInventory)) { + return; + } + + IInventory inventory = (IInventory) tileEntity; + List items = new ArrayList(); + addItemsToList(inventory, items); + if (tileEntity instanceof IUpgradeable) { + addItemsToList(((IUpgradeable) tileEntity).getUpgradeInvetory(), items); + } + WorldUtils.dropItems(items, world, pos); + } + + private void addItemsToList(IInventory inventory, List items) { + for (int i = 0; i < inventory.getSizeInventory(); i++) { + ItemStack itemStack = inventory.getStackInSlot(i); + + if (itemStack == ItemStack.EMPTY) { + continue; + } + if (itemStack != ItemStack.EMPTY && itemStack.getCount() > 0) { + if (itemStack.getItem() instanceof ItemBlock) { + if (((ItemBlock) itemStack.getItem()).getBlock() instanceof BlockFluidBase + || ((ItemBlock) itemStack.getItem()).getBlock() instanceof BlockStaticLiquid + || ((ItemBlock) itemStack.getItem()).getBlock() instanceof BlockDynamicLiquid) { + continue; + } + } + } + items.add(itemStack.copy()); + } + } + @Override protected BlockStateContainer createBlockState() { FACING = PropertyDirection.create("facing", Facings.ALL);