use of net.minecraft.util.FoodStats in project ForestryMC by ForestryMC.
the class ItemFluidContainerForestry method onItemUseFinish.
/**
* DRINKS
*/
@Override
public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityLivingBase entityLiving) {
DrinkProperties drinkProperties = getDrinkProperties(stack);
if (drinkProperties != null) {
if (entityLiving instanceof EntityPlayer && !((EntityPlayer) entityLiving).capabilities.isCreativeMode) {
EntityPlayer player = (EntityPlayer) entityLiving;
if (!player.capabilities.isCreativeMode) {
stack.shrink(1);
}
if (!worldIn.isRemote) {
FoodStats foodStats = player.getFoodStats();
foodStats.addStats(drinkProperties.getHealAmount(), drinkProperties.getSaturationModifier());
worldIn.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_PLAYER_BURP, SoundCategory.PLAYERS, 0.5F, worldIn.rand.nextFloat() * 0.1F + 0.9F);
}
player.addStat(StatList.getObjectUseStats(this));
}
}
return stack;
}
use of net.minecraft.util.FoodStats in project BloodMagic by WayofTime.
the class RitualFullStomach method performRitual.
@Override
public void performRitual(IMasterRitualStone masterRitualStone) {
World world = masterRitualStone.getWorldObj();
int currentEssence = masterRitualStone.getOwnerNetwork().getCurrentEssence();
BlockPos pos = masterRitualStone.getBlockPos();
int maxEffects = currentEssence / getRefreshCost();
int totalEffects = 0;
AreaDescriptor chestRange = getBlockRange(CHEST_RANGE);
TileEntity tile = world.getTileEntity(chestRange.getContainedPositions(pos).get(0));
if (tile == null || !tile.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null))
return;
IItemHandler inventory = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
int lastSlot = 0;
AreaDescriptor fillingRange = getBlockRange(FILL_RANGE);
List<EntityPlayer> playerList = world.getEntitiesWithinAABB(EntityPlayer.class, fillingRange.getAABB(pos));
for (EntityPlayer player : playerList) {
FoodStats foodStats = player.getFoodStats();
float satLevel = foodStats.getSaturationLevel();
for (int i = lastSlot; i < inventory.getSlots(); i++) {
ItemStack stack = inventory.extractItem(i, 1, true);
if (!stack.isEmpty() && stack.getItem() instanceof ItemFood) {
ItemFood foodItem = (ItemFood) stack.getItem();
int healAmount = foodItem.getHealAmount(stack);
float saturationAmount = foodItem.getSaturationModifier(stack) * healAmount * 2.0f;
// Pam please stop being weird. Fix your mod.
if (saturationAmount + satLevel <= 20 || satLevel < 5) {
foodStats.addStats(foodItem, stack);
inventory.extractItem(i, 1, false);
totalEffects++;
lastSlot = i;
break;
}
}
}
if (totalEffects >= maxEffects) {
masterRitualStone.getOwnerNetwork().causeNausea();
break;
}
}
masterRitualStone.getOwnerNetwork().syphon(getRefreshCost() * totalEffects);
}
Aggregations