Implement ItemStack and LivingEntity sensitive method to get the FoodProperties for an Item (#8477)

This commit is contained in:
canitzp authored and GitHub committed 2022-04-13 10:45:08 -07:00
1 parent 7d79f0d581
commit eed24f017f
9 files changed
+136 -2

No files matched your search

@@ -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();
}
}
@@ -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<CompoundTag>
{
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);
}
}
+2 -1
View File
@@ -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.<init>(ILnet/minecraft/resources/ResourceLocation;Lnet/minecraft/world/item/Item$Properties;)V=|p_41110_,p_41111_,p_41112_
net/minecraft/world/item/HorseArmorItem.<init>(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.<init>(Ljava/util/function/Supplier;
net/minecraft/world/level/dimension/LevelStem.<init>(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.<init>([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
net/minecraft/world/level/storage/loot/LootPool.<init>([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