I am attempting to make a block that will appear as another block in the game, depending on the id passed into it. To do this I am using a TileEntitySpecialRenderer, and calling RenderBlocks.renderBlockByRenderType, as shown below. This works perfectly for all 1mx1mx1m blocks, but it renders everything else at that size. For items that are not full blocks, but are using textures that are from full block (e.g. half slabs and fences), this just renders a full block using that texture (so a fence appears as oak planks). For other blocks (such as a cactus), there are just gaps between the textures. I don't have much experience with custom rendering in minecraft/forge, and was hoping that somebody could help.
From my TileEntitySpecialRenderer subclass:
@Override
public void renderTileEntityAt(TileEntity tileEntity, double d0, double d1, double d2, float f) {
TileEntityCamouflaged te = (TileEntityCamouflaged)tileEntity;
Block block = te.getTextureBlock();
RenderBlocks renderBlocks = new RenderBlocks(tileEntity.worldObj);
renderBlocks.renderBlockByRenderType(block, te.xCoord, te.yCoord, te.zCoord);
}
Methods overwritten in my block class:
@Override
public boolean renderAsNormalBlock() {
return false;
}
@Override
public boolean isOpaqueCube() {
return false;
}
@Override
public boolean shouldSideBeRendered(IBlockAccess blockAccess, int x, int y, int z, int side) {
System.out.println("shouldSideBeRendered at " + x + ", " + y + ", " + z + " on side " + side);
int newX = x;
int newY = y;
int newZ = z;
//The x, y and z coordinates appear to change because of the side
switch (side) {
case 0:
++newY;
break;
case 1:
--newY;
break;
case 2:
++newZ;
break;
case 3:
--newZ;
break;
case 4:
++newX;
break;
case 5:
--newX;
break;
}
TileEntityCamouflaged tileEntity = (TileEntityCamouflaged)blockAccess.getBlockTileEntity(newX, newY, newZ);
if (tileEntity == null) return false;
return tileEntity.getTextureBlock().shouldSideBeRendered(blockAccess, x, y, z, side);
}
@Override
public Icon getBlockTexture(IBlockAccess blockAccess, int x, int y, int z, int side) {
TileEntityCamouflaged tileEntity = (TileEntityCamouflaged)blockAccess.getBlockTileEntity(x, y, z);
return tileEntity.getTextureBlock().getBlockTexture(blockAccess, x, y, z, side);
}
@Override
public boolean isBlockSolid(IBlockAccess blockAccess, int x, int y, int z, int side) {
TileEntityCamouflaged tileEntity = (TileEntityCamouflaged)blockAccess.getBlockTileEntity(x, y, z);
return tileEntity.getTextureBlock().isBlockSolid(blockAccess, x, y, z, side);
}
@Override
public int colorMultiplier(IBlockAccess blockAccess, int x, int y, int z) {
System.out.println("colorMultiplier at " + x + ", " + y + ", " + z);
TileEntityCamouflaged tileEntity = (TileEntityCamouflaged)blockAccess.getBlockTileEntity(x, y, z);
return tileEntity.getTextureBlock().colorMultiplier(blockAccess, x, y, z);
}
@Override
public void setBlockBoundsBasedOnState(IBlockAccess blockAccess, int x, int y, int z) {
TileEntityCamouflaged tileEntity = (TileEntityCamouflaged)blockAccess.getBlockTileEntity(x, y, z);
tileEntity.getTextureBlock().setBlockBoundsBasedOnState(blockAccess, x, y, z);
}
@Override
public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) {
Block block = ((TileEntityCamouflaged)world.getBlockTileEntity(x, y, z)).getTextureBlock();
return block.getCollisionBoundingBoxFromPool(world, x, y, z);
}
@Override
public int getLightOpacity(World world, int x, int y, int z) {
Block block = ((TileEntityCamouflaged)world.getBlockTileEntity(x, y, z)).getTextureBlock();
return block.getLightOpacity(world, x, y, z);
}
@Override
public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int x, int y, int z) {
Block block = ((TileEntityCamouflaged)world.getBlockTileEntity(x, y, z)).getTextureBlock();
return block.getSelectedBoundingBoxFromPool(world, x, y, z);
}
@Override
public boolean isBlockNormalCube(World world, int x, int y, int z) {
Block block = ((TileEntityCamouflaged)world.getBlockTileEntity(x, y, z)).getTextureBlock();
return block.isBlockNormalCube(world, x, y, z);
}
@Override
public boolean isBlockSolidOnSide(World world, int x, int y, int z, ForgeDirection side) {
Block block = ((TileEntityCamouflaged)world.getBlockTileEntity(x, y, z)).getTextureBlock();
return block.isBlockSolidOnSide(world, x, y, z, side);
}
//I am not sure about this one, though it fixes the rendering of ice, and doesn't appear to cause problems with anything that already worked.
@Override
public int getRenderBlockPass() {
return 1;
}