This commit is contained in:
modmuss50 2018-04-12 13:42:55 +01:00
parent fef10740ba
commit fbd4854f30
No known key found for this signature in database
GPG key ID: 773D17BE8BF49C82

View file

@ -26,6 +26,8 @@ package techreborn.blocks.storage;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.Iterators; 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.material.Material;
import net.minecraft.block.properties.PropertyDirection; import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockStateContainer; 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.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
@ -40,17 +44,22 @@ import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundCategory; import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.fluids.BlockFluidBase;
import prospector.shootingstar.ShootingStar; import prospector.shootingstar.ShootingStar;
import prospector.shootingstar.model.ModelCompound; import prospector.shootingstar.model.ModelCompound;
import reborncore.api.IToolDrop; import reborncore.api.IToolDrop;
import reborncore.api.ToolManager; import reborncore.api.ToolManager;
import reborncore.api.tile.IUpgradeable;
import reborncore.common.BaseTileBlock; import reborncore.common.BaseTileBlock;
import reborncore.common.util.WorldUtils;
import techreborn.Core; import techreborn.Core;
import techreborn.client.TechRebornCreativeTab; import techreborn.client.TechRebornCreativeTab;
import techreborn.init.ModSounds; import techreborn.init.ModSounds;
import techreborn.lib.ModInfo; import techreborn.lib.ModInfo;
import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
import java.util.Random; import java.util.Random;
/** /**
@ -80,6 +89,7 @@ public abstract class BlockEnergyStorage extends BaseTileBlock {
if (player.isSneaking()) { if (player.isSneaking()) {
TileEntity tileEntity = world.getTileEntity(pos); TileEntity tileEntity = world.getTileEntity(pos);
if (tileEntity instanceof IToolDrop) { if (tileEntity instanceof IToolDrop) {
dropInventory(world, pos);
ItemStack drop = ((IToolDrop) tileEntity).getToolDrop(player); ItemStack drop = ((IToolDrop) tileEntity).getToolDrop(player);
if (drop == null) { if (drop == null) {
return false; return false;
@ -113,6 +123,45 @@ public abstract class BlockEnergyStorage extends BaseTileBlock {
return super.onBlockActivated(world, pos, state, player, hand, side, hitX, hitY, hitZ); 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 @Override
protected BlockStateContainer createBlockState() { protected BlockStateContainer createBlockState() {
FACING = PropertyDirection.create("facing", Facings.ALL); FACING = PropertyDirection.create("facing", Facings.ALL);