Add fix for health scaling - courtesy of Sleaker

By: md_5 <md_5@live.com.au>
This commit is contained in:
Spigot 2013-06-02 14:49:24 +10:00
parent 4b5e76bc22
commit 5f9489a272

View file

@ -0,0 +1,54 @@
From f2a8c9f207bf8e51ce517f8c0ceb647968567b66 Mon Sep 17 00:00:00 2001
From: Nick Minkler <sleaker@gmail.com>
Date: Sun, 2 Jun 2013 14:54:11 +1000
Subject: [PATCH] Fix Health Scaling
Fix scaled health sending incorrect values to client. No longer attempts to scale health above maximum. Hopefully fixes 'flash' when player eats food.
diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java
index 58a4acb..57d39fe 100644
--- a/src/main/java/net/minecraft/server/EntityLiving.java
+++ b/src/main/java/net/minecraft/server/EntityLiving.java
@@ -416,7 +416,10 @@ public abstract class EntityLiving extends Entity {
public int getScaledHealth() {
if (this.maxHealth != this.getMaxHealth() && this.getHealth() > 0) {
- return this.getHealth() * this.getMaxHealth() / this.maxHealth + 1;
+ // Spigot start
+ int health = (int) ((((double) this.getHealth()) / this.maxHealth) * this.getMaxHealth());
+ return health > 0 ? health : 1;
+ // Spigot end
} else {
return this.getHealth();
}
diff --git a/src/main/java/net/minecraft/server/FoodMetaData.java b/src/main/java/net/minecraft/server/FoodMetaData.java
index f26d552..8fcdbae 100644
--- a/src/main/java/net/minecraft/server/FoodMetaData.java
+++ b/src/main/java/net/minecraft/server/FoodMetaData.java
@@ -39,7 +39,8 @@ public class FoodMetaData {
this.foodLevel = event.getFoodLevel();
}
- ((EntityPlayer) entityhuman).playerConnection.sendPacket(new Packet8UpdateHealth(entityhuman.getHealth(), this.foodLevel, this.saturationLevel));
+ // Spigot - This next line fixes health scaling
+ ((EntityPlayer) entityhuman).playerConnection.sendPacket(new Packet8UpdateHealth(((EntityPlayer) entityhuman).getScaledHealth(), this.foodLevel, this.saturationLevel));
// CraftBukkit end
}
}
diff --git a/src/main/java/net/minecraft/server/ItemFood.java b/src/main/java/net/minecraft/server/ItemFood.java
index 409addf..c8a7f41 100644
--- a/src/main/java/net/minecraft/server/ItemFood.java
+++ b/src/main/java/net/minecraft/server/ItemFood.java
@@ -36,7 +36,8 @@ public class ItemFood extends Item {
entityhuman.getFoodData().eat(event.getFoodLevel() - oldFoodLevel, this.getSaturationModifier());
}
- ((EntityPlayer) entityhuman).playerConnection.sendPacket(new Packet8UpdateHealth(entityhuman.getHealth(), entityhuman.getFoodData().foodLevel, entityhuman.getFoodData().saturationLevel));
+ // Spigot - this next line fixes health scaling
+ ((EntityPlayer) entityhuman).playerConnection.sendPacket(new Packet8UpdateHealth(((EntityPlayer) entityhuman).getScaledHealth(), entityhuman.getFoodData().foodLevel, entityhuman.getFoodData().saturationLevel));
// CraftBukkit end
world.makeSound(entityhuman, "random.burp", 0.5F, world.random.nextFloat() * 0.1F + 0.9F);
--
1.8.1.2