Jump to content

Recommended Posts

Posted

I have a unit that will equip two items the player gives it, compare the two to a recipe, and give the player an item if it matches. To do this I first place the player item in the mobs main hand, then the second item in the off hand, compare the two and drop the item and kill the entity if they match. This is the method I use for equipping the entity. For some reason it doesn't remember what I set the item as, however, and instead replaces it with air (which is why I check if the mob is holding air. The consequence of this is that the mob always puts the item in the main slot, essentially deleting the previously held item.

 

This somewhat looks like a bug to me, since you check if the player is holding null, not air. Or is it something I'm doing wrong?

Posted
6 minutes ago, Jay Avery said:

If you're using 1.11+, the Item in an ItemStack is never null - instead you can check whether the stack is empty using ItemStack#isEmpty().

My problem isn't detecting whether the itemstack is empty or not. My problem is that the held item isn't saved. If I give the mob a diamond, and then a stick, it should be able to hold both the diamond AND the stick. It doesn't save the diamond however, and when I give it the stick he will only be holding the stick. Since it doesn't save the stick either, it will almost immediatly be air again.

Posted
Just now, Jay Avery said:

Are you aware that line #51 and line #58 are checking for the exact same condition? Should one of them be checking the offhand?

Typo on my part. It should indeed be checking the offhand. The mob still doesn't remember what he was equipped with though.

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.