Guest User

Untitled

a guest
Nov 29th, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.83 KB | None | 0 0
  1. package com.halestormxv.world.renderers;
  2.  
  3. import net.minecraft.client.Minecraft;
  4. import net.minecraft.client.multiplayer.WorldClient;
  5. import net.minecraft.client.renderer.RenderGlobal;
  6. import net.minecraft.client.renderer.RenderHelper;
  7. import net.minecraft.client.renderer.Tessellator;
  8. import net.minecraft.util.MathHelper;
  9. import net.minecraft.util.ResourceLocation;
  10. import net.minecraft.util.Vec3;
  11. import net.minecraftforge.client.IRenderHandler;
  12.  
  13. import org.lwjgl.opengl.GL11;
  14.  
  15. import cpw.mods.fml.relauncher.ReflectionHelper;
  16. import cpw.mods.fml.relauncher.Side;
  17. import cpw.mods.fml.relauncher.SideOnly;
  18.  
  19. public class SkyRenderer extends IRenderHandler {
  20.  
  21. private int starGLCallList;
  22. private int glSkyList;
  23. private int glSkyList2;
  24.  
  25. public SkyRenderer()
  26. {
  27. RenderGlobal renderGlobal = Minecraft.getMinecraft().renderGlobal;
  28. this.glSkyList2 = (this.glSkyList = (this.starGLCallList = ReflectionHelper.getPrivateValue(RenderGlobal.class, renderGlobal, "starGLCallList")) + 1) + 1;
  29. }
  30.  
  31. @Override
  32. @SideOnly(Side.CLIENT)
  33. public void render(float partialTicks, WorldClient world, Minecraft mc) {
  34. GL11.glDisable(GL11.GL_TEXTURE_2D);
  35. Vec3 vec3 = world.getSkyColor(mc.renderViewEntity, partialTicks);
  36. float f1 = (float) vec3.xCoord;
  37. float f2 = (float) vec3.yCoord;
  38. float f3 = (float) vec3.zCoord;
  39. float f4;
  40. if (mc.gameSettings.anaglyph)
  41. {
  42. float f5 = (f1 * 30.0F + f2 * 59.0F + f3 * 11.0F) / 100.0F;
  43. float f6 = (f1 * 30.0F + f2 * 70.0F) / 100.0F;
  44. f4 = (f1 * 30.0F + f3 * 70.0F) / 100.0F;
  45. f1 = f5;
  46. f2 = f6;
  47. f3 = f4;
  48. }
  49. GL11.glColor3f(f1, f2, f3);
  50. Tessellator tessellator1 = Tessellator.instance;
  51. GL11.glDepthMask(false);
  52. GL11.glEnable(GL11.GL_FOG);
  53. GL11.glColor3f(f1, f2, f3);
  54. GL11.glCallList(this.glSkyList);
  55. GL11.glDisable(GL11.GL_FOG);
  56. GL11.glDisable(GL11.GL_ALPHA_TEST);
  57. GL11.glEnable(GL11.GL_BLEND);
  58. GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
  59. RenderHelper.disableStandardItemLighting();
  60. float[] afloat = world.provider.calcSunriseSunsetColors(world.getCelestialAngle(partialTicks), partialTicks);
  61. float f7;
  62. float f8;
  63. float f9;
  64. float f10;
  65. if (afloat != null)
  66. {
  67. GL11.glDisable(GL11.GL_TEXTURE_2D);
  68. GL11.glShadeModel(GL11.GL_SMOOTH);
  69. GL11.glPushMatrix();
  70. GL11.glRotatef(90.0F, 1.0F, 0.0F, 0.0F);
  71. GL11.glRotatef(MathHelper.sin(world.getCelestialAngleRadians(partialTicks)) < 0.0F ? 180.0F : 0.0F, 0.0F, 0.0F, 1.0F);
  72. GL11.glRotatef(90.0F, 0.0F, 0.0F, 1.0F);
  73. f4 = afloat[0];
  74. f7 = afloat[1];
  75. f8 = afloat[2];
  76. float f11;
  77. if (mc.gameSettings.anaglyph)
  78. {
  79. f9 = (f4 * 30.0F + f7 * 59.0F + f8 * 11.0F) / 100.0F;
  80. f10 = (f4 * 30.0F + f7 * 70.0F) / 100.0F;
  81. f11 = (f4 * 30.0F + f8 * 70.0F) / 100.0F;
  82. f4 = f9;
  83. f7 = f10;
  84. f8 = f11;
  85. }
  86. tessellator1.startDrawing(6);
  87. tessellator1.setColorRGBA_F(f4, f7, f8, afloat[3]);
  88. tessellator1.addVertex(0.0D, 100.0D, 0.0D);
  89. byte b0 = 16;
  90. tessellator1.setColorRGBA_F(afloat[0], afloat[1], afloat[2], 0.0F);
  91. for (int j = 0; j <= b0; ++j)
  92. {
  93. f11 = (float) j * (float) Math.PI * 2.0F / (float) b0;
  94. float f12 = MathHelper.sin(f11);
  95. float f13 = MathHelper.cos(f11);
  96. tessellator1.addVertex((double) (f12 * 120.0F), (double) (f13 * 120.0F), (double) (-f13 * 40.0F * afloat[3]));
  97. }
  98. tessellator1.draw();
  99. GL11.glPopMatrix();
  100. GL11.glShadeModel(GL11.GL_FLAT);
  101. }
  102. GL11.glEnable(GL11.GL_TEXTURE_2D);
  103. GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
  104. GL11.glPushMatrix();
  105. f4 = 1.0F - world.getRainStrength(partialTicks);
  106. f7 = 0.0F;
  107. f8 = 0.0F;
  108. f9 = 0.0F;
  109. GL11.glColor4f(1.0F, 1.0F, 1.0F, f4);
  110. GL11.glTranslatef(f7, f8, f9);
  111. GL11.glRotatef(-90.0F, 0.0F, 1.0F, 0.0F);
  112. GL11.glRotatef(world.getCelestialAngle(partialTicks) * 360.0F, 1.0F, 0.0F, 0.0F);
  113.  
  114.  
  115. f10 = 32.0F; // Size of sun from center
  116. mc.renderEngine.bindTexture(new ResourceLocation("celestialcraft:/textures/environment/celestial_sun.png"));
  117.  
  118. tessellator1.startDrawingQuads();
  119. tessellator1.addVertexWithUV((double) (-f10), 100.0D, (double) (-f10), 0.0D, 0.0D);
  120. tessellator1.addVertexWithUV((double) f10, 100.0D, (double) (-f10), 1.0D, 0.0D);
  121. tessellator1.addVertexWithUV((double) f10, 100.0D, (double) f10, 1.0D, 1.0D);
  122. tessellator1.addVertexWithUV((double) (-f10), 100.0D, (double) f10, 0.0D, 1.0D);
  123.  
  124.  
  125. tessellator1.draw(); // Draw sun
  126.  
  127. //f10 = 15.0F; // Size of moon from center
  128. f10 = 32.0F;
  129. mc.renderEngine.bindTexture(new ResourceLocation("celestialcraft:/textures/environment/moon_phases.png"));
  130.  
  131.  
  132. int k = world.getMoonPhase();
  133. int l = k % 4;
  134. int i1 = k / 4 % 2;
  135. float f14 = (float) (l + 0) / 4.0F;
  136. float f15 = (float) (i1 + 0) / 2.0F;
  137. float f16 = (float) (l + 1) / 4.0F;
  138. float f17 = (float) (i1 + 1) / 2.0F;
  139. tessellator1.startDrawingQuads();
  140. tessellator1.addVertexWithUV((double) (-f10), -100.0D, (double) f10, (double) f16, (double) f17);
  141. tessellator1.addVertexWithUV((double) f10, -100.0D, (double) f10, (double) f14, (double) f17);
  142. tessellator1.addVertexWithUV((double) f10, -100.0D, (double) (-f10), (double) f14, (double) f15);
  143. tessellator1.addVertexWithUV((double) (-f10), -100.0D, (double) (-f10), (double) f16, (double) f15);
  144. tessellator1.draw();
  145. GL11.glDisable(GL11.GL_TEXTURE_2D);
  146. float f18 = world.getStarBrightness(partialTicks) * f4 * 8;
  147. if (f18 > 0.0F)
  148. {
  149. GL11.glColor4f(f18, f18, f18, f18);
  150. GL11.glCallList(this.starGLCallList);
  151. }
  152. GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  153. GL11.glDisable(GL11.GL_BLEND);
  154. GL11.glEnable(GL11.GL_ALPHA_TEST);
  155. GL11.glEnable(GL11.GL_FOG);
  156. GL11.glPopMatrix();
  157. GL11.glDisable(GL11.GL_TEXTURE_2D);
  158. GL11.glColor3f(0.0F, 0.0F, 0.0F);
  159. double d0 = mc.thePlayer.getPosition(partialTicks).yCoord - world.getHorizon();
  160. if (d0 < 0.0D)
  161. {
  162. GL11.glPushMatrix();
  163. GL11.glTranslatef(0.0F, 12.0F, 0.0F);
  164. GL11.glCallList(this.glSkyList2);
  165. GL11.glPopMatrix();
  166. f8 = 1.0F;
  167. f9 = -((float) (d0 + 65.0D));
  168. f10 = -f8;
  169. tessellator1.startDrawingQuads();
  170. tessellator1.setColorRGBA_I(0, 255);
  171. tessellator1.addVertex((double) (-f8), (double) f9, (double) f8);
  172. tessellator1.addVertex((double) f8, (double) f9, (double) f8);
  173. tessellator1.addVertex((double) f8, (double) f10, (double) f8);
  174. tessellator1.addVertex((double) (-f8), (double) f10, (double) f8);
  175. tessellator1.addVertex((double) (-f8), (double) f10, (double) (-f8));
  176. tessellator1.addVertex((double) f8, (double) f10, (double) (-f8));
  177. tessellator1.addVertex((double) f8, (double) f9, (double) (-f8));
  178. tessellator1.addVertex((double) (-f8), (double) f9, (double) (-f8));
  179. tessellator1.addVertex((double) f8, (double) f10, (double) (-f8));
  180. tessellator1.addVertex((double) f8, (double) f10, (double) f8);
  181. tessellator1.addVertex((double) f8, (double) f9, (double) f8);
  182. tessellator1.addVertex((double) f8, (double) f9, (double) (-f8));
  183. tessellator1.addVertex((double) (-f8), (double) f9, (double) (-f8));
  184. tessellator1.addVertex((double) (-f8), (double) f9, (double) f8);
  185. tessellator1.addVertex((double) (-f8), (double) f10, (double) f8);
  186. tessellator1.addVertex((double) (-f8), (double) f10, (double) (-f8));
  187. tessellator1.addVertex((double) (-f8), (double) f10, (double) (-f8));
  188. tessellator1.addVertex((double) (-f8), (double) f10, (double) f8);
  189. tessellator1.addVertex((double) f8, (double) f10, (double) f8);
  190. tessellator1.addVertex((double) f8, (double) f10, (double) (-f8));
  191. tessellator1.draw();
  192. }
  193. if (world.provider.isSkyColored())
  194. {
  195. GL11.glColor3f(0.2F + 0.04F, f2 * 0.2F + 0.04F, f3 * 0.6F + 0.1F);
  196. }
  197. else
  198. {
  199. GL11.glColor3f(f1, f2, f3);
  200. }
  201. GL11.glPushMatrix();
  202. GL11.glTranslatef(0.0F, -((float) (d0 - 16.0D)), 0.0F);
  203. GL11.glCallList(this.glSkyList2);
  204. GL11.glPopMatrix();
  205. GL11.glEnable(GL11.GL_TEXTURE_2D);
  206. GL11.glDepthMask(true);
  207. }
  208. }
Advertisement
Add Comment
Please, Sign In to add comment