Advertisement
Guest User

Untitled

a guest
Mar 13th, 2015
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.89 KB | None | 0 0
  1. public class FuelBlockRenderHandler implements ISimpleBlockRenderingHandler{
  2.  
  3. public static int lightValue;
  4.  
  5. @Override
  6. public void renderInventoryBlock(Block block, int metadata, int modelId, RenderBlocks renderer) {
  7. /* TODO: Make this fucker work so the blocks render in hand */
  8. }
  9.  
  10. @Override
  11. public boolean renderWorldBlock(IBlockAccess world, int xCoord, int yCoord, int zCoord, Block block, int modelId, RenderBlocks renderer) {
  12. BlockFuel blockFuel = (BlockFuel) world.getBlock(xCoord, yCoord, zCoord);
  13. IIcon overlayFade = blockFuel.getIcon(1, 11);
  14. IIcon overlayBox = blockFuel.getIcon(1, 12);
  15. IIcon overlayCorners = blockFuel.getIcon(1, 13);
  16. IIcon coalTexture = Blocks.coal_block.getIcon(1, 0);
  17.  
  18. lightValue = blockFuel.getMixedBrightnessForBlock(world, xCoord, yCoord, zCoord);
  19. int worldBlockMetaData = world.getBlockMetadata(xCoord, yCoord, zCoord);
  20.  
  21. float redRGB[] = new float[] {
  22. 204, 0, 0
  23. };
  24. float cyanRGB[] = new float[] {
  25. 0, 153, 153
  26. };
  27. float blackRGB[] = new float[] {
  28. 0, 0, 0
  29. };
  30. float purpleRGB[] = new float[] {
  31. 153, 0, 153
  32. };
  33. float goldRGB[] = new float[] {
  34. 204, 204, 0
  35. };
  36. float brownRGB[] = new float[] {
  37. 102, 51, 0
  38. };
  39.  
  40. int R = 0;
  41. int G = 1;
  42. int B = 2;
  43.  
  44. float overlayFadeAlpha = 1.0F;
  45. float overlayBoxAlpha = 1.5F;
  46. float overlayCornersAlpha = 1.5F;
  47. Tessellator t = Tessellator.instance;
  48.  
  49. if (Client.renderPass == 0) {
  50. /* Render the block texture itself */
  51. renderer.overrideBlockTexture = coalTexture;
  52. renderer.renderStandardBlock(blockFuel, xCoord, yCoord, zCoord);
  53. /* Render the Opaque item onto the block face */
  54. renderer.overrideBlockTexture = blockFuel.getIcon(1, Metadata.ARCANE_FUEL);
  55. drawItemOntoBlock(blockFuel.getIcon(1, Metadata.ARCANE_FUEL), xCoord, yCoord, zCoord, 1, t);
  56. renderer.overrideBlockTexture = overlayBox;
  57. drawColoredTextureToBlock(overlayBox, xCoord, yCoord, zCoord, goldRGB[R], goldRGB[G], goldRGB[B], overlayBoxAlpha, 2, t);
  58. renderer.overrideBlockTexture = overlayCorners;
  59. drawColoredTextureToBlock(overlayCorners, xCoord, yCoord, zCoord, brownRGB[R], brownRGB[G], brownRGB[B], overlayCornersAlpha, 3, t);
  60. renderer.clearOverrideBlockTexture();
  61. } else if (Client.renderPass == 1) {
  62. switch (worldBlockMetaData) {
  63. case Metadata.ARCANE_FUEL:
  64. /* Transparent Cyan Texture */
  65. renderer.overrideBlockTexture = overlayFade;
  66. drawColoredTextureToBlock(overlayFade, xCoord, yCoord, zCoord, cyanRGB[R], cyanRGB[G], cyanRGB[B], overlayFadeAlpha, 1, t);
  67. renderer.clearOverrideBlockTexture();
  68. break;
  69. case Metadata.TAINT_INFUSED_COAL:
  70. /* Transparent Purple Texture */
  71. renderer.overrideBlockTexture = overlayFade;
  72. drawColoredTextureToBlock(overlayFade, xCoord, yCoord, zCoord, purpleRGB[R], purpleRGB[G], purpleRGB[B], overlayFadeAlpha, 1, t);
  73. renderer.clearOverrideBlockTexture();
  74. break;
  75. case Metadata.COMBUSIBLE_DARK_MATTER:
  76. /* Transparent Black Texture */
  77. renderer.overrideBlockTexture = overlayFade;
  78. drawColoredTextureToBlock(overlayFade, xCoord, yCoord, zCoord, blackRGB[R], blackRGB[G], blackRGB[B], overlayFadeAlpha, 1, t);
  79. renderer.clearOverrideBlockTexture();
  80. break;
  81. case Metadata.COSMIC_INCENDIARY_CHUNK:
  82. /* Transparent Red Texture */
  83. renderer.overrideBlockTexture = overlayFade;
  84. drawColoredTextureToBlock(overlayFade, xCoord, yCoord, zCoord, redRGB[R], redRGB[G], redRGB[B], overlayFadeAlpha, 1, t);
  85. renderer.clearOverrideBlockTexture();
  86. break;
  87. }
  88. }
  89. return true;
  90. }
  91.  
  92. @Override
  93. public boolean shouldRender3DInInventory(int modelId) {
  94. return true;
  95. }
  96.  
  97. @Override
  98. public int getRenderId() {
  99. return Client.fuelBlockRenderTypeID;
  100. }
  101.  
  102. public void drawItemOntoBlock(IIcon icon, int xCoord, int yCoord, int zCoord, int layer, Tessellator t) {
  103. addBlockVeticies(t, xCoord, yCoord, zCoord, icon, "North", layer);
  104. addBlockVeticies(t, xCoord, yCoord, zCoord, icon, "South", layer);
  105. addBlockVeticies(t, xCoord, yCoord, zCoord, icon, "West", layer);
  106. addBlockVeticies(t, xCoord, yCoord, zCoord, icon, "East", layer);
  107. }
  108.  
  109. public void drawColoredTextureToBlock(IIcon icon, int xCoord, int yCoord, int zCoord, float r, float g, float b, float alpha, int layer, Tessellator t) {
  110. t.setColorRGBA_F(r, g, b, alpha);
  111. addBlockVeticies(t, xCoord, yCoord, zCoord, icon, "North", layer);
  112. addBlockVeticies(t, xCoord, yCoord, zCoord, icon, "South", layer);
  113. addBlockVeticies(t, xCoord, yCoord, zCoord, icon, "West", layer);
  114. addBlockVeticies(t, xCoord, yCoord, zCoord, icon, "East", layer);
  115. addBlockVeticies(t, xCoord, yCoord, zCoord, icon, "Up", layer);
  116. }
  117.  
  118. public void addBlockVeticies(Tessellator t, int xCoord, int yCoord, int zCoord, IIcon icon, String side, int layer) {
  119. float iconMaxU = icon.getMaxU();
  120. float iconMaxV = icon.getMaxV();
  121. float iconMinU = icon.getMinU();
  122. float iconMinV = icon.getMinV();
  123. float xAdd = 1.0001F;
  124. float yAdd = 1.0001F;
  125. float zAdd = 1.0001F;
  126. float setLayerLevel = 0.0F;
  127.  
  128. for (int layerLevel = 0; layerLevel < layer; layerLevel++) {
  129. setLayerLevel = setLayerLevel + 0.0002F;
  130. }
  131.  
  132. //t.setBrightness(lightValue);
  133.  
  134. if (side.equals("North")) {
  135. //North
  136. GL11.glPushMatrix();
  137. t.addVertexWithUV(xCoord + xAdd,yCoord + yAdd, zCoord - setLayerLevel, iconMinU, iconMinV);
  138. t.addVertexWithUV(xCoord + xAdd,yCoord, zCoord - setLayerLevel, iconMinU, iconMaxV);
  139. t.addVertexWithUV(xCoord, yCoord, zCoord - setLayerLevel, iconMaxU, iconMaxV);
  140. t.addVertexWithUV(xCoord, yCoord + yAdd, zCoord - setLayerLevel, iconMaxU, iconMinV);
  141. GL11.glPopMatrix();
  142. } else if (side.equals("Up")) {
  143. //Up
  144. GL11.glPushMatrix();
  145. t.addVertexWithUV(xCoord, yCoord + yAdd + setLayerLevel, zCoord + zAdd, iconMinU, iconMinV);
  146. t.addVertexWithUV(xCoord + xAdd,yCoord + yAdd + setLayerLevel, zCoord + zAdd, iconMinU, iconMaxV);
  147. t.addVertexWithUV(xCoord + xAdd,yCoord + yAdd + setLayerLevel, zCoord, iconMaxU, iconMaxV);
  148. t.addVertexWithUV(xCoord, yCoord + yAdd + setLayerLevel, zCoord, iconMaxU, iconMinV);
  149. GL11.glPopMatrix();
  150. } else if (side.equals("Down")) {
  151. //Down
  152. GL11.glPushMatrix();
  153. t.addVertexWithUV(xCoord, yCoord - setLayerLevel, zCoord, iconMinU, iconMinV);
  154. t.addVertexWithUV(xCoord, yCoord - setLayerLevel, zCoord + zAdd, iconMinU, iconMaxV);
  155. t.addVertexWithUV(xCoord + xAdd,yCoord - setLayerLevel, zCoord + zAdd, iconMaxU, iconMaxV);
  156. t.addVertexWithUV(xCoord + xAdd,yCoord - setLayerLevel, zCoord, iconMaxU, iconMinV);
  157. GL11.glPopMatrix();
  158. } else if (side.equals("West")) {
  159. //West
  160. GL11.glPushMatrix();
  161. t.addVertexWithUV(xCoord + xAdd + setLayerLevel,yCoord + yAdd, zCoord + zAdd, iconMinU, iconMinV);
  162. t.addVertexWithUV(xCoord + xAdd + setLayerLevel,yCoord, zCoord + zAdd, iconMinU, iconMaxV);
  163. t.addVertexWithUV(xCoord + xAdd + setLayerLevel,yCoord, zCoord, iconMaxU, iconMaxV);
  164. t.addVertexWithUV(xCoord + xAdd + setLayerLevel,yCoord + yAdd, zCoord, iconMaxU, iconMinV);
  165. GL11.glPopMatrix();
  166. } else if (side.equals("South")) {
  167. //South
  168. GL11.glPushMatrix();
  169. t.addVertexWithUV(xCoord + xAdd,yCoord + yAdd, zCoord + zAdd + setLayerLevel, iconMinU, iconMinV);
  170. t.addVertexWithUV(xCoord + xAdd,yCoord, zCoord + zAdd + setLayerLevel, iconMinU, iconMaxV);
  171. t.addVertexWithUV(xCoord, yCoord, zCoord + zAdd + setLayerLevel, iconMinU, iconMinV);
  172. t.addVertexWithUV(xCoord, yCoord + yAdd, zCoord + zAdd + setLayerLevel, iconMinU, iconMaxV);
  173. GL11.glPopMatrix();
  174. } else if (side.equals("East")) {
  175. //East
  176. GL11.glPushMatrix();
  177. t.addVertexWithUV(xCoord - setLayerLevel, yCoord + yAdd, zCoord + zAdd, iconMinU, iconMinV);
  178. t.addVertexWithUV(xCoord - setLayerLevel, yCoord, zCoord + zAdd, iconMinU, iconMaxV);
  179. t.addVertexWithUV(xCoord - setLayerLevel, yCoord, zCoord, iconMaxU, iconMaxV);
  180. t.addVertexWithUV(xCoord - setLayerLevel, yCoord + yAdd, zCoord, iconMaxU, iconMinV);
  181. GL11.glPopMatrix();
  182. }
  183. }
  184. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement