Jump to content

[1.7.10] [Solved] Tile entity with .obj model follows mouse.


Recommended Posts

Posted

I made a tile entity that renders with a .obj model. Elix helped me get it working but it's acting funny. It follows my mouse. But the I have noticed that the model disappears when I'm not looking at the tile entity. Then if I look at it it appears again.

 

Here is a video (sorry for the lag) depicting the glitch:

 

Here is my renderer's code:

public class LuminaOrbRenderer extends TileEntitySpecialRenderer {
    ResourceLocation texture;
    ResourceLocation objModelLocation;
    IModelCustom model;

    public LuminaOrbRenderer(){
        texture = new ResourceLocation(Lumina.MODID, "models/LuminaOrbTexture.png");
        objModelLocation = new ResourceLocation(Lumina.MODID, "models/LuminaOrb.obj");
        model = AdvancedModelLoader.loadModel(objModelLocation);
    }

    @Override
    public void renderTileEntityAt(TileEntity te, double posX, double posY, double posZ, float timeSinceLastTick) {
        TileEntityLuminaOrb orb = (TileEntityLuminaOrb) te;
        float scale = 0.02F;
        float rotation = orb.rotation + (timeSinceLastTick / 2F);

        bindTexture(texture);

        GL11.glPushMatrix();
        GL11.glScalef(scale, scale, scale);
        GL11.glTranslated(posX + 0.5, posY + 0.5,  posZ + 0.5);
        GL11.glRotatef(rotation, 0F, 1F, 0.5F);
        model.renderAll();
        GL11.glPopMatrix();
    }
}

 

Any help is appreciated at this point. I can't get this to work. :/

Posted

My GL knowledge is not very good, but for one I can tell - this surely looks like scaling problem. I've had problems like this before and the solution almost always lied in bad scaling.

 

Try moving scaling after translation.

1.7.10 is no longer supported by forge, you are on your own.

Posted

I've also had similar problems using only one matrix push/pop.  Add a second one between the translate and the rotate.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Ok, so like this?

GL11.glPushMatrix();
GL11.glTranslated(posX + 0.5, posY + 0.5, posZ + 0.5);
GL11.glScalef(scale, scale, scale);
GL11.glPushMatrix();
GL11.glRotatef(rotation, 0F, 1F, 0.5F);
model.renderAll();
GL11.glPopMatrix();
GL11.glPopMatrix();

 

I moved glScalef below glTranslated. Also, as Draco18s said (if I'm understanding correctly) I added a second push/pop. If I'm not understanding correctly just tell me. :)

Posted

The second Push/Pop pair doesn't do anything. Read here what Push/PopMatrix actually do: http://www.swiftless.com/tutorials/opengl/pop_and_push_matrices.html

 

And yes, first translate to its position, then scale it or you will scale the position as well.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted

I know what it's supposed to do, but I've seen really odd things when I try to do both a rotation and a translation with only the one pair.

 

