Fixes #1480
This commit is contained in:
parent
fef10740ba
commit
fbd4854f30
1 changed files with 49 additions and 0 deletions
|
@ -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<ItemStack> items = new ArrayList<ItemStack>();
|
||||
addItemsToList(inventory, items);
|
||||
if (tileEntity instanceof IUpgradeable) {
|
||||
addItemsToList(((IUpgradeable) tileEntity).getUpgradeInvetory(), items);
|
||||
}
|
||||
WorldUtils.dropItems(items, world, pos);
|
||||
}
|
||||
|
||||
private void addItemsToList(IInventory inventory, List<ItemStack> 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);
|
||||
|
|
Loading…
Reference in a new issue