Guest User

Untitled

a guest
Apr 9th, 2017
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. public class RenderCrystal extends TileEntitySpecialRenderer<TileCrystal>
  2. {
  3. private IBakedModel baked;
  4.  
  5. private IBakedModel getBakedModel()
  6. {
  7. IModel model;
  8. if (baked == null) {
  9. try
  10. {
  11. model = ModelLoaderRegistry.getModel(new ResourceLocation(PMCore.ModId, "block/crystal.obj"));
  12. }
  13. catch (Exception e)
  14. {
  15. throw new RuntimeException(e);
  16. }
  17. baked = model.bake(TRSRTransformation.identity(), DefaultVertexFormats.ITEM, location -> Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(location.toString()));
  18. }
  19. return baked;
  20. }
  21.  
  22. @Override
  23. public void renderTileEntityAt(TileCrystal te, double x, double y, double z, float partialTicks, int destroyStage) {
  24. GlStateManager.pushAttrib();
  25. GlStateManager.pushMatrix();
  26. GlStateManager.translate(x, y, z);
  27.  
  28. renderModel(te);
  29.  
  30.  
  31. GlStateManager.popMatrix();
  32. GlStateManager.popAttrib();
  33.  
  34. }
  35.  
  36. private void renderModel(TileCrystal te) {
  37. GlStateManager.pushMatrix();
  38.  
  39. GlStateManager.translate(0.5, 0, 0.5);
  40.  
  41. RenderHelper.disableStandardItemLighting();
  42. this.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
  43. if (Minecraft.isAmbientOcclusionEnabled()) {
  44. GlStateManager.shadeModel(GL11.GL_SMOOTH);
  45. } else {
  46. GlStateManager.shadeModel(GL11.GL_FLAT);
  47. }
  48.  
  49. World world = te.getWorld();
  50.  
  51. GlStateManager.translate(-te.getPos().getX(), -te.getPos().getY(), -te.getPos().getZ());
  52.  
  53. Tessellator tessellator = Tessellator.getInstance();
  54. tessellator.getBuffer().begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
  55. Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelRenderer().renderModel(
  56. world,
  57. getBakedModel(),
  58. world.getBlockState(te.getPos()),
  59. te.getPos(),
  60. Tessellator.getInstance().getBuffer(),
  61. true);
  62. tessellator.draw();
  63.  
  64. RenderHelper.enableStandardItemLighting();
  65. GlStateManager.popMatrix();
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment