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

The following examples show how to use net.minecraft.item.Item#isFood() . 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 check out the related API usage on the sidebar.
Example 1
Source File: PlayerEntityMixin.java    From the-hallow with 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 File: AutoEatHack.java    From Wurst7 with 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;
}