summaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorEvilSeph <evilseph@gmail.com>2011-09-21 18:54:31 -0400
committerEvilSeph <evilseph@gmail.com>2011-09-21 22:13:54 -0400
commitaa0739d90a534cb8072c1432250aecfdf228e9f6 (patch)
treeff2bc7288d5cb52966b48d9632b744e78e13d31f /src/main/java
parent8d5a8667de3bd67e4230eeff2ed4d22c87350b3e (diff)
downloadcraftbukkit-aa0739d90a534cb8072c1432250aecfdf228e9f6.tar
craftbukkit-aa0739d90a534cb8072c1432250aecfdf228e9f6.tar.gz
craftbukkit-aa0739d90a534cb8072c1432250aecfdf228e9f6.tar.lz
craftbukkit-aa0739d90a534cb8072c1432250aecfdf228e9f6.tar.xz
craftbukkit-aa0739d90a534cb8072c1432250aecfdf228e9f6.zip
Added FoodLevelChange event.
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/net/minecraft/server/FoodMetaData.java14
-rw-r--r--src/main/java/net/minecraft/server/ItemFood.java91
2 files changed, 103 insertions, 2 deletions
diff --git a/src/main/java/net/minecraft/server/FoodMetaData.java b/src/main/java/net/minecraft/server/FoodMetaData.java
index d2106147..fe78d4ea 100644
--- a/src/main/java/net/minecraft/server/FoodMetaData.java
+++ b/src/main/java/net/minecraft/server/FoodMetaData.java
@@ -1,6 +1,9 @@
package net.minecraft.server;
-import org.bukkit.event.entity.EntityDamageEvent; // CraftBukkit
+// CraftBukkit start
+import org.bukkit.event.entity.EntityDamageEvent;
+import org.bukkit.event.entity.FoodLevelChangeEvent;
+// CraftBukkit end
public class FoodMetaData {
@@ -32,7 +35,14 @@ public class FoodMetaData {
if (this.saturationLevel > 0.0F) {
this.saturationLevel = Math.max(this.saturationLevel - 1.0F, 0.0F);
} else if (i > 0) {
- this.foodLevel = Math.max(this.foodLevel - 1, 0);
+ // CraftBukkit start
+ FoodLevelChangeEvent event = new FoodLevelChangeEvent(entityhuman.getBukkitEntity(), Math.max(this.foodLevel - 1, 0));
+ entityhuman.world.getServer().getPluginManager().callEvent(event);
+
+ if (!event.isCancelled()) {
+ this.foodLevel = event.getFoodLevel();
+ }
+ // CraftBukkit end
}
}
diff --git a/src/main/java/net/minecraft/server/ItemFood.java b/src/main/java/net/minecraft/server/ItemFood.java
new file mode 100644
index 00000000..cfafbb6c
--- /dev/null
+++ b/src/main/java/net/minecraft/server/ItemFood.java
@@ -0,0 +1,91 @@
+package net.minecraft.server;
+
+import org.bukkit.event.entity.FoodLevelChangeEvent; // CraftBukkit
+
+public class ItemFood extends Item {
+
+ public final int a;
+ private final int bt;
+ private final float bu;
+ private final boolean bv;
+ private boolean bw;
+ private int bx;
+ private int by;
+ private int bz;
+ private float bA;
+
+ public ItemFood(int i, int j, float f, boolean flag) {
+ super(i);
+ this.a = 32;
+ this.bt = j;
+ this.bv = flag;
+ this.bu = f;
+ }
+
+ public ItemFood(int i, int j, boolean flag) {
+ this(i, j, 0.6F, flag);
+ }
+
+ public ItemStack b(ItemStack itemstack, World world, EntityHuman entityhuman) {
+ --itemstack.count;
+ // CraftBukkit start
+ FoodLevelChangeEvent event = new FoodLevelChangeEvent(entityhuman.getBukkitEntity(), Math.min(this.k() + entityhuman.foodData.foodLevel, 20));
+ entityhuman.world.getServer().getPluginManager().callEvent(event);
+
+ if (!event.isCancelled()) {
+ entityhuman.getFoodData().a(event.getFoodLevel(), this.l());
+ }
+ // CraftBukkit end
+
+ if (!world.isStatic && this.bx > 0 && world.random.nextFloat() < this.bA) {
+ entityhuman.d(new MobEffect(this.bx, this.by * 20, this.bz));
+ }
+
+ return itemstack;
+ }
+
+ public int c(ItemStack itemstack) {
+ return 32;
+ }
+
+ public EnumAnimation b(ItemStack itemstack) {
+ return EnumAnimation.b;
+ }
+
+ public ItemStack a(ItemStack itemstack, World world, EntityHuman entityhuman) {
+ if (entityhuman.c(this.bw)) {
+ entityhuman.a(itemstack, this.c(itemstack));
+ }
+
+ return itemstack;
+ }
+
+ public int k() {
+ return this.bt;
+ }
+
+ public float l() {
+ return this.bu;
+ }
+
+ public boolean m() {
+ return this.bv;
+ }
+
+ public ItemFood a(int i, int j, int k, float f) {
+ this.bx = i;
+ this.by = j;
+ this.bz = k;
+ this.bA = f;
+ return this;
+ }
+
+ public ItemFood n() {
+ this.bw = true;
+ return this;
+ }
+
+ public Item a(String s) {
+ return super.a(s);
+ }
+}