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    117

poopoodice

poopoodice    117

  • Dragon Slayer
  • poopoodice
  • Members
  • 117
  • 925 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    117

poopoodice

poopoodice    117

  • Dragon Slayer
  • poopoodice
  • Members
  • 117
  • 925 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    117

poopoodice

poopoodice    117

  • Dragon Slayer
  • poopoodice
  • Members
  • 117
  • 925 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    7690

diesieben07

diesieben07    7690

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7690
  • 56306 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    7690

diesieben07

diesieben07    7690

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7690
  • 56306 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

    • diesieben07
      The game crashed whilst rendering overlay

      By diesieben07 · Posted 25 minutes ago

      In the future please make your own thread instead of posting in an old, unrelated thread.   Delete this file.
    • FactionsFire
      Exit code 0 Sorry for inconvenience

      By FactionsFire · Posted 27 minutes ago

      I am trying to lanuch 1.8.9 forge and i get "An unexpected issue happened and the game has crashed exit sorry for inconvenience exit code 0"" And this has happened for about a week. 
    • Merken
      The game crashed whilst rendering overlay

      By Merken · Posted 31 minutes ago

      The game crashed whilst rendering overlay Error: net.minecraftforge.fml.config.ConfigFileTypeHandler$ConfigLoadingException: Failed loading config file forge-client.toml of type CLIENT for modid forge Exit Code: -1
    • Merken
      The game crashed whilst rendering overlay

      By Merken · Posted 36 minutes ago

      The game crashed whilst rendering overlay Error: net.minecraftforge.fml.config.ConfigFileTypeHandler$ConfigLoadingException: Failed loading config file forge-client.toml of type CLIENT for modid forge Exit Code: -1
    • diesieben07
      My game keeps crashing

      By diesieben07 · Posted 1 hour ago

      You do not. In the future please make your own thread instead of posting in some random thread that looks vaguely similar.   Your Optifine version is outdated and not listed as compatible with your version of Forge. Refer to the Optifine downloads page regarding compatibility with Forge.
  • Topics

    • Merken
      2
      The game crashed whilst rendering overlay

      By Merken
      Started 36 minutes ago

    • FactionsFire
      0
      Exit code 0 Sorry for inconvenience

      By FactionsFire
      Started 27 minutes ago

    • seekR4621
      1
      My game keeps crashing

      By seekR4621
      Started 2 hours ago

    • NorthWestWind
      2
      [1.16.x] Stop Held Item blobbing in Hand

      By NorthWestWind
      Started 2 hours ago

    • ehbean
      1
      1.16.x Custom Furnace/Brewing Stand

      By ehbean
      Started 11 hours ago

  • Who's Online (See full list)

    • Differentiation
    • diesieben07
    • Nanook
    • loordgek
    • Luis_ST
    • FactionsFire
  • 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