2011-09-22 00:54:31 +02:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
import org.bukkit.event.entity.FoodLevelChangeEvent; // CraftBukkit
|
|
|
|
|
|
|
|
public class ItemFood extends Item {
|
|
|
|
|
|
|
|
public final int a;
|
2011-11-20 09:01:14 +01:00
|
|
|
private final int b;
|
2012-01-12 23:10:13 +01:00
|
|
|
private final float bS;
|
|
|
|
private final boolean bT;
|
|
|
|
private boolean bU;
|
2011-11-20 09:01:14 +01:00
|
|
|
private int bV;
|
|
|
|
private int bW;
|
2012-01-12 23:10:13 +01:00
|
|
|
private int bX;
|
|
|
|
private float bY;
|
2011-09-22 00:54:31 +02:00
|
|
|
|
|
|
|
public ItemFood(int i, int j, float f, boolean flag) {
|
|
|
|
super(i);
|
|
|
|
this.a = 32;
|
2011-11-20 09:01:14 +01:00
|
|
|
this.b = j;
|
2012-01-12 23:10:13 +01:00
|
|
|
this.bT = flag;
|
|
|
|
this.bS = f;
|
2011-09-22 00:54:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2011-09-26 20:17:32 +02:00
|
|
|
int oldFoodLevel = entityhuman.getFoodData().foodLevel;
|
|
|
|
|
2012-01-14 21:03:48 +01:00
|
|
|
FoodLevelChangeEvent event = new FoodLevelChangeEvent(entityhuman.getBukkitEntity(), Math.min(this.getNutrition() + entityhuman.getFoodData().foodLevel, 20));
|
2011-09-22 00:54:31 +02:00
|
|
|
entityhuman.world.getServer().getPluginManager().callEvent(event);
|
|
|
|
|
|
|
|
if (!event.isCancelled()) {
|
2012-01-14 21:03:48 +01:00
|
|
|
entityhuman.getFoodData().eat(event.getFoodLevel() - oldFoodLevel, this.getSaturationModifier());
|
2011-09-22 00:54:31 +02:00
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
|
2012-01-12 23:10:13 +01:00
|
|
|
if (!world.isStatic && this.bV > 0 && world.random.nextFloat() < this.bY) {
|
|
|
|
entityhuman.addEffect(new MobEffect(this.bV, this.bW * 20, this.bX));
|
2011-09-22 00:54:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return itemstack;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int c(ItemStack itemstack) {
|
|
|
|
return 32;
|
|
|
|
}
|
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
public EnumAnimation d(ItemStack itemstack) {
|
2011-09-22 00:54:31 +02:00
|
|
|
return EnumAnimation.b;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ItemStack a(ItemStack itemstack, World world, EntityHuman entityhuman) {
|
2012-01-12 23:10:13 +01:00
|
|
|
if (entityhuman.b(this.bU)) {
|
2011-09-22 00:54:31 +02:00
|
|
|
entityhuman.a(itemstack, this.c(itemstack));
|
|
|
|
}
|
|
|
|
|
|
|
|
return itemstack;
|
|
|
|
}
|
|
|
|
|
2012-01-14 21:03:48 +01:00
|
|
|
public int getNutrition() {
|
2011-11-20 09:01:14 +01:00
|
|
|
return this.b;
|
2011-09-22 00:54:31 +02:00
|
|
|
}
|
|
|
|
|
2012-01-14 21:03:48 +01:00
|
|
|
public float getSaturationModifier() {
|
2012-01-12 23:10:13 +01:00
|
|
|
return this.bS;
|
2011-09-22 00:54:31 +02:00
|
|
|
}
|
|
|
|
|
2012-01-12 23:10:13 +01:00
|
|
|
public boolean q() {
|
|
|
|
return this.bT;
|
2011-09-22 00:54:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public ItemFood a(int i, int j, int k, float f) {
|
2012-01-12 23:10:13 +01:00
|
|
|
this.bV = i;
|
|
|
|
this.bW = j;
|
|
|
|
this.bX = k;
|
|
|
|
this.bY = f;
|
2011-09-22 00:54:31 +02:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2012-01-12 23:10:13 +01:00
|
|
|
public ItemFood r() {
|
|
|
|
this.bU = true;
|
2011-09-22 00:54:31 +02:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Item a(String s) {
|
|
|
|
return super.a(s);
|
|
|
|
}
|
|
|
|
}
|