Java tutorial
/******************************************************************************* * ElementalCraft * Copyright (c) 2014 Ned Hyett and Jacob * * This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 4.0 Unported License. * * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0 ******************************************************************************/ package nedhyett.elementalcraft.block.stand; import cpw.mods.fml.client.FMLClientHandler; import nedhyett.elementalcraft.core.util.Utils; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.entity.RenderItem; import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.entity.item.EntityItem; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.GL11; import static org.lwjgl.opengl.GL11.*; /** * Renders the stand in the world. * * @author Ned Hyett */ public class RenderStandWorld extends TileEntitySpecialRenderer { private final RenderItem renderItems; private final ModelStand model; private final ResourceLocation texture = Utils.getResource("textures/blocks/stand.png"); public float currentUpDown = 5F; public boolean toggle = true; private Minecraft mc; private boolean doRender = true; private int SPEED = 3; public RenderStandWorld() { mc = FMLClientHandler.instance().getClient(); renderItems = new RenderItem() { @Override public byte getMiniItemCount(ItemStack stack, byte original) { return 1; } @Override public byte getMiniBlockCount(ItemStack stack, byte original) { return 1; } @Override public boolean shouldBob() { return true; } @Override public boolean shouldSpreadItems() { return false; } }; renderItems.setRenderManager(RenderManager.instance); model = new ModelStand(); } @Override public void renderTileEntityAt(TileEntity t, double x, double y, double z, float f) { if (t == null | !(t instanceof TileStand)) { return; } TileStand ts = (TileStand) t; GL11.glPushMatrix(); GL11.glTranslatef((float) x + 0.5F, (float) y + 0.065F, (float) z + 0.5F); GL11.glPushMatrix(); GL11.glRotatef(180F, 0, 0, 1); Minecraft.getMinecraft().renderEngine.bindTexture(texture); glEnable(32826); Utils.adjustLighting(t.getWorldObj(), t.xCoord, t.yCoord, t.zCoord, t.getWorldObj().getBlock(t.xCoord, t.yCoord, t.zCoord)); model.render(null, 0, 0, -0.1F, 0, 0, 0.0625F); glDisable(32826); GL11.glPopMatrix(); GL11.glPopMatrix(); if (doRender && ts.getWorldObj().getBlock(ts.xCoord, ts.yCoord + 1, ts.zCoord) == Blocks.air && ts.getWorldObj().getClosestPlayer(ts.xCoord, ts.yCoord, ts.zCoord, 25) != null && !mc.isGamePaused()) { if (!ts.hasItem()) { return; } ItemStack stack = ts.getHeldItem(); EntityItem ei = new EntityItem(ts.getWorldObj()); ei.hoverStart = 0; ei.setEntityItemStack(stack); glPushMatrix(); glColor4f(1.0F, 1.0F, 1.0F, 1.0F); glEnable(32826); glTranslatef((float) x, (float) y, (float) z); OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 170F, 170F); glColor4f(1.0F, 1.0F, 1.0F, 1.0F); float rotational = (Minecraft.getSystemTime()) / (3000.0F) * 300.0F; float scale = 2.0F; if (Block.getBlockFromItem(stack.getItem()) != null) { glPushMatrix(); glTranslatef(0.5F, 0.8F, 0.5F); GL11.glScalef(scale, scale, scale); glRotatef(rotational / SPEED, 0F, 1F, 0F); renderItems.doRender(ei, 0, 0, 0, 0, 1); glPopMatrix(); } else { glPushMatrix(); glTranslatef(0.5F, 1.1F, 0.5F); GL11.glScalef(scale, scale, scale); glRotatef(rotational / SPEED, 0F, 1.0F, 0F); renderItems.doRender(ei, 0, 0, 0, 0, 1.0F); glPopMatrix(); } glDisable(32826); glColor4f(1.0F, 1.0F, 1.0F, 1.0F); glPopMatrix(); } } }