mirror of
https://github.com/barkeser2002/CatServer.git
synced 2026-09-25 01:39:52 +03:00
116 lines
4.5 KiB
Diff
116 lines
4.5 KiB
Diff
--- ../src-base/minecraft/net/minecraft/util/FoodStats.java
|
|
+++ ../src-work/minecraft/net/minecraft/util/FoodStats.java
|
|
@@ -1,21 +1,45 @@
|
|
package net.minecraft.util;
|
|
|
|
+import net.minecraft.entity.EntityLivingBase;
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
+import net.minecraft.entity.player.EntityPlayerMP;
|
|
import net.minecraft.item.ItemFood;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
+import net.minecraft.network.play.server.SPacketUpdateHealth;
|
|
import net.minecraft.world.EnumDifficulty;
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
|
|
|
+import java.lang.reflect.Field;
|
|
+
|
|
public class FoodStats
|
|
{
|
|
- private int foodLevel = 20;
|
|
- private float foodSaturationLevel = 5.0F;
|
|
- private float foodExhaustionLevel;
|
|
- private int foodTimer;
|
|
- private int prevFoodLevel = 20;
|
|
+ public int foodLevel = 20;
|
|
+ public float foodSaturationLevel = 5.0F;
|
|
+ public float foodExhaustionLevel;
|
|
+ public int foodTimer;
|
|
+ public int prevFoodLevel = 20;
|
|
|
|
+ private EntityPlayer entityhuman;
|
|
+
|
|
+ public FoodStats() {
|
|
+ }
|
|
+
|
|
+ public FoodStats(EntityLivingBase entityhuman) {
|
|
+ setPlayer((EntityPlayer) entityhuman);
|
|
+ }
|
|
+
|
|
+ public FoodStats setPlayer(EntityPlayer entityhuman) {
|
|
+ org.apache.commons.lang3.Validate.notNull(entityhuman);
|
|
+ this.entityhuman = entityhuman;
|
|
+ try {
|
|
+ Field appaleCore = getClass().getField("entityplayer");
|
|
+ appaleCore.set(this, entityhuman);
|
|
+ } catch (ReflectiveOperationException ignored) {}
|
|
+ return this;
|
|
+ }
|
|
+
|
|
public void addStats(int foodLevelIn, float foodSaturationModifier)
|
|
{
|
|
this.foodLevel = Math.min(foodLevelIn + this.foodLevel, 20);
|
|
@@ -24,7 +48,20 @@
|
|
|
|
public void addStats(ItemFood foodItem, ItemStack stack)
|
|
{
|
|
- this.addStats(foodItem.getHealAmount(stack), foodItem.getSaturationModifier(stack));
|
|
+ if (entityhuman == null) // CatServer - allow mods use FoodStats
|
|
+ {
|
|
+ this.addStats(foodItem.getHealAmount(stack), foodItem.getSaturationModifier(stack));
|
|
+ } else {
|
|
+ int oldFoodLevel = foodLevel;
|
|
+
|
|
+ org.bukkit.event.entity.FoodLevelChangeEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callFoodLevelChangeEvent(entityhuman, foodItem.getHealAmount(stack) + oldFoodLevel);
|
|
+
|
|
+ if (!event.isCancelled()) {
|
|
+ this.addStats(event.getFoodLevel() - oldFoodLevel, foodItem.getSaturationModifier(stack));
|
|
+ }
|
|
+
|
|
+ ((EntityPlayerMP) entityhuman).getBukkitEntity().sendHealthUpdate();
|
|
+ }
|
|
}
|
|
|
|
public void onUpdate(EntityPlayer player)
|
|
@@ -42,7 +79,18 @@
|
|
}
|
|
else if (enumdifficulty != EnumDifficulty.PEACEFUL)
|
|
{
|
|
- this.foodLevel = Math.max(this.foodLevel - 1, 0);
|
|
+ if (entityhuman == null) // CatServer - allow mods use FoodStats
|
|
+ {
|
|
+ this.foodLevel = Math.max(this.foodLevel - 1, 0);
|
|
+ } else {
|
|
+ org.bukkit.event.entity.FoodLevelChangeEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callFoodLevelChangeEvent(entityhuman, Math.max(this.foodLevel - 1, 0));
|
|
+
|
|
+ if (!event.isCancelled()) {
|
|
+ this.foodLevel = event.getFoodLevel();
|
|
+ }
|
|
+
|
|
+ ((EntityPlayerMP) entityhuman).connection.sendPacket(new SPacketUpdateHealth(((EntityPlayerMP) entityhuman).getBukkitEntity().getScaledHealth(), this.foodLevel, this.foodSaturationLevel));
|
|
+ }
|
|
}
|
|
}
|
|
|
|
@@ -55,7 +103,7 @@
|
|
if (this.foodTimer >= 10)
|
|
{
|
|
float f = Math.min(this.foodSaturationLevel, 6.0F);
|
|
- player.heal(f / 6.0F);
|
|
+ player.heal(f / 6.0F, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.SATIATED);
|
|
this.addExhaustion(f);
|
|
this.foodTimer = 0;
|
|
}
|
|
@@ -66,8 +114,8 @@
|
|
|
|
if (this.foodTimer >= 80)
|
|
{
|
|
- player.heal(1.0F);
|
|
- this.addExhaustion(6.0F);
|
|
+ player.heal(1.0F, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.SATIATED);
|
|
+ this.addExhaustion(entityhuman == null ? 6.0F : entityhuman.world.spigotConfig.regenExhaustion); // Spigot - Change to use configurable value
|
|
this.foodTimer = 0;
|
|
}
|
|
}
|