Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Items and blocks no longer have textures, they now have models.

 

Use RenderItem#getItemModelWithOverrides to get the model for an item. 

How can I display them in world? I wanted to draw a quad and then show an item texture in it... How can I do that with models?

  • Author

Would this work?

private static final Minecraft mc = Minecraft.getMinecraft();
static RenderItem ri = mc.getRenderItem();

public static void doRender(EntityItem entity, double x, double y, double z, float entityYaw, float partialTicks) {
        ItemStack itemstack = entity.getItem();
        int i = itemstack.isEmpty() ? 187 : Item.getIdFromItem(itemstack.getItem()) + itemstack.getMetadata();
        boolean flag = false;

        GlStateManager.enableRescaleNormal();
        GlStateManager.alphaFunc(516, 0.1F);
        GlStateManager.enableBlend();
        RenderHelper.enableStandardItemLighting();
        GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
        GlStateManager.pushMatrix();
        IBakedModel ibakedmodel = ri.getItemModelWithOverrides(itemstack, entity.world, null);
        GlStateManager.translate(x, y+3f, z);
        ri.renderItem(itemstack, ibakedmodel);
        GlStateManager.popMatrix();
        GlStateManager.disableRescaleNormal();
        GlStateManager.disableBlend();
}

 

EDIT: Just tried it and it isn't rendering anything... What's wrong with above code?

Edited by MGlolenstine
added ri and mc

  • Author
4 minutes ago, gummby8 said:

Is your code actually getting called at all?

 

let me check... will report

 

It's not... hmm

 

I think I know why... my class extends TESR...

Edited by MGlolenstine
update

  • Author

I changed event, and now I get a NPE on this line

IBakedModel ibakedmodel = ri.getItemModelWithOverrides(entity.getItem(), entity.world, null);

 

2 minutes ago, MGlolenstine said:

I changed event, and now I get a NPE on this line


IBakedModel ibakedmodel = ri.getItemModelWithOverrides(entity.getItem(), entity.world, null);

 

static RenderItem ri = mc.getRenderItem();

Have you tried...not doing it like this?

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.

  • Author
11 minutes ago, Draco18s said:

static RenderItem ri = mc.getRenderItem();

Have you tried...not doing it like this?

Can you suggest me something else? I'll gladly accept it.

...inline it?

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.

  • Author
2 minutes ago, Draco18s said:

...inline it?

like this?

IBakedModel ibakedmodel = mc.getRenderItem().getItemModelWithOverrides(entity.getItem(), entity.world, null);

 

You can even create a local variable, but yes.

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.

  • Author

Now I'm having an NPE at this line...

It's interesting as it hasn't been there before...

doRender(ei, ep.posX, ep.posY, ep.posZ, ep.cameraYaw, mc.getRenderPartialTicks());

It's the line I use to call the onRender method I posted above...

When I surround it with try/catch and I put in 

System.out.println(ei+", "+ ep.posX+", "+ ep.posY+", "+ ep.posZ+", "+ ep.cameraYaw+", "+ mc.getRenderPartialTicks());

I get 

EntityItem['item.item.compass'/3916, l='MpServer', x=0.00, y=0.00, z=0.00], 0.5, 22.0, 0.5, 0.0, 0.43997753

in the console

 

FIXED THE NPE

Edited by MGlolenstine
FIXED THE NPE

  • Author

But I still have a problem with the code not rendering an item

It's supposed to draw the item player is holding in hands above their heads.

Untitled.png

  • Author
36 minutes ago, gummby8 said:

doRender coordinates are relative between the player and the object being rendered. Your coordinates are all 0. So you are rendering the thing inside the current players player model. 

 

You need to put it above the target players model. 

Few things you can try to troubleshoot with

 

Look at it from first and third person view

 

Try scaling up your render with


GL11.glScalef(100, 100, 100);

put that before your doRender. then look around for something that is gigantic.

 

add to your doRender coords and see what you get


doRender(ei, ep.posX + 10, ep.posY + 10, ep.posZ + 10, ep.cameraYaw, mc.getRenderPartialTicks());

 

I will consider scaling it, but I thought that I moved the entity with this line inside of the doRender method

GlStateManager.translate(x, y+3f, z);

 

  • Author

So wait... If I understand correctly, the item is going to get rendered depending on ItemEntity's coordinates? Not the matrix coordinates?

 

If the above is correct, I've gotten everything wrong :D

  • Author
6 hours ago, gummby8 said:

The doRender coords place the matrix in the world relative to cameras position

 

The translate coords move the rendered item relative to the doRender coords

 

so your doRender coords should be something like 

x = player.x - targetPlayer.x

y = player.y - targetPlayer.y + 10 //so the item is raised above the player head

z = player.x - targetPlayer.z

 


doRender(ei, x, y, z ep.cameraYaw, mc.getRenderPartialTicks());

Thanks

  • Author
15 hours ago, gummby8 said:

The doRender coords place the matrix in the world relative to cameras position

 

The translate coords move the rendered item relative to the doRender coords

 

so your doRender coords should be something like 

x = player.x - targetPlayer.x

y = player.y - targetPlayer.y + 10 //so the item is raised above the player head

z = player.x - targetPlayer.z

 


doRender(ei, x, y, z ep.cameraYaw, mc.getRenderPartialTicks());

I'm sorry for quoting your post again, but do you mean EntityItem's coordinates when you say doRender?

Should I just remove the translation?

  • Author

Ok, so I got it working, but now I don't know how to remove items... I thought that items are going to stay for one renderTick and then dissapear... but now I'm getting awful framerates, because I can't remove them.

Loads of items

Another question... How can I prevent items from spinning and have them always face player?

 

I'm also trying to remove obsolete entities from the world using the following:

for(Map.Entry<UUID, Integer> uu : playerItem.entrySet()){
  mc.world.removeEntityFromWorld(uu.getValue());
}

playerItem is where I store data about player's UUID and Item's entityID

Edited by MGlolenstine

  • Author

I've searched the wonders of internet and I couldn't find anything on removing EntityItem except one that said that I can use 

EntityItem#setDead()

but it doesn't remove my items...

Now I tried to do it by setting item in the item entity to air, and there is less lag, the problem comes after time, when entities build up, because I'm not removing them, I'm just making them invisible.

  • Author
3 minutes ago, gummby8 said:

Looks liek you are spawning way too many entities, you should only be spawning 1 per player....that is if I even understand what you are trying to do

Well... I got it working, but when player leaves the world, item stays behind floating in the air... I don't know how to remove that floating item. I have it's Entity, but I can't do setDead() it's not working.

  • Author
Just now, gummby8 said:

where are you putting setDead() ?

 

Where should I put it?

 

I put it after the check if the player is still in the world

  • Author
4 minutes ago, gummby8 said:

is your check getting called?

It is...

Wait... I might be on to something

How can I prevent items from getting spun?

Edited by MGlolenstine

  • Author

I figured out the removing now...

But there is still a problem with rendering...

The rotation is still "jittery" as It's probaby not getting executed every render tick.

I'm using following command to rotate the item.

ei.setPositionAndRotation(ep.prevPosX + (ep.posX - ep.prevPosX) * e.getPartialTicks(), (ep.prevPosY + (ep.posY - ep.prevPosY) * e.getPartialTicks())+3f, ep.prevPosZ + (ep.posZ - ep.prevPosZ) * e.getPartialTicks(), pos.yaw, pos.pitch);

but as I said... Is there a way for me to remove that "jitter"

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.