Guest User

Untitled

a guest
Mar 9th, 2015
400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.71 KB | None | 0 0
  1. public class FuelBlockRenderHandler implements ISimpleBlockRenderingHandler{
  2.  
  3. @Override
  4. public void renderInventoryBlock(Block block, int metadata, int modelId, RenderBlocks renderer) {
  5.  
  6. }
  7.  
  8. @Override
  9. public boolean renderWorldBlock(IBlockAccess world, int xCoord, int yCoord, int zCoord, Block block, int modelId, RenderBlocks renderer) {
  10. BlockFuel blockFuel = (BlockFuel) world.getBlock(xCoord, yCoord, zCoord);
  11. int worldBlockMetaData = world.getBlockMetadata(xCoord, yCoord, zCoord);
  12. int worldLightValue = blockFuel.getMixedBrightnessForBlock(world, xCoord, yCoord, zCoord);
  13.  
  14. Tessellator t = Tessellator.instance;
  15.  
  16. if (Client.renderPass == 0) {
  17. /* Render the block texture itself */
  18. //renderer.overrideBlockTexture = Blocks.coal_block.getIcon(1, 0);
  19. //renderer.renderStandardBlock(blockFuel, xCoord, yCoord, zCoord);
  20. /* Render the Item in the center of the block face */
  21. renderer.overrideBlockTexture = blockFuel.getIcon(1, Metadata.ARCANE_FUEL);
  22. drawItemOntoBlock(blockFuel.getIcon(1, Metadata.ARCANE_FUEL), xCoord, yCoord, zCoord, worldLightValue, t);
  23. renderer.clearOverrideBlockTexture();
  24. } else if (Client.renderPass == 1) {
  25. switch (worldBlockMetaData) {
  26. case Metadata.ARCANE_FUEL:
  27. /* Transparent Cyan Texture */
  28. //renderer.overrideBlockTexture = blockFuel.getIcon(1, 11);
  29. //drawFuelBlock(blockFuel, xCoordD, yCoordD, zCoordD, Metadata.ARCANE_FUEL, worldLightValue, t);
  30. //renderer.clearOverrideBlockTexture();
  31. break;
  32. case Metadata.TAINT_INFUSED_COAL:
  33. /* Transparent Purple Texture */
  34. //renderer.overrideBlockTexture = blockFuel.getIcon(1, 11);
  35. //drawFuelBlock(blockFuel, xCoordD, yCoordD, zCoordD, Metadata.TAINT_INFUSED_COAL, worldLightValue, t);
  36. //renderer.clearOverrideBlockTexture();
  37. break;
  38. case Metadata.COMBUSIBLE_DARK_MATTER:
  39. /* Transparent Black Texture */
  40. //renderer.overrideBlockTexture = blockFuel.getIcon(1, 11);
  41. //drawFuelBlock(blockFuel, xCoordD, yCoordD, zCoordD, Metadata.COMBUSIBLE_DARK_MATTER, worldLightValue, t);
  42. //renderer.clearOverrideBlockTexture();
  43. break;
  44. case Metadata.COSMIC_INCENDIARY_CHUNK:
  45. /* Transparent Red Texture */
  46. //renderer.overrideBlockTexture = blockFuel.getIcon(1, 11);
  47. //drawFuelBlock(blockFuel, xCoordD, yCoordD, zCoordD, Metadata.COSMIC_INCENDIARY_CHUNK, worldLightValue, t);
  48. //renderer.clearOverrideBlockTexture();
  49. break;
  50. }
  51. }
  52. return true;
  53. }
  54.  
  55. @Override
  56. public boolean shouldRender3DInInventory(int modelId) {
  57. return true;
  58. }
  59.  
  60. @Override
  61. public int getRenderId() {
  62. return Client.fuelBlockRenderTypeID;
  63. }
  64.  
  65. public void drawItemOntoBlock(IIcon icon, int xCoord, int yCoord, int zCoord, int light, Tessellator t) {
  66.  
  67. /* TODO: Find a way to scale / reposition the texture on the block face.
  68. * TODO: Only insert vanilla coal texture, try to have no textures created manually.
  69. * TODO: Play with GL11 scale methods
  70. * TODO: World goes transparent when block is placed below ground? */
  71.  
  72. GL11.glEnable(GL11.GL_BLEND);
  73. t.addTranslation(xCoord, yCoord, zCoord);
  74. addBlockVeticies(t, xCoord, yCoord, zCoord, icon, "Down");
  75. }
  76.  
  77. public void drawFuelBlock(Block block, int xCoord, int yCoord, int zCoord, int metaData, int light, Tessellator t) {
  78. IIcon overlay = block.getIcon(1, 11);
  79.  
  80. float overlayMaxV = overlay.getMaxV();
  81. float overlayMinV = overlay.getMinV();
  82. float overlayWidth = overlay.getIconWidth();
  83. float overlayHeight = overlay.getIconHeight();
  84. float overlayMaxU = overlay.getMaxU();
  85. float overlayMinU = overlay.getMinU();
  86.  
  87. float redRGB[] = new float[] {
  88. 198, 52, 52
  89. };
  90. float cyanRGB[] = new float[] {
  91. 0, 153, 153
  92. };
  93. float blackRGB[] = new float[] {
  94. 0, 0, 0
  95. };
  96. float purpleRGB[] = new float[] {
  97. 153, 0, 153
  98. };
  99. int R = 0;
  100. int G = 1;
  101. int B = 2;
  102.  
  103. float overlayAlpha = 0.20F;
  104.  
  105. GL11.glEnable(GL11.GL_BLEND);
  106. t.setBrightness(light);
  107. switch (metaData) {
  108. case Metadata.ARCANE_FUEL:
  109. t.setColorRGBA_F(cyanRGB[R], cyanRGB[G], cyanRGB[B], overlayAlpha);
  110. break;
  111. case Metadata.TAINT_INFUSED_COAL:
  112. t.setColorRGBA_F(purpleRGB[R], purpleRGB[G], purpleRGB[B], overlayAlpha);
  113. break;
  114. case Metadata.COMBUSIBLE_DARK_MATTER:
  115. t.setColorRGBA_F(blackRGB[R], blackRGB[G], blackRGB[B], overlayAlpha);
  116. break;
  117. case Metadata.COSMIC_INCENDIARY_CHUNK:
  118. t.setColorRGBA_F(redRGB[R], redRGB[G], redRGB[B], overlayAlpha);
  119. break;
  120. }
  121. }
  122.  
  123. public void addBlockVeticies(Tessellator t, int xCoord, int yCoord, int zCoord, IIcon icon, String side) {
  124. float iconMaxU = icon.getMaxU();
  125. float iconMaxV = icon.getMaxV();
  126. float iconMinU = icon.getMinU();
  127. float iconMinV = icon.getMinV();
  128.  
  129. /* Block X Value Block Y Value Block Z Value Icon X Value, Icon Y Value */
  130. if (side.equals("Down")) {
  131. /* Test */
  132. t.addVertexWithUV(xCoord + 0, yCoord + 0, zCoord + 0, iconMinU, iconMinV);
  133. t.addVertexWithUV(xCoord + 0, yCoord + 1.0002F, zCoord + 0, iconMinU, iconMaxV);
  134. t.addVertexWithUV(xCoord + 1.0002F, yCoord + 1.0002F, zCoord + 0, iconMaxU, iconMaxV);
  135. t.addVertexWithUV(xCoord + 1.0002F, yCoord + 0, zCoord + 0, iconMaxU, iconMinV);
  136. } else if (side.equals("Up")) {
  137. /* Test */
  138. t.addVertexWithUV(xCoord + 0, yCoord + 1.0002F, zCoord + 1.0002F, iconMinU, iconMinV);
  139. t.addVertexWithUV(xCoord + 1.0002F, yCoord + 1.0002F, zCoord + 1.0002F, iconMinU, iconMaxV);
  140. t.addVertexWithUV(xCoord + 1.0002F, yCoord + 1.0002F, zCoord + 0, iconMaxU, iconMaxV);
  141. t.addVertexWithUV(xCoord + 0, yCoord + 1.0002F, zCoord + 0, iconMaxU, iconMinV);
  142. } else if (side.equals("North")) {
  143. /* Test */
  144. t.addVertexWithUV(xCoord + 0, yCoord + 0, zCoord + 1.0002F, iconMinU, iconMinV);
  145. t.addVertexWithUV(xCoord + 0, yCoord + 1.0002F, zCoord + 1.0002F, iconMinU, iconMaxV);
  146. t.addVertexWithUV(xCoord + 1.0002F, yCoord + 1.0002F, zCoord + 1.0002F, iconMaxU, iconMaxV);
  147. t.addVertexWithUV(xCoord + 1.0002F, yCoord + 0, zCoord + 1.0002F, iconMaxU, iconMinV);
  148. } else if (side.equals("West")) {
  149. /* Not Done */
  150. t.addVertexWithUV(xCoord + 0, yCoord + 0, zCoord + 1.0002F, iconMinU, iconMinV);
  151. t.addVertexWithUV(xCoord + 0, yCoord + 1.0002F, zCoord + 1.0002F, iconMinU, iconMaxV);
  152. t.addVertexWithUV(xCoord + 1.0002F, yCoord + 1.0002F, zCoord + 1.0002F, iconMaxU, iconMaxV);
  153. t.addVertexWithUV(xCoord + 1.0002F, yCoord + 0, zCoord + 1.0002F, iconMaxU, iconMinV);
  154. } else if (side.equals("South")) {
  155. /* Test */
  156. t.addVertexWithUV(xCoord + 0, yCoord + 0, zCoord + 0, iconMinU, iconMinV);
  157. t.addVertexWithUV(xCoord + 0, yCoord + 1.0002F, zCoord + 0, iconMinU, iconMaxV);
  158. t.addVertexWithUV(xCoord + 1.0002F, yCoord + 1.0002F, zCoord + 0, iconMaxU, iconMaxV);
  159. t.addVertexWithUV(xCoord + 1.0002F, yCoord + 0, zCoord + 0, iconMaxU, iconMinV);
  160. } else if (side.equals("East")) {
  161. /* Not Done */
  162. t.addVertexWithUV(xCoord + 0, yCoord + 0, zCoord + 0, iconMinU, iconMinV);
  163. t.addVertexWithUV(xCoord + 0, yCoord + 1.0002F, zCoord + 0, iconMinU, iconMaxV);
  164. t.addVertexWithUV(xCoord + 1.0002F, yCoord + 1.0002F, zCoord + 0, iconMaxU, iconMaxV);
  165. t.addVertexWithUV(xCoord + 1.0002F, yCoord + 0, zCoord + 0, iconMaxU, iconMinV);
  166. }
  167.  
  168. }
  169. }
Advertisement
Add Comment
Please, Sign In to add comment