Search in sources :

Example 1 with IChestType

use of net.darkhax.bookshelf.builder.ChestBuilder.IChestType 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 IChestType

use of net.darkhax.bookshelf.builder.ChestBuilder.IChestType 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)

Example 3 with IChestType

use of net.darkhax.bookshelf.builder.ChestBuilder.IChestType in project Bookshelf by Darkhax-Minecraft.

the class ItemBlockChest method registerMeshModels.

@Override
public void registerMeshModels() {
    final List<ResourceLocation> models = new ArrayList<>();
    for (final IChestType type : this.builder.getTypes()) {
        models.add(new ResourceLocation(this.builder.getModid(), "chest_" + type.getName()));
        if (this.builder.useTraps()) {
            models.add(new ResourceLocation(this.builder.getModid(), "chest_trap_" + type.getName()));
        }
    }
    ModelBakery.registerItemVariants(this, models.toArray(new ResourceLocation[models.size()]));
}
Also used : IChestType(net.darkhax.bookshelf.builder.ChestBuilder.IChestType) ResourceLocation(net.minecraft.util.ResourceLocation) ArrayList(java.util.ArrayList)

Example 4 with IChestType

use of net.darkhax.bookshelf.builder.ChestBuilder.IChestType in project Bookshelf by Darkhax-Minecraft.

the class BlockBasicChest method getContainer.

@Override
public ILockableContainer getContainer(World world, BlockPos pos, boolean locked) {
    final TileEntity tile = world.getTileEntity(pos);
    if (!(tile instanceof TileEntityBasicChest)) {
        return null;
    } else {
        ILockableContainer myChest = (TileEntityBasicChest) tile;
        final IChestType myType = ((TileEntityBasicChest) tile).getType();
        if (!locked && this.isBlocked(world, pos)) {
            return null;
        } else {
            for (final EnumFacing facing : EnumFacing.Plane.HORIZONTAL) {
                final BlockPos adjPos = pos.offset(facing);
                final TileEntity adjTile = world.getTileEntity(adjPos);
                if (world.getBlockState(adjPos).getBlock() == this && adjTile instanceof TileEntityBasicChest && ((TileEntityBasicChest) adjTile).getType() == myType) {
                    if (this.isBlocked(world, adjPos)) {
                        return null;
                    }
                    if (facing != EnumFacing.WEST && facing != EnumFacing.NORTH) {
                        myChest = new InventoryLargeChest("container.chestDouble", myChest, (TileEntityBasicChest) adjTile);
                    } else {
                        myChest = new InventoryLargeChest("container.chestDouble", (TileEntityBasicChest) adjTile, myChest);
                    }
                }
            }
            return myChest;
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ILockableContainer(net.minecraft.world.ILockableContainer) IChestType(net.darkhax.bookshelf.builder.ChestBuilder.IChestType) InventoryLargeChest(net.minecraft.inventory.InventoryLargeChest) EnumFacing(net.minecraft.util.EnumFacing) TileEntityBasicChest(net.darkhax.bookshelf.block.tileentity.TileEntityBasicChest) BlockPos(net.minecraft.util.math.BlockPos)

Example 5 with IChestType

use of net.darkhax.bookshelf.builder.ChestBuilder.IChestType in project Bookshelf by Darkhax-Minecraft.

the class BlockBasicChest method onBlockPlacedBy.

@Override
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
    final EnumFacing facing = EnumFacing.getHorizontal(MathHelper.floor(placer.rotationYaw * 4.0F / 360.0F + 0.5D) & 3).getOpposite();
    state = state.withProperty(FACING, facing);
    final BlockPos northPos = pos.north();
    final BlockPos southPos = pos.south();
    final BlockPos westPos = pos.west();
    final BlockPos eastPos = pos.east();
    final IChestType myType = this.getCustomType(stack);
    final boolean northChest = myType == this.getCustomType(worldIn, northPos);
    final boolean southChest = myType == this.getCustomType(worldIn, southPos);
    final boolean westChest = myType == this.getCustomType(worldIn, westPos);
    final boolean eastChest = myType == this.getCustomType(worldIn, eastPos);
    if (!northChest && !southChest && !westChest && !eastChest) {
        worldIn.setBlockState(pos, state, 3);
    } else if (facing.getAxis() != EnumFacing.Axis.X || !northChest && !southChest) {
        if (facing.getAxis() == EnumFacing.Axis.Z && (westChest || eastChest)) {
            if (westChest) {
                this.setState(worldIn, westPos, state, 3);
            } else {
                this.setState(worldIn, eastPos, state, 3);
            }
            worldIn.setBlockState(pos, state, 3);
        } else {
            final EnumFacing corrected = facing.rotateY();
            this.setState(worldIn, pos, state.withProperty(FACING, corrected), 3);
            if (northChest) {
                this.setState(worldIn, northPos, state.withProperty(FACING, corrected), 3);
            } else if (southChest) {
                this.setState(worldIn, southPos, state.withProperty(FACING, corrected), 3);
            } else if (westChest) {
                this.setState(worldIn, westPos, state.withProperty(FACING, corrected), 3);
            } else if (eastChest) {
                this.setState(worldIn, eastPos, state.withProperty(FACING, corrected), 3);
            }
        }
    } else {
        if (northChest) {
            this.setState(worldIn, northPos, state, 3);
        } else {
            this.setState(worldIn, southPos, state, 3);
        }
        worldIn.setBlockState(pos, state, 3);
    }
    final TileEntity te = worldIn.getTileEntity(pos);
    if (te instanceof TileEntityBasicChest) {
        final TileEntityBasicChest chest = (TileEntityBasicChest) te;
        if (stack.hasDisplayName()) {
            chest.setCustomName(stack.getDisplayName());
        }
        chest.setType(myType);
    }
    this.onBlockAdded(worldIn, pos, state);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IChestType(net.darkhax.bookshelf.builder.ChestBuilder.IChestType) EnumFacing(net.minecraft.util.EnumFacing) TileEntityBasicChest(net.darkhax.bookshelf.block.tileentity.TileEntityBasicChest) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

IChestType (net.darkhax.bookshelf.builder.ChestBuilder.IChestType)5 TileEntityBasicChest (net.darkhax.bookshelf.block.tileentity.TileEntityBasicChest)3 TileEntity (net.minecraft.tileentity.TileEntity)3 BlockPos (net.minecraft.util.math.BlockPos)3 BlockBasicChest (net.darkhax.bookshelf.block.BlockBasicChest)2 EnumFacing (net.minecraft.util.EnumFacing)2 ArrayList (java.util.ArrayList)1 InventoryLargeChest (net.minecraft.inventory.InventoryLargeChest)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 ILockableContainer (net.minecraft.world.ILockableContainer)1