diff options
Diffstat (limited to 'src')
10 files changed, 92 insertions, 18 deletions
diff --git a/src/main/java/net/minecraft/server/EntityEnderDragon.java b/src/main/java/net/minecraft/server/EntityEnderDragon.java index 7d2cf37e..ffbc15a8 100644 --- a/src/main/java/net/minecraft/server/EntityEnderDragon.java +++ b/src/main/java/net/minecraft/server/EntityEnderDragon.java @@ -82,7 +82,7 @@ public class EntityEnderDragon extends EntityLiving implements IComplex { float f1; if (!this.world.isStatic) { - this.datawatcher.watch(16, Integer.valueOf(this.health)); + this.datawatcher.watch(16, Integer.valueOf(this.getScaledHealth())); // CraftBukkit - this.health -> this.getScaledHealth() } else { f = MathHelper.cos(this.bN * 3.1415927F * 2.0F); f1 = MathHelper.cos(this.bM * 3.1415927F * 2.0F); @@ -307,7 +307,7 @@ public class EntityEnderDragon extends EntityLiving implements IComplex { } this.bR = null; - } else if (this.ticksLived % 10 == 0 && this.health < this.getMaxHealth()) { + } else if (this.ticksLived % 10 == 0 && this.health < this.maxHealth) { // CraftBukkit - this.getMaxHealth() -> this.maxHealth // CraftBukkit start EntityRegainHealthEvent event = new EntityRegainHealthEvent(this.getBukkitEntity(), 1, EntityRegainHealthEvent.RegainReason.ENDER_CRYSTAL); this.world.getServer().getPluginManager().callEvent(event); diff --git a/src/main/java/net/minecraft/server/EntityHuman.java b/src/main/java/net/minecraft/server/EntityHuman.java index 3aec4df3..85663915 100644 --- a/src/main/java/net/minecraft/server/EntityHuman.java +++ b/src/main/java/net/minecraft/server/EntityHuman.java @@ -294,7 +294,8 @@ public abstract class EntityHuman extends EntityLiving implements ICommandListen --this.bN; } - if (this.world.difficulty == 0 && this.getHealth() < this.getMaxHealth() && this.ticksLived % 20 * 12 == 0) { + // CraftBukkit - this.getMaxHealth() -> this.maxHealth + if (this.world.difficulty == 0 && this.getHealth() < this.maxHealth && this.ticksLived % 20 * 12 == 0) { // CraftBukkit - added regain reason of "REGEN" for filtering purposes. this.heal(1, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.REGEN); } @@ -1289,7 +1290,7 @@ public abstract class EntityHuman extends EntityLiving implements ICommandListen } public boolean cd() { - return this.getHealth() > 0 && this.getHealth() < this.getMaxHealth(); + return this.getHealth() > 0 && this.getHealth() < this.maxHealth; // CraftBukkit - this.getMaxHealth() -> this.maxHealth } public void a(ItemStack itemstack, int i) { diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java index bae495a2..005b8617 100644 --- a/src/main/java/net/minecraft/server/EntityLiving.java +++ b/src/main/java/net/minecraft/server/EntityLiving.java @@ -106,8 +106,11 @@ public abstract class EntityLiving extends Entity { private int bV = 0; private Entity bW; protected int bI = 0; - public int expToDrop = 0; // CraftBukkit - public int maxAirTicks = 300; // CraftBukkit + // CraftBukkit start + public int expToDrop = 0; + public int maxAirTicks = 300; + public int maxHealth = this.getMaxHealth(); + // CraftBukkit end public EntityLiving(World world) { super(world); @@ -418,6 +421,14 @@ public abstract class EntityLiving extends Entity { return 0; } } + + public int getScaledHealth() { + if (this.maxHealth != this.getMaxHealth() && this.getHealth() > 0) { + return this.getHealth() * this.getMaxHealth() / this.maxHealth + 1; + } else { + return this.getHealth(); + } + } // CraftBukkit end protected void aP() { @@ -626,10 +637,11 @@ public abstract class EntityLiving extends Entity { if (!event.isCancelled()) { this.health += event.getAmount(); } - // CraftBukkit end - if (this.health > this.getMaxHealth()) { - this.health = this.getMaxHealth(); + // this.getMaxHealth() -> this.maxHealth + if (this.health > this.maxHealth) { + this.health = this.maxHealth; + // CraftBukkit end } this.noDamageTicks = this.maxNoDamageTicks / 2; @@ -1138,12 +1150,19 @@ public abstract class EntityLiving extends Entity { } nbttagcompound.set("DropChances", nbttaglist1); + nbttagcompound.setInt("Bukkit.MaxHealth", this.maxHealth); // CraftBukkit } public void a(NBTTagCompound nbttagcompound) { this.health = nbttagcompound.getShort("Health"); + // CraftBukkit start + if (nbttagcompound.hasKey("Bukkit.MaxHealth")) { + this.maxHealth = nbttagcompound.getInt("Bukkit.MaxHealth"); + } + if (!nbttagcompound.hasKey("Health")) { - this.health = this.getMaxHealth(); + this.health = this.maxHealth; // this.getMaxHealth() -> this.maxHealth + // CraftBukkit } this.hurtTicks = nbttagcompound.getShort("HurtTime"); @@ -1811,7 +1830,7 @@ public abstract class EntityLiving extends Entity { if (this.aG() == null) { return 3; } else { - int i = (int) ((float) this.health - (float) this.getMaxHealth() * 0.33F); + int i = (int) ((float) this.health - (float) this.maxHealth * 0.33F); // this.getMaxHealth() -> this.maxHealth i -= (3 - this.world.difficulty) * 4; if (i < 0) { diff --git a/src/main/java/net/minecraft/server/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java index e2938a76..86e6ea98 100644 --- a/src/main/java/net/minecraft/server/EntityPlayer.java +++ b/src/main/java/net/minecraft/server/EntityPlayer.java @@ -205,7 +205,8 @@ public class EntityPlayer extends EntityHuman implements ICrafting { } if (this.getHealth() != this.cl || this.cm != this.foodData.a() || this.foodData.e() == 0.0F != this.cn) { - this.playerConnection.sendPacket(new Packet8UpdateHealth(this.getHealth(), this.foodData.a(), this.foodData.e())); + // CraftBukkit - this.getHealth() -> this.getScaledHealth() + this.playerConnection.sendPacket(new Packet8UpdateHealth(this.getScaledHealth(), this.foodData.a(), this.foodData.e())); this.cl = this.getHealth(); this.cm = this.foodData.a(); this.cn = this.foodData.e() == 0.0F; @@ -773,7 +774,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting { this.newLevel = this.expLevel; } - this.health = 20; + this.health = this.maxHealth; this.fireTicks = 0; this.fallDistance = 0; this.foodData = new FoodMetaData(); diff --git a/src/main/java/net/minecraft/server/EntityWitch.java b/src/main/java/net/minecraft/server/EntityWitch.java index f7a32e5f..36154225 100644 --- a/src/main/java/net/minecraft/server/EntityWitch.java +++ b/src/main/java/net/minecraft/server/EntityWitch.java @@ -81,7 +81,7 @@ public class EntityWitch extends EntityMonster implements IRangedEntity { if (this.random.nextFloat() < 0.15F && this.isBurning() && !this.hasEffect(MobEffectList.FIRE_RESISTANCE)) { short1 = 16307; - } else if (this.random.nextFloat() < 0.05F && this.health < this.getMaxHealth()) { + } else if (this.random.nextFloat() < 0.05F && this.health < this.maxHealth) { // CraftBukkit - this.getMaxHealth -> this.maxHealth short1 = 16341; } else if (this.random.nextFloat() < 0.25F && this.aG() != null && !this.hasEffect(MobEffectList.FASTER_MOVEMENT) && this.aG().e(this) > 121.0D) { short1 = 16274; diff --git a/src/main/java/net/minecraft/server/EntityWither.java b/src/main/java/net/minecraft/server/EntityWither.java index 45bcf23e..b671bd50 100644 --- a/src/main/java/net/minecraft/server/EntityWither.java +++ b/src/main/java/net/minecraft/server/EntityWither.java @@ -70,7 +70,7 @@ public class EntityWither extends EntityMonster implements IRangedEntity { public void c() { if (!this.world.isStatic) { - this.datawatcher.watch(16, Integer.valueOf(this.health)); + this.datawatcher.watch(16, Integer.valueOf(this.getScaledHealth())); // CraftBukkit - this.health -> this.getScaledHealth() } this.motY *= 0.6000000238418579D; @@ -458,7 +458,7 @@ public class EntityWither extends EntityMonster implements IRangedEntity { } public boolean o() { - return this.b() <= this.getMaxHealth() / 2; + return this.b() <= this.maxHealth / 2; // CraftBukkit - this.getMaxHealth() -> this.maxHealth } public EnumMonsterType getMonsterType() { diff --git a/src/main/java/net/minecraft/server/MobEffectList.java b/src/main/java/net/minecraft/server/MobEffectList.java index 2c4563d4..86696498 100644 --- a/src/main/java/net/minecraft/server/MobEffectList.java +++ b/src/main/java/net/minecraft/server/MobEffectList.java @@ -75,7 +75,7 @@ public class MobEffectList { public void tick(EntityLiving entityliving, int i) { if (this.id == REGENERATION.id) { - if (entityliving.getHealth() < entityliving.getMaxHealth()) { + if (entityliving.getHealth() < entityliving.maxHealth) { // CraftBukkit - .getMaxHealth() -> .maxHealth entityliving.heal(1, RegainReason.MAGIC_REGEN); // CraftBukkit } } else if (this.id == POISON.id) { diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEnderDragonPart.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEnderDragonPart.java index b62c909e..ce4a87c9 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEnderDragonPart.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEnderDragonPart.java @@ -4,6 +4,7 @@ import net.minecraft.server.EntityComplexPart; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.entity.EnderDragon; import org.bukkit.entity.EnderDragonPart; +import org.bukkit.entity.Entity; public class CraftEnderDragonPart extends CraftComplexPart implements EnderDragonPart { public CraftEnderDragonPart(CraftServer server, EntityComplexPart entity) { @@ -24,4 +25,32 @@ public class CraftEnderDragonPart extends CraftComplexPart implements EnderDrago public String toString() { return "CraftEnderDragonPart"; } + + public void damage(int amount) { + getParent().damage(amount); + } + + public void damage(int amount, Entity source) { + getParent().damage(amount, source); + } + + public int getHealth() { + return getParent().getHealth(); + } + + public void setHealth(int health) { + getParent().setHealth(health); + } + + public int getMaxHealth() { + return getParent().getMaxHealth(); + } + + public void setMaxHealth(int health) { + getParent().setMaxHealth(health); + } + + public void resetMaxHealth() { + getParent().resetMaxHealth(); + } } diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java index f2f43466..8be89064 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java @@ -75,7 +75,21 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity { } public int getMaxHealth() { - return getHandle().getMaxHealth(); + return getHandle().maxHealth; + } + + public void setMaxHealth(int amount) { + Validate.isTrue(amount > 0, "Max health must be greater than 0"); + + getHandle().maxHealth = amount; + + if (getHealth() > amount) { + setHealth(amount); + } + } + + public void resetMaxHealth() { + setMaxHealth(getHandle().getMaxHealth()); } @Deprecated diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index beb62a00..523a2f3b 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -941,4 +941,14 @@ public class CraftPlayer extends CraftHumanEntity implements Player { } } } + + public void setMaxHealth(int amount) { + super.setMaxHealth(amount); + getHandle().m(); // Update health + } + + public void resetMaxHealth() { + super.resetMaxHealth(); + getHandle().m(); // Update health + } } |