Java Code Examples for net.minecraft.entity.player.EntityPlayer.getFoodStats()

The following are Jave code examples for showing how to use getFoodStats() of the net.minecraft.entity.player.EntityPlayer class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: ExPetrum   File: PlayerManager.java   View Source Code Vote up 6 votes
public static float getExhaustion(EntityPlayer of)
{
	FoodStats stats = of.getFoodStats();
	if (!foodExhaustionLevelFld.isAccessible())
	{
		foodExhaustionLevelFld.setAccessible(true);
	}
	
	try
	{
		return foodExhaustionLevelFld.getFloat(stats);
	}
	catch (Exception ex)
	{
		FMLCommonHandler.instance().raiseException(ex, "ExPetrum was unable to reflect player's FoodStats!", true);
		return -1;
	}
}
 
Example 2
Project: ExPetrum   File: PlayerManager.java   View Source Code Vote up 6 votes
@SuppressWarnings("SameParameterValue")
public static void setExhaustion(EntityPlayer of, float f)
{
	FoodStats stats = of.getFoodStats();
	if (!foodExhaustionLevelFld.isAccessible())
	{
		foodExhaustionLevelFld.setAccessible(true);
	}
	
	try
	{
		foodExhaustionLevelFld.setFloat(stats, f);
	}
	catch (Exception ex)
	{
		FMLCommonHandler.instance().raiseException(ex, "ExPetrum was unable to reflect player's FoodStats!", true);
	}
}
 
Example 3
Project: Bewitchment   File: ItemFilledBowl.java   View Source Code Vote up 5 votes
@Override
public void onFoodEaten(ItemStack stack, World worldIn, EntityPlayer player) {
	if (stack.getTagCompound() == null) {
		stack.setTagCompound(new NBTTagCompound()); //not really supposed to happen ingame since you only get the stews with NBT values assigned but it prevents crashing
	}
	final FoodStats foodStats = player.getFoodStats();
	foodStats.setFoodLevel(foodStats.getFoodLevel() + stack.getTagCompound().getInteger("hunger"));
	foodStats.setFoodSaturationLevel(foodStats.getFoodLevel() + stack.getTagCompound().getFloat("saturation"));
	player.addItemStackToInventory(new ItemStack(Items.BOWL, 1));
}