WaveFrontRenderer.java 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package com.zjinja.mcmod.decor.element_templates.renderer;
  2. import com.zjinja.mcmod.decor.ZJinJaDecoration;
  3. import com.zjinja.mcmod.decor.element_base.EBaseTileBlock;
  4. import com.zjinja.mcmod.decor.element_base.EBaseTileRenderer;
  5. import net.minecraft.block.Block;
  6. import net.minecraft.client.Minecraft;
  7. import net.minecraft.client.renderer.RenderHelper;
  8. import net.minecraft.client.renderer.Tessellator;
  9. import net.minecraft.tileentity.TileEntity;
  10. import net.minecraft.util.ResourceLocation;
  11. import net.minecraftforge.client.model.obj.WavefrontObject;
  12. import org.lwjgl.opengl.GL11;
  13. public class WaveFrontRenderer extends EBaseTileRenderer {
  14. protected WavefrontObject WaveFrontModel;
  15. protected ResourceLocation TextureRes;
  16. public WaveFrontRenderer(){
  17. }
  18. public void LoadResources(String ObjLocation, String TextureLocation){
  19. String modelloc = "models/blocks/" + ObjLocation + ".obj";
  20. String textureloc = "textures/blocks/" + TextureLocation + ".png";
  21. if(ZJinJaDecoration.DebugMode) {
  22. ZJinJaDecoration.logger.warn("[Model Location] " + modelloc);
  23. ZJinJaDecoration.logger.warn("[Texture Location] " + textureloc);
  24. }
  25. WaveFrontModel = new WavefrontObject(new ResourceLocation(ZJinJaDecoration.MODID, modelloc));
  26. TextureRes = new ResourceLocation(ZJinJaDecoration.MODID, textureloc);
  27. }
  28. protected void preRender(double x, double y, double z){
  29. GL11.glPushMatrix();
  30. GL11.glTranslatef((float)x + 0.5F, (float)y + 0.5F, (float)z + 0.5F);
  31. RenderHelper.disableStandardItemLighting();
  32. GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
  33. GL11.glEnable(GL11.GL_BLEND);
  34. GL11.glEnable(GL11.GL_CULL_FACE);
  35. if(Minecraft.isAmbientOcclusionEnabled()){
  36. GL11.glShadeModel(GL11.GL_SMOOTH);
  37. }else {
  38. GL11.glShadeModel(GL11.GL_FLAT);
  39. }
  40. Tessellator.instance.setColorOpaque_F(1.0F, 1.0F, 1.0F);
  41. }
  42. protected void render(WavefrontObject model,EBaseTileBlock tileBlock, int meta){
  43. GL11.glPushMatrix();
  44. GL11.glScalef(0.0625F, 0.0625F, 0.0625F);
  45. tileBlock.DirUtil.GLTransformByMeta(meta);
  46. model.renderAll();
  47. GL11.glPopMatrix();
  48. GL11.glPopMatrix();
  49. GL11.glPopMatrix();
  50. GL11.glPopMatrix();
  51. }
  52. protected void postRender(){
  53. RenderHelper.enableStandardItemLighting();
  54. GL11.glPopMatrix();
  55. }
  56. @Override
  57. public void renderTileEntityAt(TileEntity te, double x, double y, double z, float scale){
  58. preRender(x, y, z);
  59. Block block = te.getWorldObj().getBlock(te.xCoord, te.yCoord, te.zCoord);
  60. int meta = te.getWorldObj().getBlockMetadata(te.xCoord, te.yCoord, te.zCoord);
  61. if(block instanceof EBaseTileBlock){
  62. EBaseTileBlock tileBlock = (EBaseTileBlock)block;
  63. Minecraft.getMinecraft().getTextureManager().bindTexture(TextureRes);
  64. render(WaveFrontModel, tileBlock, meta);
  65. }
  66. postRender();
  67. }
  68. }