Search in sources :

Example 1 with IIEInventory

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

the class BlockIETileProvider 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())) {
        if (tile instanceof IIEInventory && ((IIEInventory) tile).getDroppedItems() != null) {
            for (ItemStack s : ((IIEInventory) tile).getDroppedItems()) if (s != null)
                spawnAsEntity(world, pos, 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) != 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) IImmersiveConnectable(blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable) IIEInventory(blusunrize.immersiveengineering.common.util.inventory.IIEInventory) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IImmersiveConnectable (blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable)1 IEInventoryHandler (blusunrize.immersiveengineering.common.util.inventory.IEInventoryHandler)1 IIEInventory (blusunrize.immersiveengineering.common.util.inventory.IIEInventory)1 ItemStack (net.minecraft.item.ItemStack)1 TileEntity (net.minecraft.tileentity.TileEntity)1 IItemHandler (net.minecraftforge.items.IItemHandler)1