Jump to content

Recommended Posts

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?

Posted (edited)

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
Posted (edited)
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
Posted
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.

Posted

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

Posted

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.

Posted (edited)

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
Posted
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);

 

Posted
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

Posted
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?

Posted (edited)

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
Posted

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.

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

Posted

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

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