From 509e3d2a328273b08e3a203023b117ad120b31dd Mon Sep 17 00:00:00 2001 From: feildmaster Date: Wed, 26 Dec 2012 19:07:47 -0600 Subject: Update maxhealth for entities that have variable max health. Fixes BUKKIT-3308 Slimes and wolves have health that can change based on certain conditions. So we check if their max health should be updated, and if it has been customized in any way. We also scale the wolf's health for their tail --- src/main/java/net/minecraft/server/Entity.java | 10 ++++++++++ src/main/java/net/minecraft/server/EntitySlime.java | 8 +++++++- src/main/java/net/minecraft/server/EntityWolf.java | 13 ++++++++++--- 3 files changed, 27 insertions(+), 4 deletions(-) (limited to 'src/main') diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java index 1b1cd912..32804143 100644 --- a/src/main/java/net/minecraft/server/Entity.java +++ b/src/main/java/net/minecraft/server/Entity.java @@ -1155,6 +1155,16 @@ public abstract class Entity { this.b(this.yaw, this.pitch); this.a(nbttagcompound); + // CraftBukkit start + if (this instanceof EntityLiving) { + EntityLiving entity = (EntityLiving) this; + // If the entity does not have a max health set yet, update it (it may have changed after loading the entity) + if (!nbttagcompound.hasKey("Bukkit.MaxHealth")) { + entity.maxHealth = entity.getMaxHealth(); + } + } + // CraftBukkit end + // CraftBukkit start - exempt Vehicles from notch's sanity check if (!(this.getBukkitEntity() instanceof Vehicle)) { if (Math.abs(this.motX) > 10.0D) { diff --git a/src/main/java/net/minecraft/server/EntitySlime.java b/src/main/java/net/minecraft/server/EntitySlime.java index 54e50d13..8be72498 100644 --- a/src/main/java/net/minecraft/server/EntitySlime.java +++ b/src/main/java/net/minecraft/server/EntitySlime.java @@ -26,10 +26,16 @@ public class EntitySlime extends EntityLiving implements IMonster { // CraftBukkit - protected -> public public void setSize(int i) { + boolean updateMaxHealth = this.getMaxHealth() == this.maxHealth; // CraftBukkit this.datawatcher.watch(16, new Byte((byte) i)); this.a(0.6F * (float) i, 0.6F * (float) i); this.setPosition(this.locX, this.locY, this.locZ); - this.setHealth(this.getMaxHealth()); + // CraftBukkit start + if (updateMaxHealth) { + this.maxHealth = this.getMaxHealth(); + } + this.setHealth(this.maxHealth); + // CraftBukkit end this.bd = i; } diff --git a/src/main/java/net/minecraft/server/EntityWolf.java b/src/main/java/net/minecraft/server/EntityWolf.java index cd71c1dc..19de09e2 100644 --- a/src/main/java/net/minecraft/server/EntityWolf.java +++ b/src/main/java/net/minecraft/server/EntityWolf.java @@ -43,7 +43,7 @@ public class EntityWolf extends EntityTameableAnimal { } protected void bm() { - this.datawatcher.watch(18, Integer.valueOf(this.getHealth())); + this.datawatcher.watch(18, Integer.valueOf(this.getScaledHealth())); // CraftBukkit - this.getHealth() -> this.getScaledHealth() } public int getMaxHealth() { @@ -80,7 +80,8 @@ public class EntityWolf extends EntityTameableAnimal { } protected String aY() { - return this.isAngry() ? "mob.wolf.growl" : (this.random.nextInt(3) == 0 ? (this.isTamed() && this.datawatcher.getInt(18) < 10 ? "mob.wolf.whine" : "mob.wolf.panting") : "mob.wolf.bark"); + // CraftBukkit - getInt(18) < 10 -> < this.maxHealth / 2 + return this.isAngry() ? "mob.wolf.growl" : (this.random.nextInt(3) == 0 ? (this.isTamed() && this.datawatcher.getInt(18) < this.maxHealth / 2 ? "mob.wolf.whine" : "mob.wolf.panting") : "mob.wolf.bark"); } protected String aZ() { @@ -235,11 +236,17 @@ public class EntityWolf extends EntityTameableAnimal { if (!this.world.isStatic) { // CraftBukkit - added event call and isCancelled check. if (this.random.nextInt(3) == 0 && !org.bukkit.craftbukkit.event.CraftEventFactory.callEntityTameEvent(this, entityhuman).isCancelled()) { + boolean updateMaxHealth = this.getMaxHealth() == this.maxHealth; // CraftBukkit this.setTamed(true); this.setPathEntity((PathEntity) null); this.b((EntityLiving) null); this.d.a(true); - this.setHealth(20); + // CraftBukkit start + if (updateMaxHealth) { + this.maxHealth = this.getMaxHealth(); + } + this.setHealth(this.maxHealth); + // CraftBukkit end this.setOwnerName(entityhuman.name); this.f(true); this.world.broadcastEntityEffect(this, (byte) 7); -- cgit v1.2.3