Search in sources :

Example 1 with BlockBasicChest

use of net.darkhax.bookshelf.block.BlockBasicChest in project Bookshelf by Darkhax-Minecraft.

the class ItemBlockChest method placeBlockAt.

@Override
public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, IBlockState newState) {
    int typeCnt = 0;
    final BlockPos posN = pos.north();
    final BlockPos posS = pos.south();
    final BlockPos posW = pos.west();
    final BlockPos posE = pos.east();
    final BlockBasicChest cChest = (BlockBasicChest) this.getBlock();
    final IChestType myType = cChest.getCustomType(stack);
    if (world.getBlockState(posN).getBlock() == this.block && cChest.getCustomType(world, posN) == myType) {
        typeCnt += cChest.isDoubleChest(world, posN, myType) ? 2 : 1;
    }
    if (world.getBlockState(posS).getBlock() == this.block && cChest.getCustomType(world, posS) == myType) {
        typeCnt += cChest.isDoubleChest(world, posS, myType) ? 2 : 1;
    }
    if (world.getBlockState(posW).getBlock() == this.block && cChest.getCustomType(world, posW) == myType) {
        typeCnt += cChest.isDoubleChest(world, posW, myType) ? 2 : 1;
    }
    if (world.getBlockState(posE).getBlock() == this.block && cChest.getCustomType(world, posE) == myType) {
        typeCnt += cChest.isDoubleChest(world, posE, myType) ? 2 : 1;
    }
    if (typeCnt <= 1 && super.placeBlockAt(stack, player, world, pos, side, hitX, hitY, hitZ, newState)) {
        final TileEntity te = world.getTileEntity(pos);
        if (te instanceof TileEntityBasicChest) {
            ((TileEntityBasicChest) te).setType(myType);
            return true;
        }
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IChestType(net.darkhax.bookshelf.builder.ChestBuilder.IChestType) TileEntityBasicChest(net.darkhax.bookshelf.block.tileentity.TileEntityBasicChest) BlockPos(net.minecraft.util.math.BlockPos) BlockBasicChest(net.darkhax.bookshelf.block.BlockBasicChest)

Example 2 with BlockBasicChest

use of net.darkhax.bookshelf.block.BlockBasicChest in project Bookshelf by Darkhax-Minecraft.

the class ItemBlockChest method getUnlocalizedName.

@Override
public String getUnlocalizedName(ItemStack stack) {
    final BlockBasicChest cChest = (BlockBasicChest) this.getBlock();
    final IChestType myType = cChest.getCustomType(stack);
    return myType != null ? this.block.getUnlocalizedName() + "." + myType.getName() + (cChest.isTrapChest() ? ".trap" : "") : this.block.getUnlocalizedName();
}
Also used : IChestType(net.darkhax.bookshelf.builder.ChestBuilder.IChestType) BlockBasicChest(net.darkhax.bookshelf.block.BlockBasicChest)

Aggregations

BlockBasicChest (net.darkhax.bookshelf.block.BlockBasicChest)2 IChestType (net.darkhax.bookshelf.builder.ChestBuilder.IChestType)2 TileEntityBasicChest (net.darkhax.bookshelf.block.tileentity.TileEntityBasicChest)1 TileEntity (net.minecraft.tileentity.TileEntity)1 BlockPos (net.minecraft.util.math.BlockPos)1