Search in sources :

Example 1 with TileEntityToolbox

use of com.codetaylor.mc.artisanworktables.modules.toolbox.tile.TileEntityToolbox in project artisan-worktables by codetaylor.

the class TileEntityBase method getAdjacentToolbox.

/**
 * Searches cardinal directions around all joined tables and returns an adjacent toolbox.
 * <p>
 * If more than one toolbox is found, the first toolbox found is returned.
 * <p>
 * If no toolbox is found, null is returned.
 *
 * @return adjacent toolbox or null
 */
@Nullable
public TileEntityToolbox getAdjacentToolbox() {
    List<TileEntityBase> joinedTables = this.getJoinedTables(new ArrayList<>());
    for (TileEntityBase joinedTable : joinedTables) {
        BlockPos pos = joinedTable.getPos();
        TileEntity tileEntity;
        for (EnumFacing facing : EnumFacing.HORIZONTALS) {
            if ((tileEntity = this.world.getTileEntity(pos.offset(facing))) != null) {
                if (tileEntity instanceof TileEntityToolbox) {
                    return (TileEntityToolbox) tileEntity;
                }
            }
        }
    }
    return null;
}
Also used : SPacketUpdateTileEntity(net.minecraft.network.play.server.SPacketUpdateTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) TileEntityToolbox(com.codetaylor.mc.artisanworktables.modules.toolbox.tile.TileEntityToolbox) Nullable(javax.annotation.Nullable)

Example 2 with TileEntityToolbox

use of com.codetaylor.mc.artisanworktables.modules.toolbox.tile.TileEntityToolbox in project artisan-worktables by codetaylor.

the class BlockToolboxBase method getDrops.

@Override
public void getDrops(NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
    drops.clear();
    TileEntity tileEntity = world.getTileEntity(pos);
    if (tileEntity != null && tileEntity instanceof TileEntityToolbox) {
        boolean dropAllItems = !this.keepContentsWhenBroken();
        if (dropAllItems) {
            drops.addAll(((TileEntityToolbox) tileEntity).getBlockBreakDrops());
        } else {
            ItemStack itemStack = this.getBlockAsItemStack();
            NBTTagCompound compound = new NBTTagCompound();
            NBTTagCompound teCompound = new NBTTagCompound();
            tileEntity.writeToNBT(teCompound);
            compound.setTag("BlockEntityTag", teCompound);
            itemStack.setTagCompound(compound);
            drops.clear();
            drops.add(itemStack);
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) TileEntityToolbox(com.codetaylor.mc.artisanworktables.modules.toolbox.tile.TileEntityToolbox)

Aggregations

TileEntityToolbox (com.codetaylor.mc.artisanworktables.modules.toolbox.tile.TileEntityToolbox)2 TileEntity (net.minecraft.tileentity.TileEntity)2 Nullable (javax.annotation.Nullable)1 ItemStack (net.minecraft.item.ItemStack)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 SPacketUpdateTileEntity (net.minecraft.network.play.server.SPacketUpdateTileEntity)1 EnumFacing (net.minecraft.util.EnumFacing)1 BlockPos (net.minecraft.util.math.BlockPos)1