Search in sources :

Example 1 with BlockMinecoloniesRack

use of com.minecolonies.coremod.blocks.BlockMinecoloniesRack in project minecolonies by Minecolonies.

the class BuildingWareHouse method registerBlockPosition.

@Override
public void registerBlockPosition(@NotNull final Block block, @NotNull final BlockPos pos, @NotNull final World world) {
    if ((block instanceof BlockContainer || block instanceof BlockMinecoloniesRack) && world != null) {
        final TileEntity entity = getColony().getWorld().getTileEntity(pos);
        if (entity instanceof TileEntityChest) {
            handleBuildingOverChest(pos, (TileEntityChest) entity, world);
        }
        addContainerPosition(pos);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityChest(net.minecraft.tileentity.TileEntityChest) BlockContainer(net.minecraft.block.BlockContainer) BlockMinecoloniesRack(com.minecolonies.coremod.blocks.BlockMinecoloniesRack)

Example 2 with BlockMinecoloniesRack

use of com.minecolonies.coremod.blocks.BlockMinecoloniesRack in project minecolonies by Minecolonies.

the class TileEntityRack method neighborChanged.

/**
 * On neighbor changed this will be called from the block.
 *
 * @param newNeighbor the blockPos which has changed.
 */
public void neighborChanged(final BlockPos newNeighbor) {
    final TileEntity entity = world.getTileEntity(newNeighbor);
    if (!this.neighbor.equals(BlockPos.ORIGIN) && this.neighbor.distanceSq(this.pos) > 1 && entity instanceof TileEntityRack) {
        softReset();
    }
    if (this.neighbor.equals(BlockPos.ORIGIN) && world.getBlockState(newNeighbor).getBlock() instanceof BlockMinecoloniesRack && !(entity instanceof TileEntityRack && ((TileEntityRack) entity).getOtherChest() != null)) {
        this.neighbor = newNeighbor;
        single = false;
        if (entity instanceof TileEntityRack && !((TileEntityRack) entity).isMain()) {
            this.main = true;
            ((TileEntityRack) entity).setMain(false);
        }
        ((TileEntityRack) entity).setNeighbor(this.getPos());
        entity.markDirty();
        updateItemStorage();
        this.markDirty();
    } else if (this.neighbor.equals(newNeighbor) && !(world.getBlockState(newNeighbor).getBlock() instanceof BlockMinecoloniesRack)) {
        this.neighbor = BlockPos.ORIGIN;
        single = true;
        this.main = false;
        updateItemStorage();
    }
}
Also used : SPacketUpdateTileEntity(net.minecraft.network.play.server.SPacketUpdateTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) BlockMinecoloniesRack(com.minecolonies.coremod.blocks.BlockMinecoloniesRack)

Example 3 with BlockMinecoloniesRack

use of com.minecolonies.coremod.blocks.BlockMinecoloniesRack in project minecolonies by Minecolonies.

the class TileEntityRack method updateBlockState.

/**
 * Update the blockState of the rack.
 * Switch between connected, single, full and empty texture.
 */
private void updateBlockState() {
    if (world != null && world.getBlockState(pos).getBlock() instanceof BlockMinecoloniesRack && (main || single)) {
        final IBlockState typeHere;
        final IBlockState typeNeighbor;
        if (content.isEmpty() && (getOtherChest() == null || getOtherChest().isEmpty())) {
            if (getOtherChest() != null && world.getBlockState(neighbor).getBlock() instanceof BlockMinecoloniesRack) {
                typeHere = world.getBlockState(pos).withProperty(BlockMinecoloniesRack.VARIANT, RackType.EMPTYAIR);
                typeNeighbor = world.getBlockState(neighbor).withProperty(BlockMinecoloniesRack.VARIANT, RackType.DEFAULTDOUBLE).withProperty(BlockMinecoloniesRack.FACING, BlockPosUtil.getFacing(pos, neighbor));
            } else {
                typeHere = world.getBlockState(pos).withProperty(BlockMinecoloniesRack.VARIANT, RackType.DEFAULT);
                typeNeighbor = null;
            }
        } else {
            if (getOtherChest() != null && world.getBlockState(neighbor).getBlock() instanceof BlockMinecoloniesRack) {
                typeHere = world.getBlockState(pos).withProperty(BlockMinecoloniesRack.VARIANT, RackType.EMPTYAIR);
                typeNeighbor = world.getBlockState(neighbor).withProperty(BlockMinecoloniesRack.VARIANT, RackType.FULLDOUBLE).withProperty(BlockMinecoloniesRack.FACING, BlockPosUtil.getFacing(pos, neighbor));
            } else {
                typeHere = world.getBlockState(pos).withProperty(BlockMinecoloniesRack.VARIANT, RackType.FULL);
                typeNeighbor = null;
            }
        }
        world.setBlockState(pos, typeHere);
        if (typeNeighbor != null) {
            world.setBlockState(neighbor, typeNeighbor);
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockMinecoloniesRack(com.minecolonies.coremod.blocks.BlockMinecoloniesRack)

Aggregations

BlockMinecoloniesRack (com.minecolonies.coremod.blocks.BlockMinecoloniesRack)3 TileEntity (net.minecraft.tileentity.TileEntity)2 BlockContainer (net.minecraft.block.BlockContainer)1 IBlockState (net.minecraft.block.state.IBlockState)1 SPacketUpdateTileEntity (net.minecraft.network.play.server.SPacketUpdateTileEntity)1 TileEntityChest (net.minecraft.tileentity.TileEntityChest)1