|
1 | 1 | --- a/net/minecraft/world/food/FoodData.java |
2 | 2 | +++ b/net/minecraft/world/food/FoodData.java |
3 | | -@@ -5,17 +_,31 @@ |
| 3 | +@@ -1,10 +_,14 @@ |
| 4 | + package net.minecraft.world.food; |
| 5 | + |
| 6 | + import net.minecraft.nbt.CompoundTag; |
| 7 | ++import net.minecraft.network.protocol.game.ClientboundSetHealthPacket; |
| 8 | ++import net.minecraft.server.level.ServerPlayer; |
| 9 | + import net.minecraft.util.Mth; |
4 | 10 | import net.minecraft.world.Difficulty; |
5 | 11 | import net.minecraft.world.entity.player.Player; |
| 12 | ++import net.minecraft.world.item.ItemStack; |
6 | 13 | import net.minecraft.world.level.GameRules; |
7 | | -+import org.taiyitistmc.injection.world.food.InjectionFoodData; |
| 14 | ++import org.bukkit.craftbukkit.event.CraftEventFactory; |
8 | 15 |
|
9 | | --public class FoodData { |
10 | | -+public class FoodData implements InjectionFoodData { |
| 16 | + public class FoodData { |
11 | 17 | public int foodLevel = 20; |
12 | | - public float saturationLevel; |
13 | | - public float exhaustionLevel; |
| 18 | +@@ -13,10 +_,22 @@ |
14 | 19 | private int tickTimer; |
15 | 20 | private int lastFoodLevel = 20; |
| 21 | + |
16 | 22 | + // CraftBukkit start |
17 | | -+ private Player entityhuman; |
| 23 | ++ public Player entityhuman = null; |
18 | 24 | + public int saturatedRegenRate = 10; |
19 | 25 | + public int unsaturatedRegenRate = 80; |
20 | 26 | + public int starvationRate = 80; |
21 | 27 | + // CraftBukkit end |
22 | | - |
| 28 | ++ |
23 | 29 | public FoodData() { |
24 | 30 | this.saturationLevel = 5.0F; |
25 | 31 | } |
| 32 | + |
| 33 | ++ public FoodData player(Player player) { |
| 34 | ++ this.entityhuman = player; |
| 35 | ++ return this; |
| 36 | ++ } |
| 37 | ++ |
| 38 | + private void add(int p_340988_, float p_340961_) { |
| 39 | + this.foodLevel = Mth.clamp(p_340988_ + this.foodLevel, 0, 20); |
| 40 | + this.saturationLevel = Mth.clamp(p_340961_ + this.saturationLevel, 0.0F, (float)this.foodLevel); |
| 41 | +@@ -30,37 +_,65 @@ |
| 42 | + this.add(p_347533_.nutrition(), p_347533_.saturation()); |
| 43 | + } |
| 44 | + |
| 45 | ++ // CraftBukkit start |
| 46 | ++ public void eat(ItemStack itemstack, FoodProperties foodinfo) { |
| 47 | ++ int oldFoodLevel = this.foodLevel; |
| 48 | ++ |
| 49 | ++ org.bukkit.event.entity.FoodLevelChangeEvent event = CraftEventFactory.callFoodLevelChangeEvent(this.entityhuman, foodinfo.nutrition() + oldFoodLevel, itemstack); |
26 | 50 | + |
27 | | -+ // CraftBukkit start - added EntityHuman constructor |
28 | | -+ public FoodData(Player entityhuman) { |
29 | | -+ org.apache.commons.lang3.Validate.notNull(entityhuman); |
30 | | -+ this.entityhuman = entityhuman; |
| 51 | ++ if (!event.isCancelled()) { |
| 52 | ++ this.add(event.getFoodLevel() - oldFoodLevel, foodinfo.saturation()); |
| 53 | ++ } |
| 54 | ++ |
| 55 | ++ ((ServerPlayer) this.entityhuman).getBukkitEntity().sendHealthUpdate(); |
31 | 56 | + } |
32 | 57 | + // CraftBukkit end |
| 58 | ++ |
| 59 | ++ |
| 60 | + public void tick(Player p_38711_) { |
| 61 | + Difficulty difficulty = p_38711_.level().getDifficulty(); |
| 62 | ++ if (entityhuman == null) entityhuman = p_38711_; |
| 63 | + this.lastFoodLevel = this.foodLevel; |
| 64 | + if (this.exhaustionLevel > 4.0F) { |
| 65 | + this.exhaustionLevel -= 4.0F; |
| 66 | + if (this.saturationLevel > 0.0F) { |
| 67 | + this.saturationLevel = Math.max(this.saturationLevel - 1.0F, 0.0F); |
| 68 | + } else if (difficulty != Difficulty.PEACEFUL) { |
| 69 | +- this.foodLevel = Math.max(this.foodLevel - 1, 0); |
| 70 | ++ // CraftBukkit start |
| 71 | ++ org.bukkit.event.entity.FoodLevelChangeEvent event = CraftEventFactory.callFoodLevelChangeEvent(p_38711_, Math.max(this.foodLevel - 1, 0)); |
| 72 | ++ |
| 73 | ++ if (!event.isCancelled()) { |
| 74 | ++ this.foodLevel = event.getFoodLevel(); |
| 75 | ++ } |
| 76 | ++ |
| 77 | ++ ((ServerPlayer) p_38711_).connection.send(new ClientboundSetHealthPacket(((ServerPlayer) p_38711_).getBukkitEntity().getScaledHealth(), this.foodLevel, this.saturationLevel)); |
| 78 | ++ // CraftBukkit end |
| 79 | + } |
| 80 | + } |
33 | 81 |
|
34 | | - private void add(int p_340988_, float p_340961_) { |
35 | | - this.foodLevel = Mth.clamp(p_340988_ + this.foodLevel, 0, 20); |
| 82 | + boolean flag = p_38711_.level().getGameRules().getBoolean(GameRules.RULE_NATURAL_REGENERATION); |
| 83 | + if (flag && this.saturationLevel > 0.0F && p_38711_.isHurt() && this.foodLevel >= 20) { |
| 84 | + this.tickTimer++; |
| 85 | +- if (this.tickTimer >= 10) { |
| 86 | ++ if (this.tickTimer >= this.saturatedRegenRate) { // CraftBukkit |
| 87 | + float f = Math.min(this.saturationLevel, 6.0F); |
| 88 | ++ p_38711_.pushHealReason(org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.SATIATED); |
| 89 | + p_38711_.heal(f / 6.0F); |
| 90 | ++ p_38711_.pushExhaustReason(org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.REGEN); // CraftBukkit - EntityExhaustionEvent |
| 91 | + this.addExhaustion(f); |
| 92 | + this.tickTimer = 0; |
| 93 | + } |
| 94 | + } else if (flag && this.foodLevel >= 18 && p_38711_.isHurt()) { |
| 95 | + this.tickTimer++; |
| 96 | +- if (this.tickTimer >= 80) { |
| 97 | ++ if (this.tickTimer >= this.unsaturatedRegenRate) { // CraftBukkit - add regen rate manipulation |
| 98 | ++ p_38711_.pushHealReason(org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.SATIATED); |
| 99 | + p_38711_.heal(1.0F); |
| 100 | ++ p_38711_.pushExhaustReason(org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.REGEN); // CraftBukkit - EntityExhaustionEvent |
| 101 | + this.addExhaustion(6.0F); |
| 102 | + this.tickTimer = 0; |
| 103 | + } |
| 104 | + } else if (this.foodLevel <= 0) { |
| 105 | + this.tickTimer++; |
| 106 | +- if (this.tickTimer >= 80) { |
| 107 | ++ if (this.tickTimer >= this.starvationRate) { // CraftBukkit - add regen rate manipulation |
| 108 | + if (p_38711_.getHealth() > 10.0F || difficulty == Difficulty.HARD || p_38711_.getHealth() > 1.0F && difficulty == Difficulty.NORMAL) { |
| 109 | + p_38711_.hurt(p_38711_.damageSources().starve(), 1.0F); |
| 110 | + } |
0 commit comments