use of com.minecolonies.coremod.tileentities.TileEntityRack in project minecolonies by Minecolonies.
the class BlockMinecoloniesRack method breakBlock.
@Override
public void breakBlock(final World worldIn, final BlockPos pos, final IBlockState state) {
final TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof TileEntityRack) {
final IItemHandler handler = ((TileEntityRack) tileentity).getInventory();
InventoryUtils.dropItemHandler(handler, worldIn, pos.getX(), pos.getY(), pos.getZ());
}
super.breakBlock(worldIn, pos, state);
}
use of com.minecolonies.coremod.tileentities.TileEntityRack in project minecolonies by Minecolonies.
the class BlockMinecoloniesRack method neighborChanged.
@Override
public void neighborChanged(final IBlockState state, final World worldIn, final BlockPos pos, final Block blockIn, final BlockPos fromPos) {
if (state.getBlock() instanceof BlockMinecoloniesRack) {
final TileEntity rack = worldIn.getTileEntity(pos);
for (final EnumFacing offsetFacing : BlockHorizontal.FACING.getAllowedValues()) {
final BlockPos neighbor = pos.offset(offsetFacing);
final Block block = worldIn.getBlockState(neighbor).getBlock();
if (rack instanceof TileEntityRack && pos.getY() == neighbor.getY() && !pos.equals(neighbor) && !pos.equals(BlockPos.ORIGIN) && (block instanceof BlockMinecoloniesRack || blockIn instanceof BlockMinecoloniesRack)) {
((TileEntityRack) rack).neighborChanged(neighbor);
}
}
}
super.neighborChanged(state, worldIn, pos, blockIn, fromPos);
}
use of com.minecolonies.coremod.tileentities.TileEntityRack in project minecolonies by Minecolonies.
the class BlockMinecoloniesRack method onBlockActivated.
@Override
public boolean onBlockActivated(final World worldIn, final BlockPos pos, final IBlockState state, final EntityPlayer playerIn, final EnumHand hand, final EnumFacing facing, final float hitX, final float hitY, final float hitZ) {
final Colony colony = ColonyManager.getColony(worldIn, pos);
final TileEntity tileEntity = worldIn.getTileEntity(pos);
if ((colony == null || colony.getPermissions().hasPermission(playerIn, Action.ACCESS_HUTS)) && tileEntity instanceof TileEntityRack) {
if (!worldIn.isRemote) {
playerIn.openGui(MineColonies.instance, 0, worldIn, pos.getX(), pos.getY(), pos.getZ());
}
return true;
}
return false;
}
use of com.minecolonies.coremod.tileentities.TileEntityRack in project minecolonies by Minecolonies.
the class BlockMinecoloniesRack method getActualState.
/**
* @deprecated but we still need this because there is nothing better.
*/
@Override
public IBlockState getActualState(final IBlockState state, final IBlockAccess worldIn, final BlockPos pos) {
final TileEntity entity = worldIn.getTileEntity(pos);
if (!(entity instanceof TileEntityRack)) {
return super.getActualState(state, worldIn, pos);
}
final TileEntityRack rack = (TileEntityRack) entity;
if (rack.isEmpty() && (rack.getOtherChest() == null || rack.getOtherChest().isEmpty())) {
if (rack.getOtherChest() != null) {
if (rack.isMain()) {
return state.withProperty(BlockMinecoloniesRack.VARIANT, RackType.DEFAULTDOUBLE).withProperty(FACING, BlockPosUtil.getFacing(rack.getNeighbor(), pos));
} else {
return state.withProperty(BlockMinecoloniesRack.VARIANT, RackType.EMPTYAIR);
}
} else {
return state.withProperty(BlockMinecoloniesRack.VARIANT, RackType.DEFAULT);
}
} else {
if (rack.getOtherChest() != null) {
if (rack.isMain()) {
return state.withProperty(BlockMinecoloniesRack.VARIANT, RackType.FULLDOUBLE).withProperty(FACING, BlockPosUtil.getFacing(rack.getNeighbor(), pos));
} else {
return state.withProperty(BlockMinecoloniesRack.VARIANT, RackType.EMPTYAIR);
}
} else {
return state.withProperty(BlockMinecoloniesRack.VARIANT, RackType.FULL);
}
}
}
use of com.minecolonies.coremod.tileentities.TileEntityRack in project minecolonies by Minecolonies.
the class BuildingWareHouse method handleBuildingOverChest.
/**
* Handles the chest placement.
*
* @param pos at pos.
* @param chest the entity.
* @param world the world.
*/
public static void handleBuildingOverChest(@NotNull final BlockPos pos, final TileEntityChest chest, final World world) {
final List<ItemStack> inventory = new ArrayList<>();
final int size = chest.getSingleChestHandler().getSlots();
for (int slot = 0; slot < size; slot++) {
final ItemStack stack = chest.getSingleChestHandler().getStackInSlot(slot);
if (!ItemStackUtils.isEmpty(stack)) {
inventory.add(stack.copy());
}
chest.getSingleChestHandler().extractItem(slot, Integer.MAX_VALUE, false);
}
world.setBlockState(pos, ModBlocks.blockRack.getDefaultState(), 0x03);
final TileEntity entity = world.getTileEntity(pos);
if (entity instanceof TileEntityRack) {
for (final ItemStack stack : inventory) {
if (!ItemStackUtils.isEmpty(stack)) {
InventoryUtils.addItemStackToItemHandler(((TileEntityRack) entity).getInventory(), stack);
}
}
}
}
Aggregations