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

94 Zeilen
2.5 KiB
Java

2011-09-22 00:54:31 +02:00
package net.minecraft.server;
public class ItemFood extends Item {
public final int a;
2011-11-20 09:01:14 +01:00
private final int b;
2012-07-29 09:33:13 +02:00
private final float c;
private final boolean ck;
private boolean cl;
private int cm;
private int cn;
private int co;
private float cp;
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;
this.ck = flag;
2012-07-29 09:33:13 +02:00
this.c = f;
this.a(CreativeModeTab.h);
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
int oldFoodLevel = entityhuman.getFoodData().foodLevel;
org.bukkit.event.entity.FoodLevelChangeEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callFoodLevelChangeEvent(entityhuman, this.getNutrition() + oldFoodLevel);
2011-09-22 00:54:31 +02:00
if (!event.isCancelled()) {
entityhuman.getFoodData().eat(event.getFoodLevel() - oldFoodLevel, this.getSaturationModifier());
2011-09-22 00:54:31 +02:00
}
((EntityPlayer) entityhuman).netServerHandler.sendPacket(new Packet8UpdateHealth(entityhuman.getHealth(), entityhuman.getFoodData().foodLevel, entityhuman.getFoodData().saturationLevel));
2011-09-22 00:54:31 +02:00
// CraftBukkit end
world.makeSound(entityhuman, "random.burp", 0.5F, world.random.nextFloat() * 0.1F + 0.9F);
2012-07-29 09:33:13 +02:00
this.c(itemstack, world, entityhuman);
2011-09-22 00:54:31 +02:00
return itemstack;
}
2012-07-29 09:33:13 +02:00
protected void c(ItemStack itemstack, World world, EntityHuman entityhuman) {
if (!world.isStatic && this.cm > 0 && world.random.nextFloat() < this.cp) {
entityhuman.addEffect(new MobEffect(this.cm, this.cn * 20, this.co));
2012-07-29 09:33:13 +02:00
}
}
public int a(ItemStack itemstack) {
2011-09-22 00:54:31 +02:00
return 32;
}
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) {
if (entityhuman.f(this.cl)) {
2012-07-29 09:33:13 +02:00
entityhuman.a(itemstack, this.a(itemstack));
2011-09-22 00:54:31 +02:00
}
return itemstack;
}
public int getNutrition() {
2011-11-20 09:01:14 +01:00
return this.b;
2011-09-22 00:54:31 +02:00
}
public float getSaturationModifier() {
2012-07-29 09:33:13 +02:00
return this.c;
2011-09-22 00:54:31 +02:00
}
public boolean i() {
return this.ck;
2011-09-22 00:54:31 +02:00
}
public ItemFood a(int i, int j, int k, float f) {
this.cm = i;
this.cn = j;
this.co = k;
this.cp = f;
2011-09-22 00:54:31 +02:00
return this;
}
public ItemFood j() {
this.cl = true;
2011-09-22 00:54:31 +02:00
return this;
}
}