Search in sources :

Example 1 with IEInventoryHandler

use of blusunrize.immersiveengineering.common.util.inventory.IEInventoryHandler in project Immersive-Tech by FerroO2000.

the class BlockITTileProvider method breakBlock.

@Override
public void breakBlock(World world, BlockPos pos, IBlockState state) {
    TileEntity tile = world.getTileEntity(pos);
    if (tile != null && (!(tile instanceof ITileDrop) || !((ITileDrop) tile).preventInventoryDrop()) && tile.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)) {
        IItemHandler h = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
        if (h instanceof IEInventoryHandler)
            for (int i = 0; i < h.getSlots(); i++) if (h.getStackInSlot(i) != null) {
                spawnAsEntity(world, pos, h.getStackInSlot(i));
                ((IEInventoryHandler) h).setStackInSlot(i, null);
            }
    }
    if (tile instanceof IHasDummyBlocks) {
        ((IHasDummyBlocks) tile).breakDummies(pos, state);
    }
    if (tile instanceof IImmersiveConnectable)
        if (!world.isRemote || !Minecraft.getMinecraft().isSingleplayer())
            ImmersiveNetHandler.INSTANCE.clearAllConnectionsFor(Utils.toCC(tile), world, !world.isRemote && world.getGameRules().getBoolean("doTileDrops"));
    super.breakBlock(world, pos, state);
    world.removeTileEntity(pos);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IEInventoryHandler(blusunrize.immersiveengineering.common.util.inventory.IEInventoryHandler) IItemHandler(net.minecraftforge.items.IItemHandler) ITileDrop(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.ITileDrop) IImmersiveConnectable(blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable) IHasDummyBlocks(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IHasDummyBlocks)

Example 2 with IEInventoryHandler

use of blusunrize.immersiveengineering.common.util.inventory.IEInventoryHandler in project ImmersiveEngineering by BluSunrize.

the class BlockIETileProvider method getDrops.

@Override
public void getDrops(NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos, IBlockState state, int fortune) // public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune)
{
    TileEntity tile = world.getTileEntity(pos);
    DimensionBlockPos dpos = new DimensionBlockPos(pos, world instanceof World ? ((World) world).provider.getDimension() : 0);
    if (tile == null && tempTile.containsKey(dpos))
        tile = tempTile.get(dpos);
    if (tile != null && (!(tile instanceof ITileDrop) || !((ITileDrop) tile).preventInventoryDrop())) {
        if (tile instanceof IIEInventory && ((IIEInventory) tile).getDroppedItems() != null) {
            for (ItemStack s : ((IIEInventory) tile).getDroppedItems()) if (!s.isEmpty())
                drops.add(s);
        } else if (tile.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)) {
            IItemHandler h = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
            if (h instanceof IEInventoryHandler)
                for (int i = 0; i < h.getSlots(); i++) if (!h.getStackInSlot(i).isEmpty()) {
                    drops.add(h.getStackInSlot(i));
                    ((IEInventoryHandler) h).setStackInSlot(i, ItemStack.EMPTY);
                }
        }
    }
    if (tile instanceof ITileDrop) {
        NonNullList<ItemStack> s = ((ITileDrop) tile).getTileDrops(harvesters.get(), state);
        drops.addAll(s);
    } else
        super.getDrops(drops, world, pos, state, fortune);
    tempTile.remove(dpos);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IEInventoryHandler(blusunrize.immersiveengineering.common.util.inventory.IEInventoryHandler) IItemHandler(net.minecraftforge.items.IItemHandler) DimensionBlockPos(blusunrize.immersiveengineering.api.DimensionBlockPos) IIEInventory(blusunrize.immersiveengineering.common.util.inventory.IIEInventory) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IEInventoryHandler (blusunrize.immersiveengineering.common.util.inventory.IEInventoryHandler)2 TileEntity (net.minecraft.tileentity.TileEntity)2 IItemHandler (net.minecraftforge.items.IItemHandler)2 DimensionBlockPos (blusunrize.immersiveengineering.api.DimensionBlockPos)1 IImmersiveConnectable (blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable)1 IHasDummyBlocks (blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IHasDummyBlocks)1 ITileDrop (blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.ITileDrop)1 IIEInventory (blusunrize.immersiveengineering.common.util.inventory.IIEInventory)1 ItemStack (net.minecraft.item.ItemStack)1 World (net.minecraft.world.World)1