Search in sources :

Example 1 with ITileDrop

use of blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.ITileDrop in project Immersive-Tech by FerroO2000.

the class BlockITTileProvider method getPickBlock.

@Override
public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) {
    TileEntity tile = world.getTileEntity(pos);
    if (tile instanceof ITileDrop) {
        ItemStack s = ((ITileDrop) tile).getTileDrop(player, world.getBlockState(pos));
        if (!s.isEmpty())
            return s;
    }
    Item item = Item.getItemFromBlock(this);
    return item == Items.AIR ? ItemStack.EMPTY : new ItemStack(item, 1, this.damageDropped(world.getBlockState(pos)));
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Item(net.minecraft.item.Item) ITileDrop(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.ITileDrop) ItemStack(net.minecraft.item.ItemStack)

Example 2 with ITileDrop

use of blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.ITileDrop 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 3 with ITileDrop

use of blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.ITileDrop in project ImmersiveEngineering by BluSunrize.

the class TileEntityMultiblockPart method replaceStructureBlock.

public void replaceStructureBlock(BlockPos pos, IBlockState state, ItemStack stack, int h, int l, int w) {
    if (state.getBlock() == this.getBlockType())
        world.setBlockToAir(pos);
    world.setBlockState(pos, state);
    TileEntity tile = world.getTileEntity(pos);
    if (tile instanceof ITileDrop)
        ((ITileDrop) tile).readOnPlacement(null, stack);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ITileDrop(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.ITileDrop)

Example 4 with ITileDrop

use of blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.ITileDrop in project Immersive-Tech by FerroO2000.

the class BlockITTileProvider method onIEBlockPlacedBy.

@Override
public void onIEBlockPlacedBy(World world, BlockPos pos, IBlockState state, EnumFacing side, float hitX, float hitY, float hitZ, EntityLivingBase placer, ItemStack stack) {
    TileEntity tile = world.getTileEntity(pos);
    if (tile instanceof IDirectionalTile) {
        EnumFacing f = ((IDirectionalTile) tile).getFacingForPlacement(placer, pos, side, hitX, hitY, hitZ);
        ((IDirectionalTile) tile).setFacing(f);
        if (tile instanceof IAdvancedDirectionalTile)
            ((IAdvancedDirectionalTile) tile).onDirectionalPlacement(side, hitX, hitY, hitZ, placer);
    }
    if (tile instanceof IHasDummyBlocks) {
        ((IHasDummyBlocks) tile).placeDummies(pos, state, side, hitX, hitY, hitZ);
    }
    if (tile instanceof ITileDrop) {
        ((ITileDrop) tile).readOnPlacement(placer, stack);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) EnumFacing(net.minecraft.util.EnumFacing) ITileDrop(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.ITileDrop) IHasDummyBlocks(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IHasDummyBlocks) IDirectionalTile(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IDirectionalTile) IAdvancedDirectionalTile(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IAdvancedDirectionalTile)

Example 5 with ITileDrop

use of blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.ITileDrop in project ImmersiveEngineering by BluSunrize.

the class BlockIEMultiblock method breakBlock.

@Override
public void breakBlock(World world, BlockPos pos, IBlockState state) {
    TileEntity tileEntity = world.getTileEntity(pos);
    if (tileEntity instanceof TileEntityMultiblockPart && world.getGameRules().getBoolean("doTileDrops")) {
        TileEntityMultiblockPart tile = (TileEntityMultiblockPart) tileEntity;
        if (!tile.formed && tile.pos == -1 && !tile.getOriginalBlock().isEmpty())
            world.spawnEntity(new EntityItem(world, pos.getX() + .5, pos.getY() + .5, pos.getZ() + .5, tile.getOriginalBlock().copy()));
        if (tile.formed && tile instanceof IIEInventory) {
            IIEInventory master = (IIEInventory) tile.master();
            if (master != null && (!(master instanceof ITileDrop) || !((ITileDrop) master).preventInventoryDrop()) && master.getDroppedItems() != null)
                for (ItemStack s : master.getDroppedItems()) if (!s.isEmpty())
                    world.spawnEntity(new EntityItem(world, pos.getX() + .5, pos.getY() + .5, pos.getZ() + .5, s.copy()));
        }
    }
    if (tileEntity instanceof TileEntityMultiblockPart)
        ((TileEntityMultiblockPart) tileEntity).disassemble();
    super.breakBlock(world, pos, state);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ITileDrop(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.ITileDrop) IIEInventory(blusunrize.immersiveengineering.common.util.inventory.IIEInventory) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Aggregations

ITileDrop (blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.ITileDrop)5 TileEntity (net.minecraft.tileentity.TileEntity)5 IHasDummyBlocks (blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IHasDummyBlocks)2 ItemStack (net.minecraft.item.ItemStack)2 IImmersiveConnectable (blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable)1 IAdvancedDirectionalTile (blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IAdvancedDirectionalTile)1 IDirectionalTile (blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IDirectionalTile)1 IEInventoryHandler (blusunrize.immersiveengineering.common.util.inventory.IEInventoryHandler)1 IIEInventory (blusunrize.immersiveengineering.common.util.inventory.IIEInventory)1 EntityItem (net.minecraft.entity.item.EntityItem)1 Item (net.minecraft.item.Item)1 EnumFacing (net.minecraft.util.EnumFacing)1 IItemHandler (net.minecraftforge.items.IItemHandler)1