Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[1.11.2] My armor stand-like unit always replaces the placed item with air

Featured Replies

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?

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().

  • Author
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.

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

  • Author
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...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.