Java tutorial
/* Additional permission is granted, as an exception allowed under section 7 of the GNU GPLv3 to allow the inclusion of modified versions of source code derived from the decompilation of Minecraft as if they were covered by the licence. You are completely free to remove this exception, however, it will mean you are unable to convey the modifications to Minecraft files (the modifications are under the GNU GPLv3) within the files they modify unless you use a similar exception yourself. NovaCraft - Minecraft client side modding API Copyright (C) 2012 korikisulda This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package info.plugmania.novacraft.event.gui; import org.lwjgl.opengl.GL11; import org.lwjgl.util.glu.Cylinder; import org.lwjgl.util.glu.GLU; import org.lwjgl.util.glu.Sphere; import net.minecraft.client.Minecraft; import net.minecraft.src.EntityClientPlayerMP; import info.plugmania.novacraft.event.Event; import info.plugmania.novacraft.maths.Position; /** * Allows in-game rendering of lines and shapes */ public class Render3DOverlayEvent extends Event { private EntityClientPlayerMP p; public Render3DOverlayEvent() { p = Minecraft.getMinecraft().thePlayer; } public void drawLine(Position point1, Position point2, int colour, float lineWidth) { float red = (float) (colour >> 24 & 255) / 255.0F; float green = (float) (colour >> 16 & 255) / 255.0F; float blue = (float) (colour >> 8 & 255) / 255.0F; float alpha = (float) (colour & 255) / 255.0F; GL11.glColor4f(red, green, blue, alpha); GL11.glLineWidth(lineWidth); enable(); GL11.glBegin(GL11.GL_LINES); GL11.glVertex3d(point1.getX() - p.posX, point1.getY() - p.posY, point1.getZ() - p.posZ); GL11.glVertex3d(point2.getX() - p.posX, point2.getY() - p.posY, point2.getZ() - p.posZ); GL11.glEnd(); disable(); } public void drawCylinder(Position position, float radius, int slices, int stacks, float lineWidth, int colour) { float red = (float) (colour >> 24 & 255) / 255.0F; float green = (float) (colour >> 16 & 255) / 255.0F; float blue = (float) (colour >> 8 & 255) / 255.0F; float alpha = (float) (colour & 255) / 255.0F; Cylinder cylinder = new Cylinder(); enable(); GL11.glColor4f(red, green, blue, alpha); GL11.glTranslated(position.getX() - p.posX, position.getY() - p.posY, position.getZ() - p.posZ); GL11.glRotatef(600F, 1, 1, 1); GL11.glLineWidth(lineWidth); cylinder.setDrawStyle(GLU.GLU_SILHOUETTE); cylinder.draw(radius, radius, 2F, slices, stacks); disable(); } public void drawSphere(Position position, float size, int slices, int stacks, float lineWidth, int colour) { float red = (float) (colour >> 24 & 255) / 255.0F; float green = (float) (colour >> 16 & 255) / 255.0F; float blue = (float) (colour >> 8 & 255) / 255.0F; float alpha = (float) (colour & 255) / 255.0F; Sphere sphere = new Sphere(); enable(); GL11.glColor4f(red, green, blue, alpha); GL11.glTranslated(position.getX() - p.posX, position.getY() - p.posY, position.getZ() - p.posZ); GL11.glRotatef(600F, 1, 1, 1); GL11.glLineWidth(lineWidth); sphere.setDrawStyle(GLU.GLU_SILHOUETTE); sphere.draw(size, slices, stacks); disable(); } public void enable() { GL11.glPushMatrix(); GL11.glDepthMask(false); GL11.glDisable(GL11.GL_DEPTH_TEST); GL11.glEnable(GL11.GL_BLEND); ; GL11.glDisable(GL11.GL_TEXTURE_2D); GL11.glDisable(GL11.GL_LIGHTING); GL11.glBlendFunc(770, 771); GL11.glEnable(GL11.GL_LINE_SMOOTH); Minecraft.getMinecraft().entityRenderer.disableLightmap(1.0D); } public void disable() { Minecraft.getMinecraft().entityRenderer.enableLightmap(1.0D); GL11.glDepthMask(true); GL11.glEnable(GL11.GL_DEPTH_TEST); GL11.glDisable(GL11.GL_LINE_SMOOTH); GL11.glEnable(GL11.GL_LIGHTING); GL11.glDisable(GL11.GL_BLEND); GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glPopMatrix(); } }