net.minecraft.item.FoodComponent Java Examples

The following examples show how to use net.minecraft.item.FoodComponent. 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 6 votes vote down vote up
private boolean isAllowedFood(FoodComponent food)
{
	if(!allowChorus.isChecked() && food == FoodComponents.CHORUS_FRUIT)
		return false;
	
	for(Pair<StatusEffectInstance, Float> pair : food.getStatusEffects())
	{
		StatusEffect effect = pair.getFirst().getEffectType();
		
		if(!allowHunger.isChecked() && effect == StatusEffects.HUNGER)
			return false;
		
		if(!allowPoison.isChecked() && effect == StatusEffects.POISON)
			return false;
	}
	
	return true;
}
 
Example #3
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;
}
 
Example #4
Source File: CandyItem.java    From the-hallow with MIT License 4 votes vote down vote up
public CandyItem(Settings settings, int hunger, float saturation) {
	super(settings.food((new FoodComponent.Builder()).hunger(hunger).saturationModifier(saturation).build()));
}
 
Example #5
Source File: AutoEatHack.java    From Wurst7 with GNU General Public License v3.0 4 votes vote down vote up
private FoodPriority(String name, Comparator<FoodComponent> comparator)
{
	this.name = name;
	this.comparator = comparator;
}