Jump to content

Recommended Posts

Posted

I'm trying to rotate a tile entity model and it is causing inconsistant results. Any suggestions? Any help is appreciated!

 

Renderer:

 

package net.mc42.mods.eclipses.tileentities.EssenceInfuser;

import org.lwjgl.opengl.GL11;

import net.mc42.mods.eclipses.mod_Eclipses;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;

public class TileEntityEssenceInfuserRenderer extends TileEntitySpecialRenderer {
        
        //The model of your block
        private final EssenceInfuserModelBase model;
        
        public TileEntityEssenceInfuserRenderer() {
                this.model = new EssenceInfuserModelBase();
               // this.modelContent = new TileEntityJarContentsModel(0);
        }
        
        private void adjustRotatePivotViaMeta(World world, int x, int y, int z) {
                int meta = world.getBlockMetadata(x, y, z);
                GL11.glPushMatrix();
                GL11.glRotatef(meta * (-90), 0.0F, 0.0F, 1.0F);
                GL11.glPopMatrix();
        }
        
        @Override
        public void renderTileEntityAt(TileEntity te, double x, double y, double z, float scale) {
        	
        	TileEntityEssenceInfuser tej = (TileEntityEssenceInfuser) te;
        //The PushMatrix tells the renderer to "start" doing something.
             //The PushMatrix tells the renderer to "start" doing something.
                GL11.glPushMatrix();
        //This is setting the initial location.
                GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);
        //This is the texture of your block. It's pathed to be the same place as your other blocks here.
                //Outdated bindTextureByName("/mods/roads/textures/blocks/TrafficLightPoleRed.png");
       //Use in 1.6.2  this
                ResourceLocation textures1 = (new ResourceLocation("modeclipses:textures/blocks/EssenceInfuser/Base.png")); 
                //textures1 = (new ResourceLocation("modeclipses:textures/blocks/EssenceInfuser/Tank.png")); 
                //textures1 = (new ResourceLocation("modeclipses:textures/blocks/EssenceInfuser/Backboard.png"));
                //textures1 = (new ResourceLocation("modeclipses:textures/blocks/EssenceInfuser/Top.png"));
        //the ':' is very important
        //binding the textures
                Minecraft.getMinecraft().renderEngine.bindTexture(textures1);

        //This rotation part is very important! Without it, your model will render upside-down! And for some reason you DO need PushMatrix again!                       
                GL11.glPushMatrix();
                
                //GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
                
