This is designed for a TileEntity, but you could adapt it for other things aswell!
This is also designed for 1.7+, but it may work in older versions.
12/2/2014: Finished the 'B' option
Assuming you are using a TileEntity, this is what your render class should look like:
package your.package;
import stuff.here;
public class MyTileRendererClass extends TileEntitySpecialRenderer
{
public MyModel model = new MyModel();
@Override
public void renderTileEntityAt(TileEntity entity, double x, double y, double z, float f)
{
GL11.glPushMatrix();
//Render Model Here
GL11.glPopMatrix();
}
}
Option A: Static ItemStack (non-changing)
After the "public MyModel model..." line, add this:
ItemStack stack = new ItemStack(your_item_here, 1, 0);
EntityItem entItem = new EntityItem(Minecraft.getMinecraft().theWorld, 0D, 0D, 0D, stack);
Now after the GL11.glPopMatrix(), add this:
GL11.glPushMatrix();
//Without the below line, the item will spazz out
this.entItem.hoverStart = 0.0F;
RenderItem.renderInFrame = true;
GL11.glTranslatef((float)x + 0.5F, (float)y + 1.02F, (float)z + 0.3F);
GL11.glRotatef(180, 0, 1, 1);
RenderManager.instance.renderEntityWithPosYaw(this.entItem, 0.0D, 0.0D, 0.0D, 0.0F, 0.0F);
RenderItem.renderInFrame = false;
GL11.glPopMatrix();
Option B: Dynamic ItemStack (changing)
Note: Make sure that your TileEntity class implements IInventory!
After the "public MyModel model..." line, add this:
For people who are a bit stuck (especially if the item is being rendered in the player's face):
You must change the 0.0Ds to the coordinates of the tile entity. For example, if you want it on top of the block, centered, use this:
Did you make sure to include "GL11.glPopMatrix();" after "RenderItem.renderInFrame = false;"?
Hmmm, this is actually happening to me also after a rewrite of my mod, I'll see what I can come up with...
EDIT: I updated the tutorial, it should be fixed now!
For some reason when the item is rendered, it's very dark. (Darker than the actual item texture.)
I can't seem to fix it. Any ideas? Code is same as yours.
For some reason when the item is rendered, it's very dark. (Darker than the actual item texture.)
I can't seem to fix it. Any ideas? Code is same as yours.
Make sure that this is in your Block class:
@Override
public boolean isOpaqueCube()
{
return false;
}
Not bad, but I would recommend against instantiating a new ItemStack and EntityItem every single render frame - instead, why not make them class fields, like the model:
public class MyTileRendererClass extends TileEntitySpecialRenderer
{
public MyModel model = new MyModel();
private EntityItem itemEntity;
// actually, you don't even need to store the ItemStack - pass it to your constructor:
public MyTileRendererClass(ItemStack stack) {
itemEntity = new EntityItem(Minecraft.getMinecraft.thePlayer.getEntityWorld(), 0D, 0D, 0D, stack);
}
Then you can use 'this.itemEntity' during your rendering, and save your processor a lot of work
If you need the item to be dynamic, store the itemstack in your TileEntity and retrieve it from there during rendering, and only create a new EntityItem if the stack has changed in a way that would affect your rendering.
Not bad, but I would recommend against instantiating a new ItemStack and EntityItem every single render frame - instead, why not make them class fields, like the model:...code...
Then you can use 'this.itemEntity' during your rendering, and save your processor a lot of work
If you need the item to be dynamic, store the itemstack in your TileEntity and retrieve it from there during rendering, and only create a new EntityItem if the stack has changed in a way that would affect your rendering.
Thanks for the suggestion! I went ahead and changed the OP.
I followed your tutorial and adapted it for 1.6.4 (as far as im aware I changed one line for declaring the 'entItem') and the item renders but I have a weird texture on my screen when the blocks in the world (Screenshot attached).
Sorry for the delay, I'm not very active around here. I'll setup Forge for 1.6.4 and see if I can reproduce this, and hopefully fix it.
This is designed for a TileEntity, but you could adapt it for other things aswell!
This is also designed for 1.7+, but it may work in older versions.
12/2/2014: Finished the 'B' option
Assuming you are using a TileEntity, this is what your render class should look like:
package your.package; import stuff.here; public class MyTileRendererClass extends TileEntitySpecialRenderer { public MyModel model = new MyModel(); @Override public void renderTileEntityAt(TileEntity entity, double x, double y, double z, float f) { GL11.glPushMatrix(); //Render Model Here GL11.glPopMatrix(); } }Option A: Static ItemStack (non-changing)
Now after the GL11.glPopMatrix(), add this:
Option B: Dynamic ItemStack (changing)
After the "public MyModel model..." line, add this:
Now after the GL11.glPopMatrix(), add this:
And now your TileEntity should have the Item on it!
(Image from a mod I'm working in)
Yep! That's what I made this tutorial for
-
View User Profile
-
View Posts
-
Send Message
Curse Premium-
View User Profile
-
View Posts
-
Send Message
Moderator-
View User Profile
-
View Posts
-
Send Message
Curse PremiumIt's not needed
The renderEntityWithPosYaw function has that already in it, just change the 0.0D's to move it
You must change the 0.0Ds to the coordinates of the tile entity. For example, if you want it on top of the block, centered, use this:
Just thought I'd help out a bit
Did you make sure to include "GL11.glPopMatrix();" after "RenderItem.renderInFrame = false;"?Hmmm, this is actually happening to me also after a rewrite of my mod, I'll see what I can come up with...
EDIT: I updated the tutorial, it should be fixed now!
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumFor some reason when the item is rendered, it's very dark. (Darker than the actual item texture.)
I can't seem to fix it. Any ideas? Code is same as yours.
Make sure that this is in your Block class:
@Override public boolean isOpaqueCube() { return false; }-
View User Profile
-
View Posts
-
Send Message
Curse PremiumNope. I'm retarded.
-
View User Profile
-
View Posts
-
Send Message
Curse Premiumpublic class MyTileRendererClass extends TileEntitySpecialRenderer { public MyModel model = new MyModel(); private EntityItem itemEntity; // actually, you don't even need to store the ItemStack - pass it to your constructor: public MyTileRendererClass(ItemStack stack) { itemEntity = new EntityItem(Minecraft.getMinecraft.thePlayer.getEntityWorld(), 0D, 0D, 0D, stack); }Then you can use 'this.itemEntity' during your rendering, and save your processor a lot of work
If you need the item to be dynamic, store the itemstack in your TileEntity and retrieve it from there during rendering, and only create a new EntityItem if the stack has changed in a way that would affect your rendering.
Thanks for the suggestion! I went ahead and changed the OP.
I can not test it in eclipse crash report is shown below.
Sorry for the delay, I'm not very active around here. I'll setup Forge for 1.6.4 and see if I can reproduce this, and hopefully fix it.
Could you show me ALL of the code? You cut off the 'imports', and you have line numbers off, so I can't see where the error is coming from.