Jump to content

Recommended Posts

Posted

My intentions for my code is that when I right click a block, an arrow appears over it(not the final version of course :P). I followed a tutorial and the code is this:

 

 

GL11.glPushMatrix();

ItemStack stack = new ItemStack(Item.arrow, 1, 0);

EntityItem entItem = new EntityItem(Minecraft.getMinecraft().thePlayer.getEntityWorld(), 0D, 0D, 0D, stack);

entItem.hoverStart = 0F;

RenderItem.renderInFrame = true;

//GL11.glRotatef(180, 0, 1, 1);

RenderManager.instance.renderEntityWithPosYaw(entItem, 0.0D, 0.0D, 0.0D, 0.0F, 0.0F);

RenderItem.renderInFrame = false;

GL11.glPopMatrix();

 

 

 

However, this code renders the item in the players head. I know why(entItem is calling .thePlayer) but what do I change this to, to make it render on top of the block?

Posted

HI

 

Where is this code located?

 

Many of the rendering routines are called with the origin [0,0,0] set to the player's eye location.  You need to translate the rendering location GL11.glTranslatef to take account of that.  Typically the calling function provides the offset of the entity / tileentity relative to the eye location, or you can calculate it yourself.  A bit of trial and error, or inspection of vanilla code, will show you the way.

 

-TGG

Posted

This code is in my TileEntitySpecialRenderer class, where my model render code is. What do you mean by translare the rendering location GL11.gltranslatef? I haven't used openGL before :/

 

Also, where is this used in the vannila code? I can't remember any personally :/

Posted

Hi

 

This link is great for OpenGL

http://www.glprogramming.com/red/

 

The  renderTileEntityChestAt() provides you with the dx, dy, and dz parameters, these are the position of the tileentity relative to the player's eye, you need to use them when you render.

If you're currently rendering at the [0,0,0], then using

 

GL11.glPushMatrix();
GL11.glTranslatef((float)dx, (float)dy, (float)dz);
.. render here
GL11.glPopMatrix();

should put your render at the right location.  (I'm going from memory here, so if that's not right, try System.out.println() on the method parameters to see what they are / how they change when you move relative to your TileEntity.)

 

-TGG

 

 

 

 

 

Posted

Awesome thanks! I got the item rendering above the block! Now my aim is to rotate it :) I looked into the EntityItem code, which I think is the code that is when you drop an item onto the floor. After looking into that a bit, here is my code:

 

 

 

GL11.glPushMatrix();

GL11.glTranslatef((float)x + 0.5f, (float)y + 1.0F, (float)z + 0.3F);

ItemStack stack = new ItemStack(Item.arrow, 1, 0);

EntityItem entItem = new EntityItem(Minecraft.getMinecraft().thePlayer.getEntityWorld(), x, y, z, stack);

entItem.hoverStart = 0f;

RenderItem.renderInFrame = true;

GL11.glRotatef(180, 0, 1, 1);

entItem.hoverStart = (float)(Math.random() * Math.PI * 2.0D);

entItem.rotationYaw = (float)(Math.random() * 360.0D);

entItem.motionX = (double)((float)(Math.random() * 0.20000000298023224D - 0.10000000149011612D));

entItem.motionY = 0.20000000298023224D;

entItem.motionZ = (double)((float)(Math.random() * 0.20000000298023224D - 0.10000000149011612D));

RenderManager.instance.renderEntityWithPosYaw(entItem, entItem.motionX, entItem.motionY, entItem.motionZ, 1F, 1F);

 

RenderItem.renderInFrame = false;

GL11.glPopMatrix();

 

 

 

The motionX/Y/z are directly out of the EntityItem class, and I'm using the in renderEntityWithPosYaw - can't find that used in minecraft's entity code anywhere, so that line is just a guess on what it should be(the calling motions bit).

 

My problem is the with this setup, the item spazzes out on my block.

Posted

Hi

 

This is from vanilla

 

    /**
     * Renders the specified entity with the passed in position, yaw, and partialTickTime. Args: entity, x, y, z, yaw,
     * partialTickTime
     */
    public void renderEntityWithPosYaw(Entity par1Entity, double par2, double par4, double par6, float par8, float par9)

 

It is asking for the x,y,z position, not the motion which is a speed.  You need to provide the appropriate x,y,z position and the yaw angle.  Don't bother with the hoverStart, motionX etc, they won't do anything since you're not calling the onUpdate of the entity.  You rotate it by changing the value of the yaw angle.

 

You don't need renderInFrame either.

 

Some more information here on dropped item rendering FYI.

http://greyminecraftcoder.blogspot.com.au/2013/08/rendering-dropped-items.html

 

Alternatively, you could just render it the same way as you already did orginally, just use

GL11.glRotatef(rotationAngle, 0, 1, 0);

before your call, that will rotate it around the y axis by the angle you specify.

 

-TGG

 

 

 

Posted

Thanks so much! Fyi you are by far my favourite person here :)

 

Now I have a completely unrelated question. I have my ItemStack, and I want to enchant it, how do I do that? Not upon crafting, just enchant it. I thought it would be simple(something like ItemStack.enchant) but I can't find any tutorials on it.

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.