Skip to content

Instantly share code, notes, and snippets.

@wesserboy
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wesserboy/7837863aefdab0eeebd1 to your computer and use it in GitHub Desktop.
Save wesserboy/7837863aefdab0eeebd1 to your computer and use it in GitHub Desktop.
@Override
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
//get needed information
TileEntityDecay decay = null;
int progress = 0;
int metadata = world.getBlockMetadata(x, y, z);
TileEntity te = world.getTileEntity(x, y, z);
if(te instanceof TileEntityDecay){
decay = (TileEntityDecay) te;
progress = decay.getProgress();
}
Tessellator tessellator = Tessellator.instance;
tessellator.addTranslation(x, y, z);
tessellator.setColorOpaque_F(1F, 1F, 1F);
tessellator.setBrightness(block.getMixedBrightnessForBlock(world, x, y, z));
//get top icon
IIcon bottomIcon = block.getIcon(0, 0);
IIcon topIcon = block.getIcon(1, 0);
IIcon zNegIcon = block.getIcon(2, 0);
IIcon zPosIcon = block.getIcon(3, 0);
IIcon xNegIcon = block.getIcon(4, 0);
IIcon xPosIcon = block.getIcon(5, 0);
IIcon icon;
//render top
if(metadata < 9){
icon = bottomIcon;
renderer.renderFaceYPos(block, 0, -0.1, 0, icon);
}
//render bottom if visible
if(!world.getBlock(x, y - 1, z).isOpaqueCube() && metadata < 9){
icon = bottomIcon;
renderer.renderFaceYNeg(block, 0, 0, 0, icon);
}
double height = block.getBlockBoundsMaxY() - 0.1;
double scale;
double scale2;
if(height > 0){
//render z-pos if visible
if(!world.getBlock(x, y, z + 1).isOpaqueCube()){
icon = zPosIcon;
scale = icon.getMaxV() - icon.getMinV();
tessellator.addVertexWithUV(1, 0, 1, icon.getMaxU(), icon.getMaxV());
tessellator.addVertexWithUV(1, height, 1, icon.getMaxU(), icon.getMaxV() - scale * height);
tessellator.addVertexWithUV(0, height, 1, icon.getMinU(), icon.getMaxV() - scale * height);
tessellator.addVertexWithUV(0, 0, 1, icon.getMinU(), icon.getMaxV());
}
//render z-neg if visible
if(!world.getBlock(x, y, z - 1).isOpaqueCube()){
icon = zNegIcon;
scale = icon.getMaxV() - icon.getMinV();
tessellator.addVertexWithUV(0, 0, 0, icon.getMaxU(), icon.getMaxV());
tessellator.addVertexWithUV(0, height, 0, icon.getMaxU(), icon.getMaxV() - scale * height);
tessellator.addVertexWithUV(1, height, 0, icon.getMinU(), icon.getMaxV() - scale * height);
tessellator.addVertexWithUV(1, 0, 0, icon.getMinU(), icon.getMaxV());
}
//render x-pos if visible
if(!world.getBlock(x + 1, y, z).isOpaqueCube()){
icon = xPosIcon;
scale = icon.getMaxV() - icon.getMinV();
tessellator.addVertexWithUV(1, 0, 0, icon.getMaxU(), icon.getMaxV());
tessellator.addVertexWithUV(1, height, 0, icon.getMaxU(), icon.getMaxV() - scale * height);
tessellator.addVertexWithUV(1, height, 1, icon.getMinU(), icon.getMaxV() - scale * height);
tessellator.addVertexWithUV(1, 0, 1, icon.getMinU(), icon.getMaxV());
}
//render x-neg if visible
if(!world.getBlock(x - 1, y, z).isOpaqueCube()){
icon = xNegIcon;
scale = icon.getMaxV() - icon.getMinV();
tessellator.addVertexWithUV(0, 0, 1, icon.getMaxU(), icon.getMaxV());
tessellator.addVertexWithUV(0, height, 1, icon.getMaxU(), icon.getMaxV() - scale * height);
tessellator.addVertexWithUV(0, height, 0, icon.getMinU(), icon.getMaxV() - scale * height);
tessellator.addVertexWithUV(0, 0, 0, icon.getMinU(), icon.getMaxV());
}
}
//1000 cubes per block
//100 cubes per height layer
int BlocksThisRow = 100 - (progress - metadata * 100);
double strips = BlocksThisRow / 10;
if(strips > 0){
//render top of strips if visible
if((metadata > 0 || !world.getBlock(x, y + 1, z).isOpaqueCube()) && metadata < 10){
icon = (metadata == 0) ? topIcon : bottomIcon;
scale = icon.getMaxV() - icon.getMinV();
tessellator.addVertexWithUV(1, height + 0.1, strips / 10, icon.getMaxU(), icon.getMinV() + scale * (strips / 10));
tessellator.addVertexWithUV(1, height + 0.1, 0, icon.getMaxU(), icon.getMinV());
tessellator.addVertexWithUV(0, height + 0.1, 0, icon.getMinU(), icon.getMinV());
tessellator.addVertexWithUV(0, height + 0.1, strips / 10, icon.getMinU(), icon.getMinV() + scale * (strips / 10));
}
//render bottom of strips if visible
if(metadata == 9 && !world.getBlock(x, y - 1, z).isOpaqueCube()){
icon = bottomIcon;
scale = icon.getMaxV() - icon.getMinV();
tessellator.addVertexWithUV(1, 0, 0, icon.getMaxU(), icon.getMinV());
tessellator.addVertexWithUV(1, 0, strips / 10, icon.getMaxU(), icon.getMinV() + strips / 10 * scale);
tessellator.addVertexWithUV(0, 0, strips / 10, icon.getMinU(), icon.getMinV() + strips / 10 * scale);
tessellator.addVertexWithUV(0, 0, 0, icon.getMinU(), icon.getMinV());
}
//render z-pos strips if visible
if((strips < 10 || !world.getBlock(x, y, z + 1).isOpaqueCube()) && strips > 0){
icon = (strips < 10) ? bottomIcon : zPosIcon;
scale = icon.getMaxV() - icon.getMinV();
tessellator.addVertexWithUV(1, height, strips / 10, icon.getMaxU(), icon.getMaxV() - scale * (height + 0.1) + 0.1 * scale);
tessellator.addVertexWithUV(1, height + 0.1, strips / 10, icon.getMaxU(), icon.getMaxV() - scale * (height + 0.1));
tessellator.addVertexWithUV(0, height + 0.1, strips / 10, icon.getMinU(), icon.getMaxV() - scale * (height + 0.1));
tessellator.addVertexWithUV(0, height, strips / 10, icon.getMinU(), icon.getMaxV() - scale * (height + 0.1) + 0.1 * scale);
}
//render z-neg strips if visible
if(!world.getBlock(x, y, z - 1).isOpaqueCube() && strips > 0){
icon = zNegIcon;
scale = icon.getMaxV() - icon.getMinV();
tessellator.addVertexWithUV(0, height, 0, icon.getMaxU(), icon.getMaxV() - scale * (height + 0.1) + 0.1 * scale);
tessellator.addVertexWithUV(0, height + 0.1, 0, icon.getMaxU(), icon.getMaxV() - scale * (height + 0.1));
tessellator.addVertexWithUV(1, height + 0.1, 0, icon.getMinU(), icon.getMaxV() - scale * (height + 0.1));
tessellator.addVertexWithUV(1, height, 0, icon.getMinU(), icon.getMaxV() - scale * (height + 0.1) + 0.1 * scale);
}
//render x-pos strips if visible
if(!world.getBlock(x + 1, y, z).isOpaqueCube()){
icon = xPosIcon;
scale = icon.getMaxV() - icon.getMinV();
scale2 = icon.getMaxU() - icon.getMinU();
tessellator.addVertexWithUV(1, height, 0, icon.getMaxU(), icon.getMaxV() - scale * (height + 0.1) + 0.1 * scale);
tessellator.addVertexWithUV(1, height + 0.1, 0, icon.getMaxU(), icon.getMaxV() - scale * (height + 0.1));
tessellator.addVertexWithUV(1, height + 0.1, strips / 10, icon.getMaxU() - (strips / 10) * scale2, icon.getMaxV() - scale * (height + 0.1));
tessellator.addVertexWithUV(1, height, strips / 10, icon.getMaxU() - (strips / 10) * scale2, icon.getMaxV() - scale * (height + 0.1) + 0.1 * scale);
}
//render x-neg strips if visible
if(!world.getBlock(x + 1, y, z).isOpaqueCube()){
icon = xNegIcon;
scale = icon.getMaxV() - icon.getMinV();
scale2 = icon.getMaxU() - icon.getMinU();
tessellator.addVertexWithUV(0, height, strips / 10, icon.getMinU() + (strips / 10) * scale2, icon.getMaxV() - scale * (height + 0.1) + 0.1 * scale);
tessellator.addVertexWithUV(0, height + 0.1, strips / 10, icon.getMinU() + (strips / 10) * scale2, icon.getMaxV() - scale * (height + 0.1));
tessellator.addVertexWithUV(0, height + 0.1, 0, icon.getMinU(), icon.getMaxV() - scale * (height + 0.1));
tessellator.addVertexWithUV(0, height, 0, icon.getMinU(), icon.getMaxV() - scale * (height + 0.1) + 0.1 * scale);
}
}
double blocks = BlocksThisRow - strips * 10;
if(blocks > 0){
//render top of blocks if visible
if(metadata > 0 || !world.getBlock(x, y + 1, z).isOpaqueCube()){
icon = (metadata > 0) ? bottomIcon : topIcon;
scale = icon.getMaxV() - icon.getMinV();
scale2 = icon.getMaxU() - icon.getMinU();
tessellator.addVertexWithUV(blocks / 10, height + 0.1, strips / 10 + 0.1, icon.getMinU() + blocks / 10 * scale2, icon.getMinV() + (strips + 1) / 10 * scale);
tessellator.addVertexWithUV(blocks / 10, height + 0.1, strips / 10, icon.getMinU() + blocks / 10 * scale2, icon.getMinV() + (strips + 1) / 10 * scale - 0.1 * scale);
tessellator.addVertexWithUV(0, height + 0.1, strips / 10, icon.getMinU(), icon.getMinV() + (strips + 1) / 10 * scale - 0.1 * scale);
tessellator.addVertexWithUV(0, height + 0.1, strips / 10 + 0.1, icon.getMinU(), icon.getMinV() + (strips + 1) / 10 * scale);
}
//render bottom of blocks if visible
if(metadata == 9 && !world.getBlock(x, y - 1, z).isOpaqueCube()){
icon = bottomIcon;
scale = icon.getMaxV() - icon.getMinV();
scale2 = icon.getMaxU() - icon.getMinU();
tessellator.addVertexWithUV(blocks / 10, 0, strips / 10, icon.getMinU() + blocks / 10 * scale2, icon.getMinV() + strips / 10 * scale);
tessellator.addVertexWithUV(blocks / 10, 0, strips / 10 + 0.1, icon.getMinU() + blocks / 10 * scale2, icon.getMinV() + strips / 10 * scale + 0.1 * scale);
tessellator.addVertexWithUV(0, 0, strips / 10 + 0.1, icon.getMinU(), icon.getMinV() + strips / 10 * scale + 0.1 * scale);
tessellator.addVertexWithUV(0, 0, strips / 10, icon.getMinU(), icon.getMinV() + strips / 10 * scale);
}
//render z-pos blocks if visible
if(strips < 9 || !world.getBlock(x, y, z + 1).isOpaqueCube()){
icon = (strips == 9) ? zPosIcon : bottomIcon;
scale = icon.getMaxV() - icon.getMinV();
scale2 = icon.getMaxU() - icon.getMinU();
tessellator.addVertexWithUV(blocks / 10, height, (strips + 1) / 10, icon.getMinU() + blocks / 10 * scale2, icon.getMaxV() - scale * (height + 0.1) + 0.1 * scale);
tessellator.addVertexWithUV(blocks / 10, height + 0.1, (strips + 1) / 10, icon.getMinU() + blocks / 10 * scale2, icon.getMaxV() - scale * (height + 0.1));
tessellator.addVertexWithUV(0, height + 0.1, (strips + 1) / 10, icon.getMinU(), icon.getMaxV() - scale * (height + 0.1));
tessellator.addVertexWithUV(0, height, (strips + 1) / 10, icon.getMinU(), icon.getMaxV() - scale * (height + 0.1) + 0.1 * scale);
}
//render z-neg blocks if visible
if(strips == 0 && !world.getBlock(x, y, z - 1).isOpaqueCube()){
icon = zNegIcon;
scale = icon.getMaxV() - icon.getMinV();
scale2 = icon.getMaxU() - icon.getMinU();
tessellator.addVertexWithUV(0, height, 0, icon.getMaxU(), icon.getMaxV() - scale * (height + 0.1) + 0.1 * scale);
tessellator.addVertexWithUV(0, height + 0.1, 0, icon.getMaxU(), icon.getMaxV() - scale * (height + 0.1));
tessellator.addVertexWithUV(blocks / 10, height + 0.1, 0, icon.getMaxU() - blocks / 10 * scale2, icon.getMaxV() - scale * (height + 0.1));
tessellator.addVertexWithUV(blocks / 10, height, 0, icon.getMaxU() - blocks / 10 * scale2, icon.getMaxV() - scale * (height + 0.1) + 0.1 * scale);
}
//render x-pos blocks if visible
if(blocks < 10 || !world.getBlock(x + 1, y, z).isOpaqueCube()){
icon = (blocks < 10) ? bottomIcon : xPosIcon;
scale = icon.getMaxV() - icon.getMinV();
scale2 = icon.getMaxU() - icon.getMinU();
tessellator.addVertexWithUV(blocks / 10, height, strips / 10, icon.getMaxU() - (strips / 10) * scale2, icon.getMaxV() - scale * (height + 0.1) + 0.1 * scale);
tessellator.addVertexWithUV(blocks / 10, height + 0.1, strips / 10, icon.getMaxU() - (strips / 10) * scale2, icon.getMaxV() - scale * (height + 0.1));
tessellator.addVertexWithUV(blocks / 10, height + 0.1, strips / 10 + 0.1, icon.getMaxU() - (strips / 10) * scale2 - 0.1 * scale2, icon.getMaxV() - scale * (height + 0.1));
tessellator.addVertexWithUV(blocks / 10, height, strips / 10 + 0.1, icon.getMaxU() - (strips / 10) * scale2 - 0.1 * scale2, icon.getMaxV() - scale * (height + 0.1) + 0.1 * scale);
}
//render x-neg blocks if visible
if(!world.getBlock(x - 1, y, z).isOpaqueCube()){
icon = xNegIcon;
scale = icon.getMaxV() - icon.getMinV();
scale2 = icon.getMaxU() - icon.getMinU();
tessellator.addVertexWithUV(0, height, strips / 10 + 0.1, icon.getMinU() + strips / 10 * scale2 + 0.1 * scale2, icon.getMaxV() - scale * (height + 0.1) + 0.1 * scale);
tessellator.addVertexWithUV(0, height + 0.1, strips / 10 + 0.1, icon.getMinU() + strips / 10 * scale2 + 0.1 * scale2, icon.getMaxV() - scale * (height + 0.1));
tessellator.addVertexWithUV(0, height + 0.1, strips / 10, icon.getMinU() + strips / 10 * scale2, icon.getMaxV() - scale * (height + 0.1));
tessellator.addVertexWithUV(0, height, strips / 10, icon.getMinU() + strips / 10 * scale2, icon.getMaxV() - scale * (height + 0.1) + 0.1 * scale);
}
}
tessellator.addTranslation(-x, -y, -z);
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment