Jump to content

Recommended Posts

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.

Posted
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.

Posted

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.

Posted
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.

Posted (edited)

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

×   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.