Jump to content

[1.6.4] Rendering Item On Block OpenGL Help


Xcox123

Recommended Posts

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 :/

Link to comment
Share on other sites

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

 

 

 

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • You shouldn't be extracting the mod .jar, just place it in your mods folder.
    • so basically another rundown of my probelm. Im the admin of a 1.20.1 modded server. Were using forge 47.2.0 but tested this issue in other forge versions too on sevrer and client side. so the forge version isnt the issue. The bug happens in following instances. Were using the attacks of the jujutsucraft mod by orca normally. And for everyone that stands there nothing changes. But everyone who wasnt in the chunks before or who relogins again those chunks will appear invisible for the most part. I tried fixing this be removing and adding following mods in many combinations. Embeddium, canary, memoryleakfix, ai improvements, Krypton reforges, better chunkloading, radium reforged, embeddium plus, farsight, betterchunkloading, oculus I tested most of these mods alone and in differents combinations with each other and without the mods. What i noticed is zhat when i removed  . most invisible chunks will return or semi return. and only ine or two chunks stay invisible. I rechanged those mids mostly on the cöient side but also some in the serveside. Ir most likely isnt an issue with another non performance mod since i noticed this thing with embeddium. Ans also the problem wasnt there im the beginning of the server. Granted since then we updated some of the mods that add content and their lib mod. But i went to every big mods discord and community that we have and i didnt find someone else havinf that chunk problem. Heres the link to a video of the Problem. https://streamable.com/9v1if2     heres the link to the modlist: https://ibb.co/myF8dtX     Pleaee im foghting for months with this problem. All the performance mods kn the modlist are for sure not the issue i tested without all of them.
    • It looks like you're only setting the health if the thing you are hitting is a player.  
    • It sounds like you accidentally have two items that are both named "orange". Ensure that you give items unique names in the string when you register them. That's one of the more annoying errors to track down if you don't know what's causing it, though.
    • when i tried downloading blockfront from curseforge for version 1.20.1 i get the winrar file  and that i extract and i just get the "manifest.json" file no mod when exctracted
  • Topics

×
×
  • Create New...

Important Information

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