craftbukkit/src/main/java/net/minecraft/server/ItemFood.java

95 lines
2.6 KiB
Java
Raw Normal View History

2011-09-21 18:54:31 -04:00
package net.minecraft.server;
public class ItemFood extends Item {
public final int a;
2011-11-20 00:01:14 -08:00
private final int b;
2012-07-29 02:33:13 -05:00
private final float c;
2013-03-13 17:33:27 -05:00
private final boolean d;
2013-07-01 06:03:00 -05:00
private boolean cB;
private int cC;
private int cD;
private int cE;
private float cF;
2011-09-21 18:54:31 -04:00
public ItemFood(int i, int j, float f, boolean flag) {
super(i);
this.a = 32;
2011-11-20 00:01:14 -08:00
this.b = j;
2013-03-13 17:33:27 -05:00
this.d = flag;
2012-07-29 02:33:13 -05:00
this.c = f;
this.a(CreativeModeTab.h);
2011-09-21 18:54:31 -04: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
int oldFoodLevel = entityhuman.getFoodData().foodLevel;
org.bukkit.event.entity.FoodLevelChangeEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callFoodLevelChangeEvent(entityhuman, this.getNutrition() + oldFoodLevel);
2011-09-21 18:54:31 -04:00
if (!event.isCancelled()) {
entityhuman.getFoodData().eat(event.getFoodLevel() - oldFoodLevel, this.getSaturationModifier());
2011-09-21 18:54:31 -04:00
}
2012-12-19 22:03:52 -06:00
((EntityPlayer) entityhuman).playerConnection.sendPacket(new Packet8UpdateHealth(entityhuman.getHealth(), entityhuman.getFoodData().foodLevel, entityhuman.getFoodData().saturationLevel));
2011-09-21 18:54:31 -04:00
// CraftBukkit end
2013-07-01 06:03:00 -05:00
entityhuman.getFoodData().a(this);
world.makeSound(entityhuman, "random.burp", 0.5F, world.random.nextFloat() * 0.1F + 0.9F);
2012-07-29 02:33:13 -05:00
this.c(itemstack, world, entityhuman);
2011-09-21 18:54:31 -04:00
return itemstack;
}
2012-07-29 02:33:13 -05:00
protected void c(ItemStack itemstack, World world, EntityHuman entityhuman) {
2013-07-01 06:03:00 -05:00
if (!world.isStatic && this.cC > 0 && world.random.nextFloat() < this.cF) {
entityhuman.addEffect(new MobEffect(this.cC, this.cD * 20, this.cE));
2012-07-29 02:33:13 -05:00
}
}
2013-07-01 06:03:00 -05:00
public int d_(ItemStack itemstack) {
2011-09-21 18:54:31 -04:00
return 32;
}
2013-07-01 06:03:00 -05:00
public EnumAnimation c_(ItemStack itemstack) {
2013-03-13 17:33:27 -05:00
return EnumAnimation.EAT;
2011-09-21 18:54:31 -04:00
}
public ItemStack a(ItemStack itemstack, World world, EntityHuman entityhuman) {
2013-07-01 06:03:00 -05:00
if (entityhuman.g(this.cB)) {
entityhuman.a(itemstack, this.d_(itemstack));
2011-09-21 18:54:31 -04:00
}
return itemstack;
}
public int getNutrition() {
2011-11-20 00:01:14 -08:00
return this.b;
2011-09-21 18:54:31 -04:00
}
public float getSaturationModifier() {
2012-07-29 02:33:13 -05:00
return this.c;
2011-09-21 18:54:31 -04:00
}
2013-07-01 06:03:00 -05:00
public boolean j() {
2013-03-13 17:33:27 -05:00
return this.d;
2011-09-21 18:54:31 -04:00
}
public ItemFood a(int i, int j, int k, float f) {
2013-07-01 06:03:00 -05:00
this.cC = i;
this.cD = j;
this.cE = k;
this.cF = f;
2011-09-21 18:54:31 -04:00
return this;
}
2013-07-01 06:03:00 -05:00
public ItemFood k() {
this.cB = true;
2011-09-21 18:54:31 -04:00
return this;
}
}