mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-17 19:15:32 +00:00
Implement ItemStack and LivingEntity sensitive method to get the FoodProperties for an Item (#8477)
This commit is contained in:
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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user