Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.nextlevelminecraft.cad435.objloader.ColoredLamp;
- import net.minecraft.client.Minecraft;
- import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
- import net.minecraft.tileentity.TileEntity;
- import net.minecraft.util.ResourceLocation;
- import net.minecraft.world.World;
- import net.minecraftforge.client.model.AdvancedModelLoader;
- import net.minecraftforge.client.model.IModelCustom;
- import org.lwjgl.opengl.GL11;
- import java.util.Timer;
- import java.util.TimerTask;
- public class LampRenderer extends TileEntitySpecialRenderer {
- public static IModelCustom Base, Hull, Inner;
- public static ResourceLocation resBase, resHull, resInner;
- public static ResourceLocation Tex;
- private int rotation;
- public LampRenderer(){
- //this is for animation
- Timer RenderTick = new Timer();//TODO: transfer it to the Animation_RenderBus!
- RenderTick.scheduleAtFixedRate(new TimerTask() {
- @Override
- public void run() {
- if (rotation < 359)
- {
- rotation++;
- }
- else {
- rotation = 0;
- }
- }
- },80,80);
- //initialize Model and Texture
- //Res-Location
- resBase = new ResourceLocation("objloader", "models/ColoredLamp/LampBase.obj");
- resHull = new ResourceLocation("objloader", "models/ColoredLamp/LampHull.obj");
- resInner = new ResourceLocation("objloader", "models/ColoredLamp/LampInner.obj");
- //obj.
- Base = AdvancedModelLoader.loadModel(resBase);
- Inner = AdvancedModelLoader.loadModel(resInner);
- Hull = AdvancedModelLoader.loadModel(resHull);
- Tex = new ResourceLocation("objloader", "textures/blocks/LampBase.png");
- }
- int[] tmp;
- @Override
- public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float f) {
- Minecraft mc = Minecraft.getMinecraft(); //TODO: don't do this any tick
- World world = mc.thePlayer.getEntityWorld();
- int _x = tileentity.xCoord, _y=tileentity.yCoord, _z=tileentity.zCoord;
- tileentity = world.getTileEntity(_x,_y,_z);
- try { //TODO: remove try-catch!
- tmp = ((LampTileEntity) tileentity).RGB_VALUES.toIntArray();
- }
- catch (Exception e)
- {
- tmp = new int[]{255,255,255};
- }
- //static Tex, animated Inner
- GL11.glPushMatrix();//Matrix to Stack
- GL11.glEnable(GL11.GL_COLOR);
- GL11.glTranslated(x, y, z);
- GL11.glRotated(rotation, 1, 1, 1);//rotate
- GL11.glColor4f(0,0,0, 1f);
- mc.renderEngine.bindTexture(Tex);
- Inner.renderAll();
- GL11.glPopMatrix();//Matrix unbind
- //ColorTex non animation
- GL11.glPushMatrix();//Matrix to Stack
- GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
- GL11.glEnable(GL11.GL_BLEND);
- GL11.glEnable(GL11.GL_COLOR);
- GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
- GL11.glTranslated(x, y, z);
- GL11.glColor4f(tmp[0]/255f,tmp[1]/255f,tmp[2]/255f,0.5f);
- mc.renderEngine.bindTexture(Tex);
- Base.renderAll();
- mc.renderEngine.bindTexture(Tex);
- Hull.renderAll();
- GL11.glPopMatrix();//Matrix unbind
- GL11.glPopAttrib();//Restore Attrib
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement