Java tutorial
/***************************************************************************\ * Copyright 2016 [Lyonlancer5] * * * * Licensed under the Apache License, Version 2.0 (the "License"); * * you may not use this file except in compliance with the License. * * You may obtain a copy of the License at * * * * http://www.apache.org/licenses/LICENSE-2.0 * * * * Unless required by applicable law or agreed to in writing, software * * distributed under the License is distributed on an "AS IS" BASIS, * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * * See the License for the specific language governing permissions and * * limitations under the License. * \***************************************************************************/ package net.lyonlancer5.mcmp.karasu.client.renderer.tileentity; import net.minecraft.block.Block; import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.texture.TextureMap; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.util.ForgeDirection; import org.lwjgl.opengl.GL11; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public class TileEntityEndRodRenderer extends TileEntitySpecialRenderer { private RenderBlocks renderer; public TileEntityEndRodRenderer() { renderer = new RenderBlocks(); } @Override public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float partialTicks) { GL11.glPushMatrix(); GL11.glTranslated(x, y, z); colour(0xFFFFFF); bindTexture(TextureMap.locationBlocksTexture); ForgeDirection dir = ForgeDirection.getOrientation(tile.getBlockMetadata()); switch (dir) { case DOWN: GL11.glRotated(180, 1, 0, 0); GL11.glTranslated(0, -1, -1); break; case EAST: GL11.glRotated(270, 0, 0, 1); GL11.glTranslated(-1, 0, 0); break; case NORTH: GL11.glRotated(270, 1, 0, 0); GL11.glTranslated(0, -1, 0); break; case SOUTH: GL11.glRotated(90, 1, 0, 0); GL11.glTranslated(0, 0, -1); break; case WEST: GL11.glRotated(90, 0, 0, 1); GL11.glTranslated(0, -1, 0); break; default: break; } renderRod(renderer, tile.getBlockType(), tile.getBlockMetadata()); GL11.glPopMatrix(); } public static void renderRod(RenderBlocks renderer, Block block, int meta) { Tessellator tessellator = Tessellator.instance; double x = 7 / 16.0; double y = 0; double z = 7 / 16.0; renderer.setRenderBounds(0, 1 / 16F, 0, 2 / 16F, 1, 2 / 16F); tessellator.startDrawingQuads(); tessellator.setNormal(0.0F, -1.0F, 0.0F); renderer.renderFaceYNeg(block, x, y, z, renderer.getBlockIconFromSideAndMetadata(block, 0, meta)); tessellator.setNormal(0.0F, 1.0F, 0.0F); renderer.renderFaceYPos(block, x, y, z, renderer.getBlockIconFromSideAndMetadata(block, 1, meta)); tessellator.setNormal(0.0F, 0.0F, -1.0F); renderer.renderFaceZNeg(block, x, y, z, renderer.getBlockIconFromSideAndMetadata(block, 2, meta)); tessellator.setNormal(0.0F, 0.0F, 1.0F); renderer.renderFaceZPos(block, x, y, z, renderer.getBlockIconFromSideAndMetadata(block, 3, meta)); tessellator.setNormal(-1.0F, 0.0F, 0.0F); renderer.renderFaceXNeg(block, x, y, z, renderer.getBlockIconFromSideAndMetadata(block, 4, meta)); tessellator.setNormal(1.0F, 0.0F, 0.0F); renderer.renderFaceXPos(block, x, y, z, renderer.getBlockIconFromSideAndMetadata(block, 5, meta)); tessellator.draw(); x = 4 / 16.0; y = 0; z = 4 / 16.0; renderer.setRenderBounds(2 / 16F, 0, 2 / 16F, 6 / 16F, 1 / 16F, 6 / 16F); tessellator.startDrawingQuads(); tessellator.setNormal(0.0F, -1.0F, 0.0F); renderer.renderFaceYNeg(block, x, y, z, renderer.getBlockIconFromSideAndMetadata(block, 0, meta)); tessellator.setNormal(0.0F, 1.0F, 0.0F); renderer.renderFaceYPos(block, x, y, z, renderer.getBlockIconFromSideAndMetadata(block, 1, meta)); y = -13 / 16.0; renderer.setRenderBounds(2 / 16F, 13 / 16F, 2 / 16F, 6 / 16F, 14 / 16F, 6 / 16F); tessellator.setNormal(0.0F, 0.0F, -1.0F); renderer.renderFaceZNeg(block, x, y, z, renderer.getBlockIconFromSideAndMetadata(block, 2, meta)); tessellator.setNormal(0.0F, 0.0F, 1.0F); renderer.renderFaceZPos(block, x, y, z, renderer.getBlockIconFromSideAndMetadata(block, 3, meta)); tessellator.setNormal(-1.0F, 0.0F, 0.0F); renderer.renderFaceXNeg(block, x, y, z, renderer.getBlockIconFromSideAndMetadata(block, 4, meta)); tessellator.setNormal(1.0F, 0.0F, 0.0F); renderer.renderFaceXPos(block, x, y, z, renderer.getBlockIconFromSideAndMetadata(block, 5, meta)); tessellator.draw(); } private static void colour(int colour) { float r = (colour >> 16 & 255) / 255F; float g = (colour >> 8 & 255) / 255F; float b = (colour & 255) / 255F; GL11.glColor3f(r, g, b); } }