use of net.darkhax.bookshelf.block.tileentity.TileEntityBasicChest 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;
}
use of net.darkhax.bookshelf.block.tileentity.TileEntityBasicChest 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;
}
}
}
use of net.darkhax.bookshelf.block.tileentity.TileEntityBasicChest 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);
}
use of net.darkhax.bookshelf.block.tileentity.TileEntityBasicChest in project Bookshelf by Darkhax-Minecraft.
the class BlockBasicChest method setState.
/**
* Sets the state of the block, and updates the chest connections.
*
* @param worldIn The world instance.
* @param pos The position.
* @param state The state.
* @param flag The update flags.
*/
public void setState(World worldIn, BlockPos pos, IBlockState state, int flag) {
final TileEntity te = worldIn.getTileEntity(pos);
worldIn.setBlockState(pos, state, flag);
if (te != null) {
te.validate();
worldIn.setTileEntity(pos, te);
if (te instanceof TileEntityBasicChest) {
((TileEntityBasicChest) te).adjacentChestChecked = false;
}
}
}
Aggregations