diff --git a/patches/minecraft/net/minecraft/world/entity/LivingEntity.java.patch b/patches/minecraft/net/minecraft/world/entity/LivingEntity.java.patch index 8c74505495..5bb2b035d6 100644 --- a/patches/minecraft/net/minecraft/world/entity/LivingEntity.java.patch +++ b/patches/minecraft/net/minecraft/world/entity/LivingEntity.java.patch @@ -455,6 +455,15 @@ this.m_142106_(this.f_20935_); } else { this.m_5810_(); +@@ -2799,7 +_,7 @@ + + private boolean m_21332_() { + int i = this.m_21212_(); +- FoodProperties foodproperties = this.f_20935_.m_41720_().m_41473_(); ++ FoodProperties foodproperties = this.f_20935_.getFoodProperties(this); + boolean flag = foodproperties != null && foodproperties.m_38748_(); + flag |= i <= this.f_20935_.m_41779_() - 7; + return flag && i % 4 == 0; @@ -2829,8 +_,10 @@ public void m_6672_(InteractionHand p_21159_) { ItemStack itemstack = this.m_21120_(p_21159_); @@ -549,6 +558,15 @@ } public ItemStack m_5584_(Level p_21067_, ItemStack p_21068_) { +@@ -3160,7 +_,7 @@ + private void m_21063_(ItemStack p_21064_, Level p_21065_, LivingEntity p_21066_) { + Item item = p_21064_.m_41720_(); + if (item.m_41472_()) { +- for(Pair pair : item.m_41473_().m_38749_()) { ++ for(Pair pair : p_21064_.getFoodProperties(this).m_38749_()) { + if (!p_21065_.f_46443_ && pair.getFirst() != null && p_21065_.f_46441_.nextFloat() < pair.getSecond()) { + p_21066_.m_7292_(new MobEffectInstance(pair.getFirst())); + } @@ -3196,6 +_,64 @@ this.m_21166_(p_21191_ == InteractionHand.MAIN_HAND ? EquipmentSlot.MAINHAND : EquipmentSlot.OFFHAND); } diff --git a/patches/minecraft/net/minecraft/world/entity/animal/Cat.java.patch b/patches/minecraft/net/minecraft/world/entity/animal/Cat.java.patch index 097ec27358..88dde64765 100644 --- a/patches/minecraft/net/minecraft/world/entity/animal/Cat.java.patch +++ b/patches/minecraft/net/minecraft/world/entity/animal/Cat.java.patch @@ -1,5 +1,14 @@ --- a/net/minecraft/world/entity/animal/Cat.java +++ b/net/minecraft/world/entity/animal/Cat.java +@@ -400,7 +_,7 @@ + if (!(item instanceof DyeItem)) { + if (item.m_41472_() && this.m_6898_(itemstack) && this.m_21223_() < this.m_21233_()) { + this.m_142075_(p_28153_, p_28154_, itemstack); +- this.m_5634_((float)item.m_41473_().m_38744_()); ++ this.m_5634_((float)itemstack.getFoodProperties(this).m_38744_()); + return InteractionResult.CONSUME; + } + @@ -425,7 +_,7 @@ } } else if (this.m_6898_(itemstack)) { diff --git a/patches/minecraft/net/minecraft/world/entity/animal/Wolf.java.patch b/patches/minecraft/net/minecraft/world/entity/animal/Wolf.java.patch index 6c639d5883..4fcf6575db 100644 --- a/patches/minecraft/net/minecraft/world/entity/animal/Wolf.java.patch +++ b/patches/minecraft/net/minecraft/world/entity/animal/Wolf.java.patch @@ -1,5 +1,14 @@ --- a/net/minecraft/world/entity/animal/Wolf.java +++ b/net/minecraft/world/entity/animal/Wolf.java +@@ -329,7 +_,7 @@ + itemstack.m_41774_(1); + } + +- this.m_5634_((float)item.m_41473_().m_38744_()); ++ this.m_5634_((float)itemstack.getFoodProperties(this).m_38744_()); + this.m_146859_(GameEvent.f_157771_, this.m_146901_()); + return InteractionResult.SUCCESS; + } @@ -361,7 +_,7 @@ itemstack.m_41774_(1); } @@ -9,3 +18,12 @@ this.m_21828_(p_30412_); this.f_21344_.m_26573_(); this.m_6710_((LivingEntity)null); +@@ -401,7 +_,7 @@ + + public boolean m_6898_(ItemStack p_30440_) { + Item item = p_30440_.m_41720_(); +- return item.m_41472_() && item.m_41473_().m_38746_(); ++ return item.m_41472_() && p_30440_.getFoodProperties(this).m_38746_(); + } + + public int m_5792_() { diff --git a/patches/minecraft/net/minecraft/world/entity/player/Player.java.patch b/patches/minecraft/net/minecraft/world/entity/player/Player.java.patch index a1e7fbc437..ea6a6c3e2c 100644 --- a/patches/minecraft/net/minecraft/world/entity/player/Player.java.patch +++ b/patches/minecraft/net/minecraft/world/entity/player/Player.java.patch @@ -346,7 +346,7 @@ return this.m_36218_(mutablecomponent); } -@@ -1895,18 +_,18 @@ +@@ -1895,24 +_,24 @@ Predicate predicate = ((ProjectileWeaponItem)p_36349_.m_41720_()).m_6442_(); ItemStack itemstack = ProjectileWeaponItem.m_43010_(this, predicate); if (!itemstack.m_41619_()) { @@ -368,6 +368,13 @@ } } } + + public ItemStack m_5584_(Level p_36185_, ItemStack p_36186_) { +- this.m_36324_().m_38712_(p_36186_.m_41720_(), p_36186_); ++ this.m_36324_().eat(p_36186_.m_41720_(), p_36186_, this); + this.m_36246_(Stats.f_12982_.m_12902_(p_36186_.m_41720_())); + p_36185_.m_6263_((Player)null, this.m_20185_(), this.m_20186_(), this.m_20189_(), SoundEvents.f_12321_, SoundSource.PLAYERS, 0.5F, p_36185_.f_46441_.nextFloat() * 0.1F + 0.9F); + if (this instanceof ServerPlayer) { @@ -1991,5 +_,63 @@ public Component m_36423_() { return this.f_36413_; diff --git a/patches/minecraft/net/minecraft/world/food/FoodData.java.patch b/patches/minecraft/net/minecraft/world/food/FoodData.java.patch new file mode 100644 index 0000000000..0274fc1003 --- /dev/null +++ b/patches/minecraft/net/minecraft/world/food/FoodData.java.patch @@ -0,0 +1,19 @@ +--- a/net/minecraft/world/food/FoodData.java ++++ b/net/minecraft/world/food/FoodData.java +@@ -24,9 +_,15 @@ + this.f_38697_ = Math.min(this.f_38697_ + (float)p_38708_ * p_38709_ * 2.0F, (float)this.f_38696_); + } + ++ // Use the LivingEntity sensitive version in favour of this. ++ @Deprecated + public void m_38712_(Item p_38713_, ItemStack p_38714_) { ++ this.eat(p_38713_, p_38714_, null); ++ } ++ ++ public void eat(Item p_38713_, ItemStack p_38714_, @javax.annotation.Nullable net.minecraft.world.entity.LivingEntity entity) { + if (p_38713_.m_41472_()) { +- FoodProperties foodproperties = p_38713_.m_41473_(); ++ FoodProperties foodproperties = p_38714_.getFoodProperties(entity); + this.m_38707_(foodproperties.m_38744_(), foodproperties.m_38745_()); + } + diff --git a/patches/minecraft/net/minecraft/world/item/Item.java.patch b/patches/minecraft/net/minecraft/world/item/Item.java.patch index 332ef1cf6a..1960b67449 100644 --- a/patches/minecraft/net/minecraft/world/item/Item.java.patch +++ b/patches/minecraft/net/minecraft/world/item/Item.java.patch @@ -31,6 +31,15 @@ public void m_5929_(Level p_41428_, LivingEntity p_41429_, ItemStack p_41430_, int p_41431_) { } +@@ -134,7 +_,7 @@ + public InteractionResultHolder m_7203_(Level p_41432_, Player p_41433_, InteractionHand p_41434_) { + if (this.m_41472_()) { + ItemStack itemstack = p_41433_.m_21120_(p_41434_); +- if (p_41433_.m_36391_(this.m_41473_().m_38747_())) { ++ if (p_41433_.m_36391_(itemstack.getFoodProperties(p_41433_).m_38747_())) { + p_41433_.m_6672_(p_41434_); + return InteractionResultHolder.m_19096_(itemstack); + } else { @@ -149,10 +_,12 @@ return this.m_41472_() ? p_41411_.m_5584_(p_41410_, p_41409_) : p_41409_; } @@ -72,6 +81,15 @@ public boolean m_41470_() { return this.f_41378_ != null; } +@@ -251,7 +_,7 @@ + + public int m_8105_(ItemStack p_41454_) { + if (p_41454_.m_41720_().m_41472_()) { +- return this.m_41473_().m_38748_() ? 16 : 32; ++ return p_41454_.getFoodProperties(null).m_38748_() ? 16 : 32; + } else { + return 0; + } @@ -293,7 +_,7 @@ } @@ -122,6 +140,15 @@ } public ItemStack m_7968_() { +@@ -352,6 +_,8 @@ + return this.f_41380_ != null; + } + ++ // Use IForgeItem#getFoodProperties(ItemStack, LivingEntity) in favour of this. ++ @Deprecated + @Nullable + public FoodProperties m_41473_() { + return this.f_41380_; @@ -382,6 +_,32 @@ return true; } diff --git a/src/main/java/net/minecraftforge/common/extensions/IForgeItem.java b/src/main/java/net/minecraftforge/common/extensions/IForgeItem.java index 2887955a7d..cd5b50ec24 100644 --- a/src/main/java/net/minecraftforge/common/extensions/IForgeItem.java +++ b/src/main/java/net/minecraftforge/common/extensions/IForgeItem.java @@ -16,6 +16,7 @@ import javax.annotation.Nullable; import com.google.common.collect.Multimap; import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.food.FoodProperties; import net.minecraft.world.item.*; import net.minecraft.world.item.enchantment.Enchantment; import net.minecraft.world.level.block.state.BlockState; @@ -782,4 +783,21 @@ public interface IForgeItem return 0; } + /** + * Get the food properties for this item. + * Use this instead of the {@link Item#getFoodProperties()} method, for ItemStack sensitivity. + * + * The @Nullable annotation was only added, due to the default method, also being @Nullable. + * Use this with a grain of salt, as if you return null here and true at {@link Item#isEdible()}, NPEs will occur! + * + * @param stack The ItemStack the entity wants to eat. + * @param entity The entity which wants to eat the food. Be aware that this can be null! + * @return The current FoodProperties for the item. + */ + @Nullable // read javadoc to find a potential problem + default FoodProperties getFoodProperties(ItemStack stack, @Nullable LivingEntity entity) + { + return self().getFoodProperties(); + } + } diff --git a/src/main/java/net/minecraftforge/common/extensions/IForgeItemStack.java b/src/main/java/net/minecraftforge/common/extensions/IForgeItemStack.java index ccf2154fee..67806dfe09 100644 --- a/src/main/java/net/minecraftforge/common/extensions/IForgeItemStack.java +++ b/src/main/java/net/minecraftforge/common/extensions/IForgeItemStack.java @@ -11,6 +11,7 @@ import javax.annotation.Nullable; import net.minecraft.core.Registry; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.monster.EnderMan; +import net.minecraft.world.food.FoodProperties; import net.minecraft.world.item.crafting.RecipeType; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.pattern.BlockInWorld; @@ -506,4 +507,20 @@ public interface IForgeItemStack extends ICapabilitySerializable { self().getItem().onDestroyed(itemEntity, damageSource); } + + /** + * Get the food properties for this item. + * This is a bouncer for easier use of {@link IForgeItem#getFoodProperties(ItemStack, LivingEntity)} + * + * The @Nullable annotation was only added, due to the default method, also being @Nullable. + * Use this with a grain of salt, as if you return null here and true at {@link Item#isEdible()}, NPEs will occur! + * + * @param entity The entity which wants to eat the food. Be aware that this can be null! + * @return The current FoodProperties for the item. + */ + @Nullable // read javadoc to find a potential problem + default FoodProperties getFoodProperties(@Nullable LivingEntity entity) + { + return self().getItem().getFoodProperties(self(), entity); + } } diff --git a/src/main/resources/forge.exc b/src/main/resources/forge.exc index 72ee0ff9dd..1779550217 100644 --- a/src/main/resources/forge.exc +++ b/src/main/resources/forge.exc @@ -39,6 +39,7 @@ net/minecraft/world/entity/item/ItemEntity.changeDimension(Lnet/minecraft/server net/minecraft/world/entity/npc/AbstractVillager.changeDimension(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraftforge/common/util/ITeleporter;)Lnet/minecraft/world/entity/Entity;=|p_35295_,teleporter net/minecraft/world/entity/player/Player.getDigSpeed(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/core/BlockPos;)F=|p_36282_,pos net/minecraft/world/entity/projectile/ThrownEnderpearl.changeDimension(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraftforge/common/util/ITeleporter;)Lnet/minecraft/world/entity/Entity;=|p_37506_,teleporter +net/minecraft/world/food/FoodData.eat(Lnet/minecraft/world/item/Item;Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/entity/LivingEntity;)V=|p_38713_,p_38714_,entity net/minecraft/world/item/BoneMealItem.applyBonemeal(Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/entity/player/Player;)Z=|p_40628_,p_40629_,p_40630_,player net/minecraft/world/item/DyeableHorseArmorItem.(ILnet/minecraft/resources/ResourceLocation;Lnet/minecraft/world/item/Item$Properties;)V=|p_41110_,p_41111_,p_41112_ net/minecraft/world/item/HorseArmorItem.(ILnet/minecraft/resources/ResourceLocation;Lnet/minecraft/world/item/Item$Properties;)V=|p_41364_,p_41365_,p_41366_ @@ -57,4 +58,4 @@ net/minecraft/world/level/block/LiquidBlock.(Ljava/util/function/Supplier; net/minecraft/world/level/dimension/LevelStem.(Lnet/minecraft/core/Holder;Lnet/minecraft/world/level/chunk/ChunkGenerator;Z)V=|p_204519_,p_204520_,useServerSeed net/minecraft/world/level/entity/PersistentEntitySectionManager.addEntityWithoutEvent(Lnet/minecraft/world/level/entity/EntityAccess;Z)Z=|p_157539_,p_157540_ net/minecraft/world/level/levelgen/structure/templatesystem/StructureTemplate.processEntityInfos(Lnet/minecraft/world/level/levelgen/structure/templatesystem/StructureTemplate;Lnet/minecraft/world/level/LevelAccessor;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/levelgen/structure/templatesystem/StructurePlaceSettings;Ljava/util/List;)Ljava/util/List;=|template,p_215387_0_,p_215387_1_,p_215387_2_,p_215387_3_ -net/minecraft/world/level/storage/loot/LootPool.([Lnet/minecraft/world/level/storage/loot/entries/LootPoolEntryContainer;[Lnet/minecraft/world/level/storage/loot/predicates/LootItemCondition;[Lnet/minecraft/world/level/storage/loot/functions/LootItemFunction;Lnet/minecraft/world/level/storage/loot/providers/number/NumberProvider;Lnet/minecraft/world/level/storage/loot/providers/number/NumberProvider;Ljava/lang/String;)V=|p_165128_,p_165129_,p_165130_,p_165131_,p_165132_,name \ No newline at end of file +net/minecraft/world/level/storage/loot/LootPool.([Lnet/minecraft/world/level/storage/loot/entries/LootPoolEntryContainer;[Lnet/minecraft/world/level/storage/loot/predicates/LootItemCondition;[Lnet/minecraft/world/level/storage/loot/functions/LootItemFunction;Lnet/minecraft/world/level/storage/loot/providers/number/NumberProvider;Lnet/minecraft/world/level/storage/loot/providers/number/NumberProvider;Ljava/lang/String;)V=|p_165128_,p_165129_,p_165130_,p_165131_,p_165132_,name