Jump to content

Recommended Posts

Posted (edited)

I want to cheack if a player wear my costum Armor i creat this:

but it always return false but why

and the if statment:

 

		if (hasVoidArmor(player)) {
			
			player.fallDistance = 0f;
			
			if (!player.isSneaking()) {
		
				if (!world.getBlockState(pos).isSolid()) {
					
					if (player.getMotion().getY() < 0) {
						
						player.setMotion(player.getMotion().getX(), 0, player.getMotion().getZ());
						
					}
					
				}
				
			}
			
		}

 

	private static boolean hasVoidArmor(PlayerEntity player) {
		
		ItemStack itemHead = player.getItemStackFromSlot(EquipmentSlotType.fromSlotTypeAndIndex(EquipmentSlotType.Group.ARMOR, 3));
		ItemStack itemChest = player.getItemStackFromSlot(EquipmentSlotType.fromSlotTypeAndIndex(EquipmentSlotType.Group.ARMOR, 2));
		ItemStack itemLegs = player.getItemStackFromSlot(EquipmentSlotType.fromSlotTypeAndIndex(EquipmentSlotType.Group.ARMOR, 1));
		ItemStack itemFeet = player.getItemStackFromSlot(EquipmentSlotType.fromSlotTypeAndIndex(EquipmentSlotType.Group.ARMOR, 0));
		
		ItemStack hasitemHead = new ItemStack(CaveArmor.VOID_HELMET.get());
		ItemStack hasitemChest = new ItemStack(CaveArmor.VOID_CHESTPLATE.get());
		ItemStack hasitemLegs = new ItemStack(CaveArmor.VOID_LEGGINS.get());
		ItemStack hasitemFeet = new ItemStack(CaveArmor.VOID_BOOTS.get());
		
		if (itemHead == hasitemHead) {
			
			if (itemChest == hasitemChest) {
				
				if (itemLegs == hasitemLegs) {
					
					if (itemFeet == hasitemFeet) {
						
						return true;
						
					} else {
						
						return false;
						
					}
					
				} else {
					
					return false;
					
				}
				
			} else {
				
				return false;
				
			}
			
		} else {
			
			return false;
			
		}
		
	}

 

ot this:

 

	private static boolean hasVoidArmor(PlayerEntity player) {
		
		ItemStack itemHead = player.getItemStackFromSlot(EquipmentSlotType.HEAD);
		ItemStack itemChest = player.getItemStackFromSlot(EquipmentSlotType.CHEST);
		ItemStack itemLegs = player.getItemStackFromSlot(EquipmentSlotType.LEGS);
		ItemStack itemFeet = player.getItemStackFromSlot(EquipmentSlotType.FEET);
		
		ItemStack hasitemHead = new ItemStack(CaveArmor.VOID_HELMET.get());
		ItemStack hasitemChest = new ItemStack(CaveArmor.VOID_CHESTPLATE.get());
		ItemStack hasitemLegs = new ItemStack(CaveArmor.VOID_LEGGINS.get());
		ItemStack hasitemFeet = new ItemStack(CaveArmor.VOID_BOOTS.get());
		
		if (itemHead == hasitemHead) {
			
			if (itemChest == hasitemChest) {
				
				if (itemLegs == hasitemLegs) {
					
					if (itemFeet == hasitemFeet) {
						
						return true;
						
					} else {
						
						return false;
						
					}
					
				} else {
					
					return false;
					
				}
				
			} else {
				
				return false;
				
			}
			
		} else {
			
			return false;
			
		}
		
	}

 

Edited by Luis_ST
Posted
5 minutes ago, diesieben07 said:

Why not just EquipmentSlotType.HEAD so everyone knows wtf you mean?

I also used that first then I tried that

 

10 minutes ago, diesieben07 said:

Why not just EquipmentSlotType.HEAD so everyone knows wtf you mean?

 

Please learn what the == operator in Java does. Then look at this again and understand why it will never work.

so i have to use .equals() ? but i just tried thiswith the Debugger and it will retrun false

Posted
2 minutes ago, diesieben07 said:

And you changed it... why?

i just creat to methods with diffrent code

 

3 minutes ago, diesieben07 said:

ook at ItemStack. Does it override equals? No, it does not. As such equals and == will do exactly the same.

then equals(ItemStack other, boolean limitTags)?

Posted
8 minutes ago, diesieben07 said:

You are running into precisely the reason why ItemStack does not override equals.

What do you actually want to check? Do you want to do an exact comparison? Do you want to exclude NBT? Do you want to exclude damage?

i just found it out
thank you

Posted (edited)
1 hour ago, diesieben07 said:

You are running into precisely the reason why ItemStack does not override equals.

What do you actually want to check? Do you want to do an exact comparison? Do you want to exclude NBT? Do you want to exclude damage?

I need your help again. I use the LivingHurtEvent to check whether a player gets damage from IN_FIRE, ON_FIRE, HOT_FLOOR, or LAVA. Then I check whether a player is wearing custom armor (using my method above) but I always get false back. When I change the armor it works.

 

https://github.com/Luis-st/XOres-1.16.1-6.4/blob/master/forge-1.16.1 Only Ores/src/main/java/net/luis/cave/events/client/entity/OnLivingHurtEvent.java

 

The heading is incorrect I use in 1.16.1

 

 

Edited by Luis_ST
spelling mistake
Posted
5 minutes ago, diesieben07 said:

The method you are using to compare ItemStacks also compares NBT tags, which includes the damage. Since you are always creating new stacks to compare against, you will only get a match for undamaged armor without any other NBT tags.

thanks next time i read first the i ask

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.