[MC-4264] EntityLiving setHealth(int i) method throws Illegal Argument Exception Created: 08/Dec/12  Updated: 05/May/15  Resolved: 19/Jun/13

Status: Resolved
Project: Minecraft: Java Edition
Component/s: None
Affects Version/s: Minecraft 1.4.5, Minecraft 1.4.7, Minecraft 1.5.2
Fix Version/s: None

Type: Bug
Reporter: Josh Assignee: Unassigned
Resolution: Invalid Votes: 0
Labels: None
Environment:

Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\Users\deathmarine>java -version
java version "1.7.0_06"
Java(TM) SE Runtime Environment (build 1.7.0_06-b24)
Java HotSpot(TM) 64-Bit Server VM (build 23.2-b09, mixed mode)

C:\Users\deathmarine>


CHK:
Confirmation Status: Unconfirmed

 Description   

EntityLiving:630
public void setHealth(int i)

{ this.health = i; if (i > getMaxHealth()) i = getMaxHealth(); }

Fix:
public void setHealth(int i)

{ if (i > getMaxHealth()) i = getMaxHealth(); this.health = i; }

 Comments   
Comment by [Mojang] Grum (Erik Broes) [ 19/Jun/13 ]

Doesnt exist in 13w25b.

Comment by Markku [ 19/Feb/13 ]

1.4.7 Seems to still have the same old code. Would be nice to get instructions on how to reproduce that exception, though. Edit: Not that the wonder of exception matters, the bug is obvious even by reading the code, but just me being curious.

Comment by Tails [ 19/Feb/13 ]

Is this still a concern in the current Minecraft version? If so, please update the affected versions in order to best aid Mojang ensuring bugs are still valid in the latest releases/pre-releases.

Comment by Kumasasa [ 08/Dec/12 ]

Thanks

Comment by [Mod] CubeTheThird [ 08/Dec/12 ]

Corrected your code

Comment by Kumasasa [ 08/Dec/12 ]

Well, if everybody throws in his favourite bit of code:

public void setHealth(int i)
{this.health = Math.min(i,getMaxHealth()} 
Comment by [Mod] CubeTheThird [ 08/Dec/12 ]

How about:
public void setHealth(int i)

{this.health = i > getMaxHealth() ? getMaxHealth() : i; }
Generated at Sun Jan 12 12:03:59 UTC 2025 using Jira 9.12.2#9120002-sha1:301bf498dd45d800842af0b84230f1bb58606c13.