Jump to content

[1.8] Rendering item model from item stack using EntityItem and...?


Recommended Posts

Posted

Hi, All.  :)

 

I'm still working on my shelves mod: I have my shelf block behaving properly, rendering and able to hold up to four item stacks.

I'm trying to make the item models render on the shelves in the proper location.

I want to say,

For each itemStacks[0 through 3],

take the ItemStack, find it's item model, render the item model in the proper location[0 through 3] relative to the block.

 

I was looking at EntityItem, and I can set an item stack, but I'm not sure how to render it.

Looking at RenderEntityItem, there are arguments of types RenderManager and RenderItem (and I'm not sure how to create those), but I'm thinking I should be able to find something that says "render this item in this location of this block" or something.  sounds like something I might have to write... 

 

What structure would you use to get this done?

hw developer in a sw world

Posted
float renderPosX;
float renderPosZ;

for(int i=0; i<4; i++) {
renderPosX = i/2; /*  0 / 2 = 0, 1 / 1 = 0, etc. */
renderPosZ = i%2;  /*  0 % 2 = 0, 1 % 2 = 1, etc. */
/*the multiply by some fraction, add in the block's world coordinates*/
/*finally, call the renderer*/
}

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

Thanks, Draco; so, what I got out of that is that the position data is of type float.

 

Right now I'm trying to figure out how to add in the block's coordinates but haven't found the translation between BlockPos and x, y, and z coordinates.

I'll have a y offset for my items, too, so I'll add that into the for loop.

I'm reading up on BlockPos and Entity and RenderEntityItem to figure out the position data.

 

It's the rendering part I'm stuck on. 

hw developer in a sw world

Posted
  On 3/11/2015 at 3:46 PM, RoseCotton said:

haven't found the translation between BlockPos and x, y, and z coordinates.

 

BlockPos.x ?

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

after stumbling around, the code that eclipse hasn't complained much about is:

 

double x = ((TileEntity)shelfTileEntity).getPos().getX();

double y = ((TileEntity)shelfTileEntity).getPos().getY();

double z = ((TileEntity)shelfTileEntity).getPos().getZ();

 

we'll see if that works...  :P

 

I can't believe I just realized yesterday that it's TileEntity, not TitleEntity.  I have a _lot_ of spelling errors in my code now.  :\

hw developer in a sw world

Posted

I've put together something that I think might render my items (I at least want to see if it works) but I'm not sure from where to call my RenderShelfTileEntity class.

 

package com.rosecotton.shelvesmod;

import net.minecraft.client.renderer.entity.RenderEntityItem;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.tileentity.TileEntity;

public class RenderShelfTileEntity 
{
public RenderShelfTileEntity(ShelfTitleEntity shelfTileEntity)
{
	RenderEntityItem renderEntityItem = new RenderEntityItem(null, null);
	double x = ((TileEntity)shelfTileEntity).getPos().getX();
	double y = ((TileEntity)shelfTileEntity).getPos().getY();
	double z = ((TileEntity)shelfTileEntity).getPos().getZ();
	EntityItem shelfEntityItem[] = new EntityItem[4];
	for (int n = 0; n <4; n++)
	{
		shelfEntityItem[n].setEntityItemStack(shelfTileEntity.itemStacks[n]);

		double xPlus = x + (double)((4+(n%2)*8)/16);
		double yPlus = y + (double)((2+(n/2)*6)/16);
		double zPlus = z + (double)((13-(n/2)*8)/16);

		renderEntityItem.func_177075_a(shelfEntityItem[n], xPlus, yPlus, zPlus, 0.0625f, 1.05f);
	}

}
}

 

Should I call this from the BlockShelf class, the ShelvesEventHandler (which currently doese nothing), or the ShelfTitleEntity class?

 

I know I need to rename everything that says TitleEntity to TileEntity.  :\

hw developer in a sw world

Posted

uh, oh.... if position data is type float, then I just calculated doubles for who-knows-what reason and passed them into I-don't-know-what in my renderEntityItem.func_177075_a(bunches-of-stuff).

hw developer in a sw world

Posted

UPDATE:

trying to update inventory in my shelf, which is where I call my EntityItem renderer code, definitely causes mc to crash.

 

 

  Reveal hidden contents

 

hw developer in a sw world

Posted

UPDATE:

I just stopped my mod from crashing when there's a null slot on my shelfblock (i.e. trying to render an empty item) by checking to make sure it's not null before doing the render.

 

however, it still doesn't render my items and when I remove them from my ShelfBlock storage slots, they disappear.  I must have broken something and not gotten the rendering right. 

 

package com.rosecotton.shelvesmod;

import net.minecraft.client.renderer.entity.RenderEntityItem;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.tileentity.TileEntity;

public class RenderShelfTileEntity 
{
public RenderShelfTileEntity(ShelfTitleEntity shelfTileEntity)
{
	RenderEntityItem renderEntityItem = new RenderEntityItem(null, null);
	double x = ((TileEntity)shelfTileEntity).getPos().getX();
	double y = ((TileEntity)shelfTileEntity).getPos().getY();
	double z = ((TileEntity)shelfTileEntity).getPos().getZ();
	EntityItem shelfEntityItem[] = new EntityItem[4];
	for (int n = 0; n <4; n++)
	{
		if (shelfEntityItem[n] != null)
		{
			shelfEntityItem[n].setEntityItemStack(shelfTileEntity.itemStacks[n]);
			double xPlus = x + (double)((4+(n%2)*8)/16);
			double yPlus = y + (double)((2+(n/2)*6)/16);
			double zPlus = z + (double)((13-(n/2)*8)/16);

			renderEntityItem.func_177075_a(shelfEntityItem[n], xPlus, yPlus, zPlus, 0.0625f, 1.05f);
		}


	}

}
}

hw developer in a sw world

Posted

Uhmm... that's not how you use a renderer. You probably have to use a

TESR (TileEntitySpecialRenderer)

.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted

hmmm...ok, I was hoping to get away from using that because it always led me down this trail of classes and methods until I got to arguments I couldn't figure out how to use, like RenderManager.

 

So to render an Item (any) that represents an ItemStack (any) held in a slot in the TileEntity (for me, ShelfTitleEntity because I misspelled it) of a Block (mine is BlockShelf), I need to use ShelfRenderer.renderTileEntityAt(TileEntity tileentity, double d0, double d1, double d2, float f, int i) which extends TileEntitySpecialRenderer.

The example I found creates a model, so ModelShelf shelf = new ModelShelf() (which extends model base), and that has a render method, shelf.render(TileEntity te, double x, double y, double z) that's called in renderTileEntityAt.

 

So where do I create a ShelfRenderer object and call its renderTileEntityAt method? 

Do I do that when I close the GUI for the BlockShelf (i.e. after putting objects in or taking them out)?

hw developer in a sw world

Posted

The TileEntitySpecialRenderer itself hasn't changed, only the rendering you do inside them is different.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

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.