3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-20 13:30:05 +01:00
Paper/src/main/java/net/minecraft/server/ItemFood.java
Travis Watkins af89cc783f Don't cap food level at 20 when eating. Fixes BUKKIT-1667
The amount of food gained when eating is used for calculating the food
saturation value so capping it at 20 at this point causes us to get
incorrect results. FoodMetaData.eat caps it at 20 anyway so we're safe to
not do so here.

Also readds a line from mc-dev that was mistakenly removed.
2012-05-17 21:17:23 -05:00

92 Zeilen
2.2 KiB
Java

package net.minecraft.server;
public class ItemFood extends Item {
public final int a;
private final int b;
private final float bU;
private final boolean bV;
private boolean bW;
private int bX;
private int bY;
private int bZ;
private float ca;
public ItemFood(int i, int j, float f, boolean flag) {
super(i);
this.a = 32;
this.b = 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
int oldFoodLevel = entityhuman.getFoodData().foodLevel;
org.bukkit.event.entity.FoodLevelChangeEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callFoodLevelChangeEvent(entityhuman, this.getNutrition() + oldFoodLevel);
if (!event.isCancelled()) {
entityhuman.getFoodData().eat(event.getFoodLevel() - oldFoodLevel, this.getSaturationModifier());
}
// CraftBukkit end
world.makeSound(entityhuman, "random.burp", 0.5F, world.random.nextFloat() * 0.1F + 0.9F);
if (!world.isStatic && this.bX > 0 && world.random.nextFloat() < this.ca) {
entityhuman.addEffect(new MobEffect(this.bX, this.bY * 20, this.bZ));
}
return itemstack;
}
public int c(ItemStack itemstack) {
return 32;
}
public EnumAnimation d(ItemStack itemstack) {
return EnumAnimation.b;
}
public ItemStack a(ItemStack itemstack, World world, EntityHuman entityhuman) {
if (entityhuman.b(this.bW)) {
entityhuman.a(itemstack, this.c(itemstack));
}
return itemstack;
}
public int getNutrition() {
return this.b;
}
public float getSaturationModifier() {
return this.bU;
}
public boolean q() {
return this.bV;
}
public ItemFood a(int i, int j, int k, float f) {
this.bX = i;
this.bY = j;
this.bZ = k;
this.ca = f;
return this;
}
public ItemFood r() {
this.bW = true;
return this;
}
public Item a(String s) {
return super.a(s);
}
}