Posted September 3, 20178 yr 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?
September 3, 20178 yr 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 September 3, 20178 yr by MGlolenstine added ri and mc
September 3, 20178 yr 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 September 3, 20178 yr by MGlolenstine update
September 3, 20178 yr Author I changed event, and now I get a NPE on this line IBakedModel ibakedmodel = ri.getItemModelWithOverrides(entity.getItem(), entity.world, null);
September 3, 20178 yr 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.
September 3, 20178 yr 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.
September 3, 20178 yr ...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.
September 3, 20178 yr Author 2 minutes ago, Draco18s said: ...inline it? like this? IBakedModel ibakedmodel = mc.getRenderItem().getItemModelWithOverrides(entity.getItem(), entity.world, null);
September 3, 20178 yr 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.
September 3, 20178 yr 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 September 3, 20178 yr by MGlolenstine FIXED THE NPE
September 3, 20178 yr 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.
September 3, 20178 yr 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);
September 3, 20178 yr 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
September 4, 20178 yr 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
September 4, 20178 yr 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?
September 4, 20178 yr 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. 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 September 4, 20178 yr by MGlolenstine
September 4, 20178 yr 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.
September 4, 20178 yr 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.
September 4, 20178 yr 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
September 4, 20178 yr 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 September 4, 20178 yr by MGlolenstine
September 4, 20178 yr 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.