Jump to content

Test for player armor


Merthew

Recommended Posts

If you have a reference to the player, check their equipment slots. There are four of them.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

@SubscribeEvent
	public void onDamage(LivingDamageEvent event) {
		EntityPlayer player;
		List<ItemStack> armor = null;
		
		if(event.getEntity() instanceof EntityPlayer) {
			player = (EntityPlayer) event.getEntity();
			armor = (List<ItemStack>) player.getArmorInventoryList();
		}
		if(!armor.isEmpty()) {
			if(armor.get(0) == new ItemStack(ItemInit.BOOTS_MERTHEW)) {
				if(armor.get(1) == new ItemStack(ItemInit.LEGGINGS_MERTHEW)) {
					if(armor.get(2) == new ItemStack(ItemInit.CHESTPLATE_MERTHEW)) {
						if(armor.get(3) == new ItemStack(ItemInit.HELM_MERTHEW)) {
							event.setAmount(0);
						}
					}
				}
			}
		}
	}

This is what i was trying to do, what am i doing wrong?
if you need the git hub: https://github.com/Merthew/MerthewMod/

The seven became one and the one became two.

Link to comment
Share on other sites

wrong code.. srry

@Override
	public void onArmorTick(final World world, final EntityPlayer player, final ItemStack itemStack) {
		List<ItemStack> narmor = new ArrayList<ItemStack>();
		narmor.add(new ItemStack(ItemInit.BOOTS_MERTHEW));
		narmor.add(new ItemStack(ItemInit.LEGGINGS_MERTHEW));
		narmor.add(new ItemStack(ItemInit.CHESTPLATE_MERTHEW));
		narmor.add(new ItemStack(ItemInit.HELM_MERTHEW));
		
		List<ItemStack> armor = (List<ItemStack>) player.getArmorInventoryList();
		
		if(armor.get(0) == narmor.get(3)) {
			if (!player.isPotionActive(potionEffect.getPotion())) { // If the Potion isn't currently active,
				player.addPotionEffect(new PotionEffect(potionEffect)); // Apply a copy of the PotionEffect to the player
			}
		}
	}

 

The seven became one and the one became two.

Link to comment
Share on other sites

What if they are wearing only a chestplate? Is the list still 4 items long?

Are the items in the right order?

if(armor.get(0) == narmor.get(3))

This will never be true.

 

You should be using EntityPlayer#getItemStackFromSlot(EntityEquipmentSlot)

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

7 hours ago, Merthew said:

Thanks, i never knew about many of the methods you so far have helped with.

To compare ItemStacks you need to compare the item and the metadata. ItemStack#getItem and ItemStack.getMetadata() It is also possible to use the utility functions in the ItemStack class. ItemStack.are.....

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

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.