Advertisement
Guest User

Untitled

a guest
Feb 1st, 2015
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.51 KB | None | 0 0
  1. package com.nextlevelminecraft.cad435.objloader.ColoredLamp;
  2.  
  3. import net.minecraft.client.Minecraft;
  4. import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
  5. import net.minecraft.tileentity.TileEntity;
  6. import net.minecraft.util.ResourceLocation;
  7. import net.minecraft.world.World;
  8. import net.minecraftforge.client.model.AdvancedModelLoader;
  9. import net.minecraftforge.client.model.IModelCustom;
  10. import org.lwjgl.opengl.GL11;
  11.  
  12. import java.util.Timer;
  13. import java.util.TimerTask;
  14.  
  15. public class LampRenderer extends TileEntitySpecialRenderer {
  16.     public static IModelCustom Base, Hull, Inner;
  17.     public static ResourceLocation resBase, resHull, resInner;
  18.     public static ResourceLocation Tex;
  19.  
  20.     private int rotation;
  21.     public LampRenderer(){
  22.  
  23.         //this is for animation
  24.         Timer RenderTick = new Timer();//TODO: transfer it to the Animation_RenderBus!
  25.         RenderTick.scheduleAtFixedRate(new TimerTask() {
  26.             @Override
  27.             public void run() {
  28.  
  29.                 if (rotation < 359)
  30.                 {
  31.                     rotation++;
  32.                 }
  33.                 else {
  34.                     rotation = 0;
  35.                 }
  36.             }
  37.         },80,80);
  38.  
  39.  
  40.         //initialize Model and Texture
  41.  
  42.         //Res-Location
  43.         resBase = new ResourceLocation("objloader", "models/ColoredLamp/LampBase.obj");
  44.         resHull = new ResourceLocation("objloader", "models/ColoredLamp/LampHull.obj");
  45.         resInner = new ResourceLocation("objloader", "models/ColoredLamp/LampInner.obj");
  46.  
  47.  
  48.         //obj.
  49.         Base = AdvancedModelLoader.loadModel(resBase);
  50.         Inner = AdvancedModelLoader.loadModel(resInner);
  51.         Hull = AdvancedModelLoader.loadModel(resHull);
  52.         Tex = new ResourceLocation("objloader", "textures/blocks/LampBase.png");
  53.  
  54.     }
  55.  
  56.     int[] tmp;
  57.     @Override
  58.     public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float f) {
  59.  
  60.         Minecraft mc = Minecraft.getMinecraft(); //TODO: don't do this any tick
  61.         World world = mc.thePlayer.getEntityWorld();
  62.         int _x = tileentity.xCoord, _y=tileentity.yCoord, _z=tileentity.zCoord;
  63.         tileentity = world.getTileEntity(_x,_y,_z);
  64.  
  65.         try { //TODO: remove try-catch!
  66.             tmp = ((LampTileEntity) tileentity).RGB_VALUES.toIntArray();
  67.         }
  68.         catch (Exception e)
  69.         {
  70.             tmp = new int[]{255,255,255};
  71.         }
  72.  
  73.  
  74.         //static Tex, animated Inner
  75.         GL11.glPushMatrix();//Matrix to Stack
  76.         GL11.glEnable(GL11.GL_COLOR);
  77.  
  78.             GL11.glTranslated(x, y, z);
  79.             GL11.glRotated(rotation, 1, 1, 1);//rotate
  80.  
  81.  
  82.             GL11.glColor4f(0,0,0, 1f);
  83.                 mc.renderEngine.bindTexture(Tex);
  84.                 Inner.renderAll();
  85.  
  86.         GL11.glPopMatrix();//Matrix unbind
  87.  
  88.  
  89.         //ColorTex non animation
  90.         GL11.glPushMatrix();//Matrix to Stack
  91.         GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
  92.  
  93.         GL11.glEnable(GL11.GL_BLEND);
  94.         GL11.glEnable(GL11.GL_COLOR);
  95.         GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
  96.  
  97.  
  98.             GL11.glTranslated(x, y, z);
  99.  
  100.  
  101.             GL11.glColor4f(tmp[0]/255f,tmp[1]/255f,tmp[2]/255f,0.5f);
  102.                 mc.renderEngine.bindTexture(Tex);
  103.                 Base.renderAll();
  104.  
  105.                 mc.renderEngine.bindTexture(Tex);
  106.                 Hull.renderAll();
  107.  
  108.  
  109.  
  110.         GL11.glPopMatrix();//Matrix unbind
  111.         GL11.glPopAttrib();//Restore Attrib
  112.  
  113.     }
  114.  
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement