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.

Featured Replies

Posted

I am trying to make a mechanic where if a player is wearing a full hazmat suit they do not get poisoned.

My current way of doing it is this:

if((livingEntity.getItemStackFromSlot(EquipmentSlotType.HEAD) == new ItemStack(RegistryHandler.HAZMAT_HELMET.get())) && (livingEntity.getItemStackFromSlot(EquipmentSlotType.CHEST) == new ItemStack(RegistryHandler.HAZMAT_CHESTPLATE.get())) && (livingEntity.getItemStackFromSlot(EquipmentSlotType.LEGS) == new ItemStack(RegistryHandler.HAZMAT_LEGGINGS.get())) && (livingEntity.getItemStackFromSlot(EquipmentSlotType.FEET) == new ItemStack(RegistryHandler.HAZMAT_BOOTS.get()))) { return; }

but

1) It isn't working

2) It looks very janky and I don't like it.

4 minutes ago, sccreeper said:

I am trying to make a mechanic where if a player is wearing a full hazmat suit they do not get poisoned.

My current way of doing it is this:


if((livingEntity.getItemStackFromSlot(EquipmentSlotType.HEAD) == new ItemStack(RegistryHandler.HAZMAT_HELMET.get())) && (livingEntity.getItemStackFromSlot(EquipmentSlotType.CHEST) == new ItemStack(RegistryHandler.HAZMAT_CHESTPLATE.get())) && (livingEntity.getItemStackFromSlot(EquipmentSlotType.LEGS) == new ItemStack(RegistryHandler.HAZMAT_LEGGINGS.get())) && (livingEntity.getItemStackFromSlot(EquipmentSlotType.FEET) == new ItemStack(RegistryHandler.HAZMAT_BOOTS.get()))) { return; }

but

1) It isn't working

2) It looks very janky and I don't like it.

Probably you should use ItemStack::equals for comparing itemstacks

Everything said above may be absolutely wrong. No rights reserved.

Compare ItemStacks using some provided methods in ItemStack (I don't remember what they're called), but you should be checking if their Items are equal (which == is fine), not the ItemStacks.

Just now, diesieben07 said:

ItemStack has no equals method.

Oh, that's sad:(
But yeah, == is likely to not work here.

 

Everything said above may be absolutely wrong. No rights reserved.

  • Author

Got it to work with this code:
 

            if(e.player.inventory.hasItemStack(new ItemStack(RegistryHandler.HAZMAT_CHESTPLATE.get()))) {
                if(e.player.inventory.armorItemInSlot(2).getItem() == RegistryHandler.HAZMAT_CHESTPLATE.get()) {
                    e.player.removeActivePotionEffect(Effects.POISON);
                    e.player.removeActivePotionEffect(Effects.NAUSEA);
                    LOGGER.log(Level.INFO, "I works");
                    return;
                }

And yes I know I could check for both conditions with the && operator.
This post here helped a bit didn't realise armorItemSlot had other methods.
 

Edited by sccreeper

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.