                GL11.glRotatef(180F, tej.orient*1F, 0.0F, 1.0F);
        //A reference to your Model file. Again, very important.
                //this.modelCap.render((Entity)null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
                this.model.renderBase((Entity)null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
        //Tell it to stop rendering for both the PushMatrix's
                GL11.glPopMatrix();
                textures1 = (new ResourceLocation("modeclipses:textures/blocks/EssenceInfuser/Tank.png")); 
                //textures1 = (new ResourceLocation("modeclipses:textures/blocks/EssenceInfuser/Tank.png")); 
                //textures1 = (new ResourceLocation("modeclipses:textures/blocks/EssenceInfuser/Backboard.png"));
                //textures1 = (new ResourceLocation("modeclipses:textures/blocks/EssenceInfuser/Top.png"));
        //the ':' is very important
        //binding the textures
                Minecraft.getMinecraft().renderEngine.bindTexture(textures1);

        //This rotation part is very important! Without it, your model will render upside-down! And for some reason you DO need PushMatrix again!                       
                GL11.glPushMatrix();
                GL11.glDisable(GL11.GL_CULL_FACE);
                
                //GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
                
                GL11.glRotatef(180F, tej.orient*1F, 0.0F, 1.0F);
        //A reference to your Model file. Again, very important.
                //this.modelCap.render((Entity)null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
                this.model.renderTank((Entity)null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
        //Tell it to stop rendering for both the PushMatrix's
                GL11.glEnable(GL11.GL_CULL_FACE);
                GL11.glPopMatrix();
                textures1 = (new ResourceLocation("modeclipses:textures/blocks/EssenceInfuser/Backboard.png")); 
                //textures1 = (new ResourceLocation("modeclipses:textures/blocks/EssenceInfuser/Tank.png")); 
                //textures1 = (new ResourceLocation("modeclipses:textures/blocks/EssenceInfuser/Backboard.png"));
                //textures1 = (new ResourceLocation("modeclipses:textures/blocks/EssenceInfuser/Top.png"));
        //the ':' is very important
        //binding the textures
                Minecraft.getMinecraft().renderEngine.bindTexture(textures1);

        //This rotation part is very important! Without it, your model will render upside-down! And for some reason you DO need PushMatrix again!                       
                GL11.glPushMatrix();
                
                //GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
                
                GL11.glRotatef(180F, tej.orient*1F, 0.0F, 1.0F);        //A reference to your Model file. Again, very important.
                //this.modelCap.render((Entity)null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
                this.model.renderBackboard((Entity)null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
        //Tell it to stop rendering for both the PushMatrix's
                GL11.glPopMatrix();
                textures1 = (new ResourceLocation("modeclipses:textures/blocks/EssenceInfuser/Top.png")); 
                //textures1 = (new ResourceLocation("modeclipses:textures/blocks/EssenceInfuser/Tank.png")); 
                //textures1 = (new ResourceLocation("modeclipses:textures/blocks/EssenceInfuser/Backboard.png"));
                //textures1 = (new ResourceLocation("modeclipses:textures/blocks/EssenceInfuser/Top.png"));
        //the ':' is very important
        //binding the textures
                Minecraft.getMinecraft().renderEngine.bindTexture(textures1);

        //This rotation part is very important! Without it, your model will render upside-down! And for some reason you DO need PushMatrix again!                       
                GL11.glPushMatrix();
                
                //GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
                
                GL11.glRotatef(180F, tej.orient*1F, 0.0F, 1.0F);
        //A reference to your Model file. Again, very important.
                //this.modelCap.render((Entity)null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
                this.model.renderTop((Entity)null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
        //Tell it to stop rendering for both the PushMatrix's
                GL11.glPopMatrix();
                GL11.glPopMatrix();
        }

        //Set the lighting stuff, so it changes it's brightness properly.       
        private void adjustLightFixture(World world, int i, int j, int k, Block block) {
                Tessellator tess = Tessellator.instance;
                //float brightness = block.getBlockBrightness(world, i, j, k);
                //As of MC 1.7+ block.getBlockBrightness() has become block.getLightValue():
                float brightness = block.getLightValue(world, i, j, k);
                int skyLight = world.getLightBrightnessForSkyBlocks(i, j, k, 0);
                int modulousModifier = skyLight % 65536;
                int divModifier = skyLight / 65536;
                tess.setColorOpaque_F(brightness, brightness, brightness);
                OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit,  (float) modulousModifier,  divModifier);
        }
}

 

 

Model:

 

// Date: 9/7/2014 8:03:14 PM
// Template version 1.1
// Java generated by Techne
// Keep in mind that you still need to fill in some blanks
// - ZeuX






package net.mc42.mods.eclipses.tileentities.EssenceInfuser;

import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;

public class EssenceInfuserModelBase extends ModelBase
{
  //fields
    ModelRenderer Base;
    ModelRenderer Tank;
    ModelRenderer Backboard;
    ModelRenderer Top;
  
  public EssenceInfuserModelBase()
  {
    textureWidth = 64;
    textureHeight = 32;
    
      Base = new ModelRenderer(this, 0, 0);
      Base.addBox(0F, 0F, 0F, 14, 14, 14);
      Base.setRotationPoint(-6F, 10F, -7F);
      Base.setTextureSize(64, 32);
      Base.mirror = true;
      setRotation(Base, 0.0174533F, 0F, 0F);
      Tank = new ModelRenderer(this, 0, 0);
      Tank.addBox(0F, 0F, 0F, 8, 14, ;
      Tank.setRotationPoint(-1F, -4F, -4.25F);
      Tank.setTextureSize(64, 32);
      Tank.mirror = true;
      setRotation(Tank, 0.0174533F, 0F, 0F);
      Backboard = new ModelRenderer(this, 0, 0);
      Backboard.addBox(0F, 0F, 0F, 2, 14, 10);
      Backboard.setRotationPoint(6F, -4F, -5.25F);
      Backboard.setTextureSize(64, 32);
      Backboard.mirror = true;
      setRotation(Backboard, 0.0174533F, 0F, 0F);
      Top = new ModelRenderer(this, 0, 0);
      Top.addBox(0F, 0F, 0F, 10, 2, 10);
      Top.setRotationPoint(-2F, -5F, -5.25F);
      Top.setTextureSize(64, 32);
      Top.mirror = true;
      setRotation(Top, 0F, 0F, 0F);
  }
  
  public void renderBase(Entity entity, float f, float f1, float f2, float f3, float f4, float f5)
  {
    super.render(entity, f, f1, f2, f3, f4, f5);
    setRotationAngles(f, f1, f2, f3, f4, f5, entity);
    Base.render(f5);
    //Tank.render(f5);
    //Backboard.render(f5);
    //Top.render(f5);
  }
  public void renderTank(Entity entity, float f, float f1, float f2, float f3, float f4, float f5)
  {
    super.render(entity, f, f1, f2, f3, f4, f5);
    setRotationAngles(f, f1, f2, f3, f4, f5, entity);
    //Base.render(f5);
    Tank.render(f5);
    //Backboard.render(f5);
    //Top.render(f5);
  }
  public void renderBackboard(Entity entity, float f, float f1, float f2, float f3, float f4, float f5)
  {
    super.render(entity, f, f1, f2, f3, f4, f5);
    setRotationAngles(f, f1, f2, f3, f4, f5, entity);
    //Base.render(f5);
    //Tank.render(f5);
    Backboard.render(f5);
    //Top.render(f5);
  }
  public void renderTop(Entity entity, float f, float f1, float f2, float f3, float f4, float f5)
  {
    super.render(entity, f, f1, f2, f3, f4, f5);
    setRotationAngles(f, f1, f2, f3, f4, f5, entity);
    //Base.render(f5);
    //Tank.render(f5);
    //Backboard.render(f5);
    Top.render(f5);
  }
  
  private void setRotation(ModelRenderer model, float x, float y, float z)
  {
    model.rotateAngleX = x;
    model.rotateAngleY = y;
    model.rotateAngleZ = z;
  }
  
  public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5, Entity e)
  {
    super.setRotationAngles(f, f1, f2, f3, f4, f5, e);
  }

}

 

 

post3.png

Posted

I actually haven't done much rendering at all, but I think this could be because you're not rotating it back after you're done. I could be completely wrong though.

 

What do you mean?

 

Posted

GL11.glRotatef(180F, tej.orient*1F, 0.0F, 1.0F);

 

You realize this is rotating about a non-Euclidian axis. The results will not be what you expect. Simple rotation about a world axis sets only one of X, Y or Z to 1.0f the others should be 0.0f.

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.