I'm trying to create a block that changes the way that it renders based on whether blocks of the same ID are directly next to it. I've implemented an ISimpleBlockRenderingHandler that takes care of the rendering itself, and that works perfectly, but I'm having trouble getting the bounding box of the blocks to appropriately update. My renderWorldBlock function calls back to the source block to update its bounds with this code:
public void updateBoundingBox(IBlockAccess world, int x, int y, int z) {
float lowX = 0.25F;
float lowY = 0.25F;
float lowZ = 0.25F;
float highX = 0.75F;
float highY = 0.75F;
float highZ = 0.75F;
if(world.getBlockId(x+1, y, z) == this.blockID) {
highX = 1.0F;
}
if(world.getBlockId(x-1, y, z) == this.blockID) {
lowX = 0.0F;
}
if(world.getBlockId(x, y+1, z) == this.blockID) {
highY = 1.0F;
}
if(world.getBlockId(x, y-1, z) == this.blockID) {
lowY = 0.0F;
}
if(world.getBlockId(x, y, z+1) == this.blockID) {
highZ = 1.0F;
}
if(world.getBlockId(x, y, z-1) == this.blockID) {
lowZ = 0.0F;
}
this.setBlockBounds(lowX, lowY, lowZ, highX, highY, highZ);
}
Each time I place a new instance of the block, every single instance of the block in the world changes its bounding box as well, as if this is modifying the global setting for the block. I've also tried implementing this function which I saw in BlockFence:
public AxisAlignedBB getCollisionBoundingBoxFromPool(IBlockAccess par1World, int x, int y, int z) {
float lowX = 0.25F;
float lowY = 0.25F;
float lowZ = 0.25F;
float highX = 0.75F;
float highY = 0.75F;
float highZ = 0.75F;
if(par1World.getBlockId(x+1, y, z) == this.blockID) {
highX = 1.0F;
}
if(par1World.getBlockId(x-1, y, z) == this.blockID) {
lowX = 0.0F;
}
if(par1World.getBlockId(x, y+1, z) == this.blockID) {
highY = 1.0F;
}
if(par1World.getBlockId(x, y-1, z) == this.blockID) {
lowY = 0.0F;
}
if(par1World.getBlockId(x, y, z+1) == this.blockID) {
highZ = 1.0F;
}
if(par1World.getBlockId(x, y, z-1) == this.blockID) {
lowZ = 0.0F;
}
return AxisAlignedBB.getAABBPool().addOrModifyAABBInPool((double)((float)x + lowX), (double)((float)y + lowY), (double)((float)z + lowZ), (double)((float)x + highX), (double)((float)y + highY), (double)((float)z + highZ));
}
This doesn't help at all. I'm rather confused with this, since I've basically copied what BlockFence does for its bounding, but for some reason it won't work on the per-block level.