Advertisement
Guest User

Untitled

a guest
Jul 12th, 2017
505
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.34 KB | None | 0 0
  1. open class WorkingAreaRenderer<T: ElectricFarmMachine> : HudInfoRenderer<T>() {
  2. private var cR: Float = .9f
  3. private var cG: Float = .7f
  4. private var cB: Float = .0f
  5.  
  6. override fun render(te: T, x: Double, y: Double, z: Double, partialTicks: Float, destroyStage: Int, alpha: Float) {
  7. super.render(te, x, y, z, partialTicks, destroyStage, alpha)
  8.  
  9. if (te.showWorkArea) {
  10. val area = te.getWorkArea()
  11.  
  12. val color = te.getWorkAreaColor()
  13.  
  14. this.cR = (color shr 16 and 255).toFloat() / 255.0f
  15. this.cB = (color shr 8 and 255).toFloat() / 255.0f
  16. this.cG = (color and 255).toFloat() / 255.0f
  17.  
  18. GlStateManager.pushMatrix()
  19. GlStateManager.pushAttrib()
  20.  
  21. GlStateManager.translate(x.toFloat(), y.toFloat(), z.toFloat())
  22. RenderHelper.disableStandardItemLighting()
  23. Minecraft.getMinecraft().entityRenderer.disableLightmap()
  24. GlStateManager.disableTexture2D()
  25. GlStateManager.disableBlend()
  26. GlStateManager.disableLighting()
  27. GlStateManager.disableAlpha()
  28. GlStateManager.glLineWidth(2f)
  29. GlStateManager.color(1f, 1f, 1f)
  30.  
  31. val box = area.boundingBox.offset(-te.pos.x.toDouble(), -te.pos.y.toDouble(), -te.pos.z.toDouble())
  32. this.renderCubeOutline(box)
  33.  
  34. GlStateManager.enableAlpha()
  35. GlStateManager.enableBlend()
  36. GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA)
  37.  
  38. this.renderCubeFaces(box)
  39.  
  40. Minecraft.getMinecraft().entityRenderer.enableLightmap()
  41. GlStateManager.enableTexture2D()
  42. GlStateManager.popAttrib()
  43. GlStateManager.popMatrix()
  44. }
  45. }
  46.  
  47. private fun BufferBuilder.posEx(x: Double, y: Double, z: Double): BufferBuilder {
  48. this.pos(x, y, z).color(this@WorkingAreaRenderer.cR, this@WorkingAreaRenderer.cG, this@WorkingAreaRenderer.cB, 1f).endVertex()
  49. return this
  50. }
  51.  
  52. private fun BufferBuilder.posExA(x: Double, y: Double, z: Double): BufferBuilder {
  53. this.pos(x, y, z).color(this@WorkingAreaRenderer.cR, this@WorkingAreaRenderer.cG, this@WorkingAreaRenderer.cB, .42f).endVertex()
  54. return this
  55. }
  56.  
  57. private fun renderCubeOutline(pos: AxisAlignedBB) {
  58. val buffer = Tessellator.getInstance().buffer
  59.  
  60. val x1 = pos.minX
  61. val x2 = pos.maxX
  62. val y1 = pos.minY
  63. val y2 = pos.maxY
  64. val z1 = pos.minZ
  65. val z2 = pos.maxZ
  66. buffer.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION_COLOR)
  67.  
  68. buffer.posEx(x1, y1, z1)
  69. buffer.posEx(x2, y1, z1)
  70. buffer.posEx(x1, y1, z1)
  71. buffer.posEx(x1, y2, z1)
  72. buffer.posEx(x1, y1, z1)
  73. buffer.posEx(x1, y1, z2)
  74. buffer.posEx(x2, y2, z2)
  75. buffer.posEx(x1, y2, z2)
  76. buffer.posEx(x2, y2, z2)
  77. buffer.posEx(x2, y1, z2)
  78. buffer.posEx(x2, y2, z2)
  79. buffer.posEx(x2, y2, z1)
  80. buffer.posEx(x1, y2, z1)
  81. buffer.posEx(x1, y2, z2)
  82. buffer.posEx(x1, y2, z1)
  83. buffer.posEx(x2, y2, z1)
  84. buffer.posEx(x2, y1, z1)
  85. buffer.posEx(x2, y1, z2)
  86. buffer.posEx(x2, y1, z1)
  87. buffer.posEx(x2, y2, z1)
  88. buffer.posEx(x1, y1, z2)
  89. buffer.posEx(x2, y1, z2)
  90. buffer.posEx(x1, y1, z2)
  91. buffer.posEx(x1, y2, z2)
  92.  
  93. Tessellator.getInstance().draw()
  94. }
  95.  
  96. private fun renderCubeFaces(pos: AxisAlignedBB) {
  97. val buffer = Tessellator.getInstance().buffer
  98.  
  99. val x1 = pos.minX
  100. val x2 = pos.maxX
  101. val y1 = pos.minY
  102. val y2 = pos.maxY
  103. val z1 = pos.minZ
  104. val z2 = pos.maxZ
  105. buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR)
  106.  
  107. buffer.posExA(x1, y1, z1).posExA(x1, y2, z1).posExA(x2, y2, z1).posExA(x2, y1, z1)
  108. buffer.posExA(x1, y1, z2).posExA(x2, y1, z2).posExA(x2, y2, z2).posExA(x1, y2, z2)
  109.  
  110. buffer.posExA(x1, y1, z1).posExA(x2, y1, z1).posExA(x2, y1, z2).posExA(x1, y1, z2)
  111. buffer.posExA(x1, y2, z1).posExA(x1, y2, z2).posExA(x2, y2, z2).posExA(x2, y2, z1)
  112.  
  113. buffer.posExA(x1, y1, z1).posExA(x1, y1, z2).posExA(x1, y2, z2).posExA(x1, y2, z1)
  114. buffer.posExA(x2, y1, z1).posExA(x2, y2, z1).posExA(x2, y2, z2).posExA(x2, y1, z2)
  115.  
  116. Tessellator.getInstance().draw()
  117. }
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement