Jump to content

Recommended Posts

Posted

Okay, I've been happily modding entities for a while now, with custom models and renderer classes and it worked well.  I recently tried to do something that required something to be dynamically passed to the renderer and when I really thought about how the renderer registration works I started to confuse myself. 

 

The confusion came about because I was creating an egg-like throwable item and so I copied the render class for the snowball item.  However, the constructor for the snowball takes an Item parameter and so at the time of registration you have to pass an instance to it.  But my problem is that each instance of my item may render differently (mostly different colors).

 

So I think it won't work directly because the Item instance passed to the RenderSnowball during registration will be different than the instance of the item I'm actually wanting to render.  In other words it will render the original item passed and not the current one that created the entity being thrown.

 

I just want to confirm that point, as I guess I'll have to go through some hoops to make it work.  Basically my plan is to have the throwable entity get the custom render information from the item at the time it is thrown, and then pass that back to the renderer.

 

Not sure if my explanation above is clear.  My question is specifically whether the RenderSnowball will render the Item as registered rather than the item as used to create the entity.  My review of the code indicates: yes.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

You could do as suggested above, or try something I've used which is to store the ItemStack in the entity's DataWatcher:

// data type 5 is ItemStack, as seen in EntityItem's entityInit()
dataWatcher.addObjectByDataType(DATAWATCHER_INDEX, 5);

// then before you spawn your entity, update the DataWatcher with whatever ItemStack you want

 

I did it that way because at the time I didn't know about IEntityAdditionalSpawnData, and it seems to get the job done just as well. I don't know if there is any advantage to one over the other, but perhaps some others have input in that regard.

Posted

Thanks both of you.  Pretty much what I expected.  Need to bring original item along with the entity.  Data watcher is interesting as it would save the packet sync.  I need to look at that additional spawn data interface, also looks interesting and isn't something I noticed before.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

Thanks both of you.  Pretty much what I expected.  Need to bring original item along with the entity.  Data watcher is interesting as it would save the packet sync.  I need to look at that additional spawn data interface, also looks interesting and isn't something I noticed before.

The additional spawn data is for the spawn entity packet sent to the client automatically by Forge (this is why you need to register all your mod entities, for this specific packet); thus, if you implemented that interface, you wouldn't have to do interact with the packet at all manually.

 

Either way you do it, you still need to set the ItemStack you want before you spawn the entity, and then have a method to retrieve it (or make it a public field, but that's just bad practice :P )

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.