diff options
author | T00thpick1 <t00thpick1dirko@gmail.com> | 2013-07-23 21:30:38 -0500 |
---|---|---|
committer | Wesley Wolfe <weswolf@aol.com> | 2013-07-23 21:52:17 -0500 |
commit | 1192f2a53a20354e7d2292a1c710d6bfe779b600 (patch) | |
tree | 0a543ad3c73860cd3b5ccec64e429c85ca2bdd41 /src/main/java/net/minecraft/server/EntityLiving.java | |
parent | 4ad3cdd4b5cfe90f319cfba6c4dabc9bff10a59d (diff) | |
download | craftbukkit-1192f2a53a20354e7d2292a1c710d6bfe779b600.tar craftbukkit-1192f2a53a20354e7d2292a1c710d6bfe779b600.tar.gz craftbukkit-1192f2a53a20354e7d2292a1c710d6bfe779b600.tar.lz craftbukkit-1192f2a53a20354e7d2292a1c710d6bfe779b600.tar.xz craftbukkit-1192f2a53a20354e7d2292a1c710d6bfe779b600.zip |
Add API to control scaled health. Adds BUKKIT-4590
This commit implements the ability to set the scale of hearts that the
client renders. When the Packet44UpdateAttributes packet is sent, the
max health attribute is replaced with a scaled version, to preserve the
scaled health illusion clientside.
In order to accurately display the scaled health for players, a true
health is stored within CraftPlayer, and the datawatcher now stores the
scaled health. The getHealth() method for players still returns their
true health.
Changed setHealth() within EntityLiving to appropriately handle health
for instances of EntityPlayer. Inlined a call to
setHealth(getMaxHealth()) within the EntityLiving constructor to work
around CraftEntity instantiation.
Additionally fixes the health values sent when eating food within
FoodMetaData and ItemFood, which previously sent the unscaled health;
this commit alters them to send the properly scaled health.
Additionally fixes BUKKIT-4535, BUKKIT-4536, and BUKKIT-4127
Diffstat (limited to 'src/main/java/net/minecraft/server/EntityLiving.java')
-rw-r--r-- | src/main/java/net/minecraft/server/EntityLiving.java | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java index 45b1410e..c7012c51 100644 --- a/src/main/java/net/minecraft/server/EntityLiving.java +++ b/src/main/java/net/minecraft/server/EntityLiving.java @@ -82,7 +82,8 @@ public abstract class EntityLiving extends Entity { public EntityLiving(World world) { super(world); this.ay(); - this.setHealth(this.getMaxHealth()); + // CraftBukkit - setHealth(getMaxHealth()) -> current - inlined to skip the instanceof check for EntityPlayers + this.datawatcher.watch(6, (float) this.getAttributeInstance(GenericAttributes.a).getValue()); this.m = true; this.aM = (float) (Math.random() + 1.0D) * 0.01F; this.setPosition(this.locX, this.locY, this.locZ); @@ -583,10 +584,31 @@ public abstract class EntityLiving extends Entity { } public final float getHealth() { + // CraftBukkit start - Scaled Health + if (this instanceof EntityPlayer) { + return (float) ((EntityPlayer) this).getBukkitEntity().getHealth(); + } + // CraftBukkit end return this.datawatcher.getFloat(6); } public void setHealth(float f) { + // CraftBukkit start - Scaled Health + if (this instanceof EntityPlayer) { + org.bukkit.craftbukkit.entity.CraftPlayer player = ((EntityPlayer) this).getBukkitEntity(); + // Squeeze + if (f < 0.0F) { + player.setRealHealth(0.0D); + } else if (f > player.getMaxHealth()) { + player.setRealHealth(player.getMaxHealth()); + } else { + player.setRealHealth(f); + } + + this.datawatcher.watch(6, Float.valueOf(player.getScaledHealth())); + return; + } + // CraftBukkit end this.datawatcher.watch(6, Float.valueOf(MathHelper.a(f, 0.0F, this.getMaxHealth()))); } |