Java tutorial
/** * This work is made available under the terms of the Creative Commons Attribution License: * http://creativecommons.org/licenses/by-nc-sa/4.0/deed.en * * Cette uvre est mise disposition selon les termes de la Licence Creative Commons Attribution: * http://creativecommons.org/licenses/by-nc-sa/4.0/deed.fr */ package fr.mcnanotech.kevin_68.nanotechmod.main.client.renderer; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.entity.Render; import net.minecraft.entity.Entity; import net.minecraft.util.MathHelper; import net.minecraft.util.ResourceLocation; import net.minecraft.util.Vec3; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL12; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import fr.mcnanotech.kevin_68.nanotechmod.main.entity.others.EntityReinforcedFishingHook; @SideOnly(Side.CLIENT) public class RenderReinforcedFishingHook extends Render { private static final ResourceLocation texture = new ResourceLocation("textures/particle/particles.png"); public void doRenderFishHook(EntityReinforcedFishingHook entityFishHook, double par2, double par4, double par6, float par8, float par9) { GL11.glPushMatrix(); GL11.glTranslatef((float) par2, (float) par4, (float) par6); GL11.glEnable(GL12.GL_RESCALE_NORMAL); GL11.glScalef(0.5F, 0.5F, 0.5F); this.bindEntityTexture(entityFishHook); Tessellator tessellator = Tessellator.instance; byte b0 = 1; byte b1 = 2; float f2 = (b0 * 8 + 0) / 128.0F; float f3 = (b0 * 8 + 8) / 128.0F; float f4 = (b1 * 8 + 0) / 128.0F; float f5 = (b1 * 8 + 8) / 128.0F; float f6 = 1.0F; float f7 = 0.5F; float f8 = 0.5F; GL11.glRotatef(180.0F - this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F); GL11.glRotatef(-this.renderManager.playerViewX, 1.0F, 0.0F, 0.0F); tessellator.startDrawingQuads(); tessellator.setNormal(0.0F, 1.0F, 0.0F); tessellator.addVertexWithUV(0.0F - f7, 0.0F - f8, 0.0D, f2, f5); tessellator.addVertexWithUV(f6 - f7, 0.0F - f8, 0.0D, f3, f5); tessellator.addVertexWithUV(f6 - f7, 1.0F - f8, 0.0D, f3, f4); tessellator.addVertexWithUV(0.0F - f7, 1.0F - f8, 0.0D, f2, f4); tessellator.draw(); GL11.glDisable(GL12.GL_RESCALE_NORMAL); GL11.glPopMatrix(); if (entityFishHook.angler != null) { float f9 = entityFishHook.angler.getSwingProgress(par9); float f10 = MathHelper.sin(MathHelper.sqrt_float(f9) * (float) Math.PI); Vec3 vec3 = Vec3.createVectorHelper(-0.5D, 0.03D, 0.8D); vec3.rotateAroundX(-(entityFishHook.angler.prevRotationPitch + (entityFishHook.angler.rotationPitch - entityFishHook.angler.prevRotationPitch) * par9) * (float) Math.PI / 180.0F); vec3.rotateAroundY(-(entityFishHook.angler.prevRotationYaw + (entityFishHook.angler.rotationYaw - entityFishHook.angler.prevRotationYaw) * par9) * (float) Math.PI / 180.0F); vec3.rotateAroundY(f10 * 0.5F); vec3.rotateAroundX(-f10 * 0.7F); double d3 = entityFishHook.angler.prevPosX + (entityFishHook.angler.posX - entityFishHook.angler.prevPosX) * par9 + vec3.xCoord; double d4 = entityFishHook.angler.prevPosY + (entityFishHook.angler.posY - entityFishHook.angler.prevPosY) * par9 + vec3.yCoord; double d5 = entityFishHook.angler.prevPosZ + (entityFishHook.angler.posZ - entityFishHook.angler.prevPosZ) * par9 + vec3.zCoord; double d6 = entityFishHook.angler == Minecraft.getMinecraft().thePlayer ? 0.0D : (double) entityFishHook.angler.getEyeHeight(); if (this.renderManager.options.thirdPersonView > 0 || entityFishHook.angler != Minecraft.getMinecraft().thePlayer) { float f11 = (entityFishHook.angler.prevRenderYawOffset + (entityFishHook.angler.renderYawOffset - entityFishHook.angler.prevRenderYawOffset) * par9) * (float) Math.PI / 180.0F; double d7 = MathHelper.sin(f11); double d8 = MathHelper.cos(f11); d3 = entityFishHook.angler.prevPosX + (entityFishHook.angler.posX - entityFishHook.angler.prevPosX) * par9 - d8 * 0.35D - d7 * 0.85D; d4 = entityFishHook.angler.prevPosY + d6 + (entityFishHook.angler.posY - entityFishHook.angler.prevPosY) * par9 - 0.45D; d5 = entityFishHook.angler.prevPosZ + (entityFishHook.angler.posZ - entityFishHook.angler.prevPosZ) * par9 - d7 * 0.35D + d8 * 0.85D; } double d9 = entityFishHook.prevPosX + (entityFishHook.posX - entityFishHook.prevPosX) * par9; double d10 = entityFishHook.prevPosY + (entityFishHook.posY - entityFishHook.prevPosY) * par9 + 0.25D; double d11 = entityFishHook.prevPosZ + (entityFishHook.posZ - entityFishHook.prevPosZ) * par9; double d12 = ((float) (d3 - d9)); double d13 = ((float) (d4 - d10)); double d14 = ((float) (d5 - d11)); GL11.glDisable(GL11.GL_TEXTURE_2D); GL11.glDisable(GL11.GL_LIGHTING); tessellator.startDrawing(3); tessellator.setColorOpaque_I(0); byte b2 = 16; for (int i = 0; i <= b2; ++i) { float f12 = (float) i / (float) b2; tessellator.addVertex(par2 + d12 * f12, par4 + d13 * (f12 * f12 + f12) * 0.5D + 0.25D, par6 + d14 * f12); } tessellator.draw(); GL11.glEnable(GL11.GL_LIGHTING); GL11.glEnable(GL11.GL_TEXTURE_2D); } } protected ResourceLocation getTexture(EntityReinforcedFishingHook entityFishHook) { return texture; } @Override protected ResourceLocation getEntityTexture(Entity entity) { return this.getTexture((EntityReinforcedFishingHook) entity); } @Override public void doRender(Entity entity, double par2, double par4, double par6, float par8, float par9) { this.doRenderFishHook((EntityReinforcedFishingHook) entity, par2, par4, par6, par8, par9); } }