Advertisement
bloxgate

TileEntitySpecialRenderSpaceTimeAnomaly

Jun 9th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.11 KB | None | 0 0
  1. class TileEntitySpecialRendererSpaceTimeAnomaly : TileEntitySpecialRenderer<TileEntity>() {
  2.  
  3.     companion object {
  4.         val model = ModelCache.models.get("/assets/timecraft/models/block/spaceTimeAnomaly.obj")
  5.     }
  6.  
  7.     override fun renderTileEntityAt(te: TileEntity, x: Double, y: Double, z: Double, partialTicks: Float, destroyStage: Int) {
  8.  
  9.         var teSA = te as TileEntitySpaceTimeAnomaly
  10.         try {
  11.             GlStateManager.pushMatrix()
  12.             GL11.glPushAttrib(GL11.GL_ENABLE_BIT)
  13.             GlStateManager.translate(x, y, z)
  14.  
  15.             GL11.glTranslatef(0.5f, 0.5f, 0.5f)
  16.             GlStateManager.rotate(teSA.getNextAngularPosition(0.03333).toFloat(), 0f, 1f, 0f)
  17.             GlStateManager.translate(-0.5f, -0.5f, -0.5f)
  18.  
  19.             val tessellator = Tessellator.getInstance()
  20.             val wr = tessellator.worldRenderer
  21.  
  22.             GL11.glDepthMask(true)
  23.             this.bindTexture(texture)
  24.             wr.begin(GL11.GL_TRIANGLES, DefaultVertexFormats.POSITION_NORMAL)
  25.  
  26.             addIcoSphereVertices(wr)
  27.             tessellator.draw()
  28.  
  29.         } finally {
  30.             GL11.glPopAttrib()
  31.             GlStateManager.popMatrix()
  32.         }
  33.     }
  34.  
  35.     fun addIcoSphereVertices(wr: WorldRenderer) {
  36.  
  37.         for (face in model.faces) {
  38.             val n1 = model.normals[face.normal.x.toInt() - 1]
  39.             val v1 = model.vertices[face.vertex.x.toInt() - 1]
  40.             val n2 = model.normals[face.normal.y.toInt() - 1]
  41.             val v2 = model.vertices[face.vertex.y.toInt() - 1]
  42.             val n3 = model.normals[face.normal.z.toInt() - 1]
  43.             val v3 = model.vertices[face.vertex.z.toInt() - 1]
  44.             wr.pos(v1.x.toDouble(), v1.y.toDouble(), v1.z.toDouble()).normal(n1.x, n1.y, n1.z).endVertex()
  45.             wr.pos(v2.x.toDouble(), v2.y.toDouble(), v2.z.toDouble()).normal(n2.x, n2.y, n2.z).endVertex()
  46.             wr.pos(v3.x.toDouble(), v3.y.toDouble(), v3.z.toDouble()).normal(n3.x, n3.y, n3.z).endVertex()
  47.         }
  48.     }
  49.  
  50.     internal val texture: ResourceLocation = ResourceLocation(Reference.MODID + ":textures/blocks/spaceTimeAnomaly.png")
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement