Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package co.uk.silvania.cities.core.client;
- import org.lwjgl.opengl.GL11;
- import co.uk.silvania.cities.core.CoreBlocks;
- import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
- import net.minecraft.block.Block;
- import net.minecraft.client.renderer.RenderBlocks;
- import net.minecraft.client.renderer.Tessellator;
- import net.minecraft.util.IIcon;
- import net.minecraft.world.IBlockAccess;
- public class LightBlockRenderer implements ISimpleBlockRenderingHandler {
- Tessellator tess;
- @Override
- public void renderInventoryBlock(Block block, int meta, int modelId, RenderBlocks renderer) {
- tess = Tessellator.instance;
- GL11.glTranslatef(-0.5F, -0.5F, -0.5F);
- IIcon light = CoreBlocks.lightingBlocks.getIcon(0, meta);
- IIcon side = CoreBlocks.lightingBlocks.getIcon(2, meta);
- double u0 = (double) light.getMinU();
- double u1 = (double) light.getMaxU();
- double v0 = (double) light.getMinV();
- double v1 = (double) light.getMaxV();
- double u2 = (double) side.getMinU();
- double u3 = (double) side.getMaxU();
- double v2 = (double) side.getMinV();
- double v3 = (double) side.getMaxV();
- final float FACE_XZ_NORMAL = 0.8944F;
- final float FACE_Y_NORMAL = 0.4472F;
- tess.startDrawingQuads();
- double a = 0.96875; //base height
- //Top Side
- tess.setNormal(0.0F, 1.0F, 0.0F);
- tess.addVertexWithUV(0, 1, 0, u3, v3);
- tess.addVertexWithUV(0, 1, 1, u3, v2);
- tess.addVertexWithUV(1, 1, 1, u2, v2);
- tess.addVertexWithUV(1, 1, 0, u2, v3);
- tess.draw();
- //North Side
- tess.startDrawingQuads();
- tess.setNormal(0.0F, FACE_Y_NORMAL, -FACE_XZ_NORMAL);
- tess.addVertexWithUV(1, 1, 0, u3, v3);
- tess.addVertexWithUV(1, a, 0, u3, v2);
- tess.addVertexWithUV(0, a, 0, u2, v2);
- tess.addVertexWithUV(0, 1, 0, u2, v3);
- tess.draw();
- //East Side
- tess.startDrawingQuads();
- tess.setNormal(FACE_XZ_NORMAL, FACE_Y_NORMAL, 0.0F);
- tess.addVertexWithUV(1, 1, 1, u3, v3);
- tess.addVertexWithUV(1, a, 1, u3, v2);
- tess.addVertexWithUV(1, a, 0, u2, v2);
- tess.addVertexWithUV(1, 1, 0, u2, v3);
- tess.draw();
- //South Side
- tess.startDrawingQuads();
- tess.setNormal(0.0F, FACE_Y_NORMAL, FACE_XZ_NORMAL);
- tess.addVertexWithUV(0, 1, 1, u3, v3);
- tess.addVertexWithUV(0, a, 1, u3, v2);
- tess.addVertexWithUV(1, a, 1, u2, v2);
- tess.addVertexWithUV(1, 1, 1, u2, v3);
- tess.draw();
- //West Side
- tess.startDrawingQuads();
- tess.setNormal(-FACE_XZ_NORMAL, FACE_Y_NORMAL, 0.0F);
- tess.addVertexWithUV(0, 1, 0, u3, v3);
- tess.addVertexWithUV(0, a, 0, u3, v2);
- tess.addVertexWithUV(0, a, 1, u2, v2);
- tess.addVertexWithUV(0, 1, 1, u2, v3);
- tess.draw();
- //Bottom Side
- tess.startDrawingQuads();
- tess.setNormal(0.0F, -1.0F, 0.0F);
- tess.addVertexWithUV(0, a, 1, u1, v1);
- tess.addVertexWithUV(0, a, 0, u1, v0);
- tess.addVertexWithUV(1, a, 0, u0, v0);
- tess.addVertexWithUV(1, a, 1, u0, v1);
- tess.draw();
- GL11.glTranslatef(0.5F, 0.5F, 0.5F);
- }
- @Override
- public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
- System.out.println("Rendering world block");
- tess = Tessellator.instance;
- IIcon light = CoreBlocks.lightingBlocks.getIcon(0, 0);
- IIcon side = CoreBlocks.lightingBlocks.getIcon(2, 0);
- double u0 = (double) light.getMinU();
- double u1 = (double) light.getMaxU();
- double v0 = (double) light.getMinV();
- double v1 = (double) light.getMaxV();
- double u2 = (double) side.getMinU();
- double u3 = (double) side.getMaxU();
- double v2 = (double) side.getMinV();
- double v3 = (double) side.getMaxV();
- double a = 0.96875;
- //Top Side
- tess.addVertexWithUV(0, 1, 0, u3, v3);
- tess.addVertexWithUV(0, 1, 1, u3, v2);
- tess.addVertexWithUV(1, 1, 1, u2, v2);
- tess.addVertexWithUV(1, 1, 0, u2, v3);
- tess.draw();
- //North Side
- tess.startDrawingQuads();
- tess.addVertexWithUV(1, 1, 0, u3, v3);
- tess.addVertexWithUV(1, a, 0, u3, v2);
- tess.addVertexWithUV(0, a, 0, u2, v2);
- tess.addVertexWithUV(0, 1, 0, u2, v3);
- tess.draw();
- //East Side
- tess.startDrawingQuads();
- tess.addVertexWithUV(1, 1, 1, u3, v3);
- tess.addVertexWithUV(1, a, 1, u3, v2);
- tess.addVertexWithUV(1, a, 0, u2, v2);
- tess.addVertexWithUV(1, 1, 0, u2, v3);
- tess.draw();
- //South Side
- tess.startDrawingQuads();
- tess.addVertexWithUV(0, 1, 1, u3, v3);
- tess.addVertexWithUV(0, a, 1, u3, v2);
- tess.addVertexWithUV(1, a, 1, u2, v2);
- tess.addVertexWithUV(1, 1, 1, u2, v3);
- tess.draw();
- //West Side
- tess.startDrawingQuads();
- tess.addVertexWithUV(0, 1, 0, u3, v3);
- tess.addVertexWithUV(0, a, 0, u3, v2);
- tess.addVertexWithUV(0, a, 1, u2, v2);
- tess.addVertexWithUV(0, 1, 1, u2, v3);
- tess.draw();
- //Bottom Side
- tess.startDrawingQuads();
- tess.addVertexWithUV(0, a, 1, u1, v1);
- tess.addVertexWithUV(0, a, 0, u1, v0);
- tess.addVertexWithUV(1, a, 0, u0, v0);
- tess.addVertexWithUV(1, a, 1, u0, v1);
- return true;
- }
- @Override
- public boolean shouldRender3DInInventory(int modelId) {
- return true;
- }
- @Override
- public int getRenderId() {
- return ClientProxy.lightBlockRenderID;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement