Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.15.2] Max Health Attribute Issue
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 1
jaxbymc42

[1.15.2] Max Health Attribute Issue

By jaxbymc42, November 6, 2020 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

jaxbymc42    0

jaxbymc42

jaxbymc42    0

  • Tree Puncher
  • jaxbymc42
  • Members
  • 0
  • 14 posts
Posted November 6, 2020

I have made a set of armor that, when the full set is worn, the player is granted with 2 additional hearts.  Whenever you take the armor off, the two extra hearts disappear but are still "there" and the player acts as though he has 12 hearts when only 10 are shown (until the player takes enough damage to lose those 2 extra hearts then it is like vanilla MC with 10 hearts).  

I was just wondering what else to do to check and remove the extra life so when the armor is off, the player has only 10 hearts (not the extra 2 hearts that are "there" till damage gets rid of them).

 

public class HoneyArmorItem extends ArmorItem
{
	public HoneyArmorItem(IArmorMaterial materialIn, EquipmentSlotType slot, Properties builder) 
	{
		super(materialIn, slot, builder);
	}
	
	@Override
	public void onArmorTick(ItemStack stack, World world, PlayerEntity player)
	{		
		if(player.inventory.armorItemInSlot(0).getItem() == ItemInit.HONEY_BOOTS.get() &&
			player.inventory.armorItemInSlot(1).getItem() == ItemInit.HONEY_LEGGINGS.get() && 
			player.inventory.armorItemInSlot(2).getItem() == ItemInit.HONEY_CHESTPLATE.get() &&
			player.inventory.armorItemInSlot(3).getItem() == ItemInit.HONEY_HELMET.get())
		{			
				player.getAttributes().getAttributeInstance(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(24);
		} else { super.onArmorTick(stack, world, player);
			player.getAttributes().getAttributeInstance(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(20);				 		
			}	
	}
}
  • Quote

Share this post


Link to post
Share on other sites

poopoodice    118

poopoodice

poopoodice    118

  • Dragon Slayer
  • poopoodice
  • Members
  • 118
  • 928 posts
Posted November 6, 2020

You should probably apply modifiers on attributes instead of directly modify their base values.. but I'm not sure if there's anything to do with this.

  • Quote

Share this post


Link to post
Share on other sites

jaxbymc42    0

jaxbymc42

jaxbymc42    0

  • Tree Puncher
  • jaxbymc42
  • Members
  • 0
  • 14 posts
Posted November 6, 2020

I tried applying modifiers straight out but then I ran into the issue of infinitely adding 2 more hearts.

  • Quote

Share this post


Link to post
Share on other sites

poopoodice    118

poopoodice

poopoodice    118

  • Dragon Slayer
  • poopoodice
  • Members
  • 118
  • 928 posts
Posted November 6, 2020

show the updated code

 

  • Quote

Share this post


Link to post
Share on other sites

jaxbymc42    0

jaxbymc42

jaxbymc42    0

  • Tree Puncher
  • jaxbymc42
  • Members
  • 0
  • 14 posts
Posted November 6, 2020
public class HoneyArmorItem extends ArmorItem
{
	public HoneyArmorItem(IArmorMaterial materialIn, EquipmentSlotType slot, Properties builder) 
	{
		super(materialIn, slot, builder);
	}
	
	@Override
	public void onArmorTick(ItemStack stack, World world, PlayerEntity player)
	{		
		if(player.inventory.armorItemInSlot(0).getItem() == ItemInit.HONEY_BOOTS.get() &&
			player.inventory.armorItemInSlot(1).getItem() == ItemInit.HONEY_LEGGINGS.get() && 
			player.inventory.armorItemInSlot(2).getItem() == ItemInit.HONEY_CHESTPLATE.get() &&
			player.inventory.armorItemInSlot(3).getItem() == ItemInit.HONEY_HELMET.get())
		{					
		      player.getAttribute(SharedMonsterAttributes.MAX_HEALTH).applyModifier(new AttributeModifier("MaxHealth", 4.0f, AttributeModifier.Operation.ADDITION));
			
		} else { super.onArmorTick(stack, world, player);
			player.getAttribute(SharedMonsterAttributes.MAX_HEALTH).removeModifier(new AttributeModifier("MaxHealth", 4.0f, AttributeModifier.Operation.ADDITION));		 		
		}	
	}
}
  • Quote

Share this post


Link to post
Share on other sites

poopoodice    118

poopoodice

poopoodice    118

  • Dragon Slayer
  • poopoodice
  • Members
  • 118
  • 928 posts
Posted November 6, 2020 (edited)

You are applying a new modifier every tick, you should create a static final modifier, then apply/remove it to the player if the player has the modifier.

Edited November 6, 2020 by poopoodice
  • Quote

Share this post


Link to post
Share on other sites

diesieben07    7696

diesieben07

diesieben07    7696

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7696
  • 56382 posts
Posted November 6, 2020

You should use LivingEquipmentChangeEvent instead of applying the effect every tick.

  • Quote

Share this post


Link to post
Share on other sites

jaxbymc42    0

jaxbymc42

jaxbymc42    0

  • Tree Puncher
  • jaxbymc42
  • Members
  • 0
  • 14 posts
Posted November 6, 2020

How exactly do I go about using LivingEquipmentChangeEvent?

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    7696

diesieben07

diesieben07    7696

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7696
  • 56382 posts
Posted November 6, 2020

https://mcforge.readthedocs.io/en/latest/events/intro/

  • Quote

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 1
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • cadbane86140
      Minecraft: Parkour Stairs Part 1!

      By cadbane86140 · Posted 2 minutes ago

      Hello There! Today we are playing a BRAND NEW parkour map that was actually just released about a month ago and all I gotta say is that this map is so freaking unique and the map creators did something with this map that we have never seen in parkour before! There are so many hilarious moments in this video that I know you guys are gonna love! I hope you all enjoy this video and if you did don't forget to like and sub for more! https://www.youtube.com/watch?v=5aGkMp5bExg
    • cadbane86140
      Minecraft: Parkour Stairs Part 1!

      By cadbane86140 · Posted 3 minutes ago

      Hello There! Today we are playing a BRAND NEW parkour map that was actually just released about a month ago and all I gotta say is that this map is so freaking unique and the map creators did something with this map that we have never seen in parkour before! There are so many hilarious moments in this video that I know you guys are gonna love! I hope you all enjoy this video and if you did don't forget to like and sub for more! https://www.youtube.com/watch?v=5aGkMp5bExg
    • kiou.23
      Block Rotate

      By kiou.23 · Posted 31 minutes ago

      That's usually the case, always try to understand the code before copy and pasting, or else you'll get a lot of headaches later in the code's life
    • Varzac
      Forge jar file not opening

      By Varzac · Posted 57 minutes ago

      I ran Jarfix and then tried installing again with the same results. Nothing happening I even tried using winrar, but as you said nothing happened
    • BeardlessBrady
      [1.16.4] Null when OpenGUI

      By BeardlessBrady · Posted 1 hour ago

      Ah.. Thats what I get for stopping half way through and not double checking, thanks!
  • Topics

    • cadbane86140
      0
      Minecraft: Parkour Stairs Part 1!

      By cadbane86140
      Started 2 minutes ago

    • cadbane86140
      0
      Minecraft: Parkour Stairs Part 1!

      By cadbane86140
      Started 3 minutes ago

    • ehbean
      10
      Block Rotate

      By ehbean
      Started 7 hours ago

    • Varzac
      3
      Forge jar file not opening

      By Varzac
      Started 13 hours ago

    • BeardlessBrady
      2
      [1.16.4] Null when OpenGUI

      By BeardlessBrady
      Started 1 hour ago

  • Who's Online (See full list)

    • cadbane86140
    • ehbean
    • We Random
    • The_Deadly_Taco
    • kiou.23
    • DieGo901yt
    • brok4d
    • JackRaidenPH
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.15.2] Max Health Attribute Issue
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community