There was a forge wiki page on it (can't figure out which one now) that has the comment:

//I don't know why you need another, but you do

Or something along those lines.

 

I don't have a renderer that's going bonkers right now (the one I was having trouble with most recently I ended up rebuilding in techne upside down because it refused to turn around properly).

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Ok, I was tinkering around with it, using what you guys said. But now it's doing this. Isn't it cute?

ih35RHF.png

It's probably scaled a little small. What should I change the scale to?

Here is my updated code:

public class LuminaOrbRenderer extends TileEntitySpecialRenderer {
    ResourceLocation texture;
    ResourceLocation objModelLocation;
    IModelCustom model;

    public LuminaOrbRenderer(){
        texture = new ResourceLocation(Lumina.MODID, "models/LuminaOrbTexture.png");
        objModelLocation = new ResourceLocation(Lumina.MODID, "models/LuminaOrb.obj");
        model = AdvancedModelLoader.loadModel(objModelLocation);
    }

    @Override
    public void renderTileEntityAt(TileEntity te, double posX, double posY, double posZ, float timeSinceLastTick) {
        TileEntityLuminaOrb orb = (TileEntityLuminaOrb) te;
        float scale = 0.02F;
        float rotation = orb.rotation + (timeSinceLastTick / 2F);

        bindTexture(texture);

        GL11.glPushMatrix();
        GL11.glTranslated(posX + 0.5, posY + 0.5, posZ + 0.5);
        GL11.glScalef(scale, scale, scale);
        GL11.glPushMatrix();
        GL11.glRotatef(rotation, 0F, 1F, 0.5F);
        model.renderAll();
        GL11.glPopMatrix();
        GL11.glPopMatrix();
    }
}

Posted

It's not following the mouse anymore now. Forgot to say that. :D

Posted

BTW, to get it to render as a 3D item, you can render it just like in the world: just pass the renderer a dummy entity and render it at (0,0,0).

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Implement TileEntityInventoryRenderer in your TESR

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

To make item render in 1.7.10, use  MinecraftForgeClient.registerItemRenderer(item, IItemRenderer);

Where iitem renderer is new class that implements it (Example: LuminaOrbItemRenderer), in constructor you pass it YourTileEntityRenderer (!!!WARNING: SAME OBJECT THAT YOU PASS TO bindTileEntitySpecialRenderer OR MINECRAFT WILL CRASH!!!) and where your return true to first methods, and in last, you just call terenderer.render ...

Posted

It doesn't exist. Is that in 1.8?

 

Its 1.7.10 and what I'm using.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Ok, this is what I have so far:

public class LuminaOrbItemRenderer implements IItemRenderer {

    @Override
    public boolean handleRenderType(ItemStack item, ItemRenderType type) {
        return false;
    }

    @Override
    public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) {
        return false;
    }

    @Override
    public void renderItem(ItemRenderType type, ItemStack item, Object... data) {

    }
}

What do I do now?

Posted

Ok, this is what I have so far:

public class LuminaOrbItemRenderer implements IItemRenderer {

    @Override
    public boolean handleRenderType(ItemStack item, ItemRenderType type) {
        return false;
    }

    @Override
    public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) {
        return false;
    }

    @Override
    public void renderItem(ItemRenderType type, ItemStack item, Object... data) {

    }
}

What do I do now?

in constructor you pass it YourTileEntityRenderer (!!!WARNING: SAME OBJECT THAT YOU PASS TO bindTileEntitySpecialRenderer OR MINECRAFT WILL CRASH!!!) and where your return true to first two methods, and in last, you just call terenderer.render ...

 

Posted

It doesn't exist. Is that in 1.8?

 

Its 1.7.10 and what I'm using.

 

Oh lol, I thought you said TileEntityItemRenderer. :) Now I get it. You actually said TileEntityInventoryRenderer.

 

Edit: Well, that doesn't exist either, :/ I think I'll use Elix's way.

Posted

So, like this Elix?

public class LuminaOrbItemRenderer implements IItemRenderer {
    LuminaOrbRenderer tesr;


    public  LuminaOrbItemRenderer(LuminaOrbRenderer renderer){
        tesr = renderer;
    }

    @Override
    public boolean handleRenderType(ItemStack item, ItemRenderType type) {
        return true;
    }

    @Override
    public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) {
        return true;
    }

    @Override
    public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
        tesr.renderTileEntityAt(null, 0, 0, 0, 0);
    }
}

Posted

So, like this Elix?

public class LuminaOrbItemRenderer implements IItemRenderer {
    LuminaOrbRenderer tesr;


    public  LuminaOrbItemRenderer(LuminaOrbRenderer renderer){
        tesr = renderer;
    }

    @Override
    public boolean handleRenderType(ItemStack item, ItemRenderType type) {
        return true;
    }

    @Override
    public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) {
        return true;
    }

    @Override
    public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
        tesr.renderTileEntityAt(null, 0, 0, 0, 0);
    }
}

and where your return true to first 2 methods (optional)

If your tileentity renderer doen't need te data, you can use null, but yours uses some, so in constructor initialise tileentity, and pass it instead of null...

 

Posted

Whoops, sorry.  It was some of my own helper code, haha.  The one reply was done from my tablet, so I couldn't look at my code.

 

It was an interface I created so that my TEs could be passed to an IItemRenderer, just as you've done and I didn't need a separate IItemRenderer for each TE.  I apologize for the confusion.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.