Jump to content

(Solved)[1.15.2]setHealth method don't work as I expected


Recommended Posts

Posted (edited)

This cord set max health to 40.0f as I expected, but setHealth don't work.

Logger always says "Change to: 40.0 / 40.0" only in Server Thread.

I think setHealth calls only in Server Thread.

How do I fix?

@SubscribeEvent
  public static void respawnPlayer(PlayerEvent.PlayerRespawnEvent event) {
    player.getAttribute(SharedMonsterAttributes.MAX_HEALTH).removeModifier(TestMaxHealthUUID);
    player.getAttribute(SharedMonsterAttributes.MAX_HEALTH).applyModifier(new AttributeModifier(TestMaxHealthUUID, "TestMaxHealth", 2.0f - 1.0f, AttributeModifier.Operation.MULTIPLY_TOTAL));
    player.setHealth(40.0f);
    LOGGER.debug("change to: " + player.getHealth() + " / " + player.getMaxHealth());
  }
Edited by kyazuki
Posted (edited)

I want to set max health to 40.0f as default value.

So I don't use effects of potions and equipments.

 

The game renders 20 hearts.

So the client knows my modified max health, didn't it?

Edited by kyazuki
Posted (edited)

applyModifier works, but setHealth didn't works.

 

My mod gradually reduces the max health from 40.0 to 10.0.

Then, the player whose max health is 10.0 is killed.

I want to reset the player's max health to 40.0.

So, I calls my method when the player dies.

The method reset their max healths as I expected.

However, setHealth doesn't work in the client.

Health is same value before they die(ex. 10.0 / 40.0), but LOGGER says 40.0 / 40.0 in Server Thread.

Client's health isn't synced to Server's health.

Edited by kyazuki
Posted

I checked by debugger.

setHealth method works in Server Thread.

Should I check methods in Render Thread?

I don't know the method which health synced to the server.

Posted (edited)

I was mistaken about isRemote method.

I reduced their max health in Render Thread( if(isRemote()) ).

Thank you very much!

 

Could you answer to this topic?

Edited by kyazuki

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.