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;
}
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);
}
}
}
Aggregations