Java Code Examples for net.minecraft.item.Item#isFood()

The following examples show how to use net.minecraft.item.Item#isFood() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: the-hallow   File: PlayerEntityMixin.java    License: MIT License 6 votes vote down vote up
@Inject(at = @At(
	value = "INVOKE",
	target = "Lnet/minecraft/entity/player/HungerManager;eat(Lnet/minecraft/item/Item;Lnet/minecraft/item/ItemStack;)V",
	shift = At.Shift.AFTER
), method = "eatFood(Lnet/minecraft/world/World;Lnet/minecraft/item/ItemStack;)Lnet/minecraft/item/ItemStack;")
private void addPumpkinRingBonus(World world, ItemStack itemStack, CallbackInfoReturnable<ItemStack> info) {
	PlayerEntity playerEntity = (PlayerEntity) (Object) this;
	TrinketComponent trinketPlayer = TrinketsApi.getTrinketComponent(playerEntity);
	
	ItemStack mainHandStack = trinketPlayer.getStack("hand:ring");
	ItemStack offHandStack = trinketPlayer.getStack("offhand:ring");
	Item item = itemStack.getItem();
	
	if (mainHandStack.getItem().equals(HallowedItems.PUMPKIN_RING) || offHandStack.getItem().equals(HallowedItems.PUMPKIN_RING)) {
		if (item.isFood()) {
			if (item.isIn(HallowedTags.Items.PUMPKIN_FOODS)) {
				FoodComponent foodComponent = item.getFoodComponent();
				int extraHunger = (int) Math.ceil(foodComponent.getHunger() * .25);
				this.hungerManager.add(extraHunger, 1);
			}
		}
	}
}
 
Example 2
Source Project: Wurst7   File: AutoEatHack.java    License: GNU General Public License v3.0 5 votes vote down vote up
private int getBestSlot()
{
	int bestSlot = -1;
	FoodComponent bestFood = null;
	Comparator<FoodComponent> comparator =
		foodPriority.getSelected().comparator;
	
	for(int i = 0; i < 9; i++)
	{
		// filter out non-food items
		Item item = MC.player.inventory.getStack(i).getItem();
		if(!item.isFood())
			continue;
		
		FoodComponent food = item.getFoodComponent();
		if(!isAllowedFood(food))
			continue;
		
		// compare to previously found food
		if(bestFood == null || comparator.compare(food, bestFood) > 0)
		{
			bestFood = food;
			bestSlot = i;
		}
	}
	
	return bestSlot;
}