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

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

  • Author
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)?

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

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

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

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.