diff options
author | Dinnerbone <dinnerbone@dinnerbone.com> | 2011-09-15 06:24:45 +0100 |
---|---|---|
committer | Dinnerbone <dinnerbone@dinnerbone.com> | 2011-09-15 06:24:45 +0100 |
commit | 8b08696177df412f708cb161972f0dc1d464874f (patch) | |
tree | 61c77ffdb9040170396cae807a206edfb4665771 /src/main/java | |
parent | 7eff773769d55b3c090d3846b7981b65560c9abd (diff) | |
download | craftbukkit-8b08696177df412f708cb161972f0dc1d464874f.tar craftbukkit-8b08696177df412f708cb161972f0dc1d464874f.tar.gz craftbukkit-8b08696177df412f708cb161972f0dc1d464874f.tar.lz craftbukkit-8b08696177df412f708cb161972f0dc1d464874f.tar.xz craftbukkit-8b08696177df412f708cb161972f0dc1d464874f.zip |
Implemented food methods + fixed dying resetting food
Diffstat (limited to 'src/main/java')
3 files changed, 113 insertions, 0 deletions
diff --git a/src/main/java/net/minecraft/server/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java index 53ac7b1e..b49ed108 100644 --- a/src/main/java/net/minecraft/server/EntityPlayer.java +++ b/src/main/java/net/minecraft/server/EntityPlayer.java @@ -99,6 +99,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting { this.itemInWorldManager = new ItemInWorldManager((WorldServer) world); this.itemInWorldManager.player = this; this.itemInWorldManager.a(oldMode); + this.m = new FoodMetaData(); // CraftBukkit end } diff --git a/src/main/java/net/minecraft/server/FoodMetaData.java b/src/main/java/net/minecraft/server/FoodMetaData.java new file mode 100644 index 00000000..29ea6efc --- /dev/null +++ b/src/main/java/net/minecraft/server/FoodMetaData.java @@ -0,0 +1,88 @@ +package net.minecraft.server; + +public class FoodMetaData { + + // CraftBukkit start - all made public + public int a = 20; + public float b = 5.0F; + public float c; + public int d = 0; + // CraftBukkit end + private int e = 20; + + public FoodMetaData() {} + + public void a(int i, float f) { + this.a = Math.min(i + this.a, 20); + this.b = Math.min(this.b + (float) i * f * 2.0F, (float) this.a); + } + + public void a(ItemFood itemfood) { + this.a(itemfood.k(), itemfood.l()); + } + + public void a(EntityHuman entityhuman) { + int i = entityhuman.world.spawnMonsters; + + this.e = this.a; + if (this.c > 4.0F) { + this.c -= 4.0F; + if (this.b > 0.0F) { + this.b = Math.max(this.b - 1.0F, 0.0F); + } else if (i > 0) { + this.a = Math.max(this.a - 1, 0); + } + } + + if (this.a >= 18 && entityhuman.W()) { + ++this.d; + if (this.d >= 80) { + entityhuman.c(1); + this.d = 0; + } + } else if (this.a <= 0) { + ++this.d; + if (this.d >= 80) { + if (entityhuman.health > 10 || i >= 3 || entityhuman.health > 1 && i >= 2) { + entityhuman.damageEntity(DamageSource.f, 1); + } + + this.d = 0; + } + } else { + this.d = 0; + } + } + + public void a(NBTTagCompound nbttagcompound) { + if (nbttagcompound.hasKey("foodLevel")) { + this.a = nbttagcompound.e("foodLevel"); + this.d = nbttagcompound.e("foodTickTimer"); + this.b = nbttagcompound.g("foodSaturationLevel"); + this.c = nbttagcompound.g("foodExhaustionLevel"); + } + } + + public void b(NBTTagCompound nbttagcompound) { + nbttagcompound.a("foodLevel", this.a); + nbttagcompound.a("foodTickTimer", this.d); + nbttagcompound.a("foodSaturationLevel", this.b); + nbttagcompound.a("foodExhaustionLevel", this.c); + } + + public int a() { + return this.a; + } + + public boolean b() { + return this.a < 20; + } + + public void a(float f) { + this.c = Math.min(this.c + f, 40.0F); + } + + public float c() { + return this.b; + } +}
\ No newline at end of file diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index 86eeb82e..8076fa08 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -424,4 +424,28 @@ public class CraftPlayer extends CraftHumanEntity implements Player { getHandle().exp = getTotalExperience(); } } + + public float getExhaustion() { + return getHandle().V().c; + } + + public void setExhaustion(float value) { + getHandle().V().c = value; + } + + public float getSaturation() { + return getHandle().V().b; + } + + public void setSaturation(float value) { + getHandle().V().b = value; + } + + public int getFoodLevel() { + return getHandle().V().a; + } + + public void setFoodLevel(int value) { + getHandle().V().a = value; + } } |