Search in sources :

Example 6 with FoodStats

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;
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) FoodStats(net.minecraft.util.FoodStats)

Example 7 with FoodStats

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);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ItemFood(net.minecraft.item.ItemFood) IItemHandler(net.minecraftforge.items.IItemHandler) EntityPlayer(net.minecraft.entity.player.EntityPlayer) FoodStats(net.minecraft.util.FoodStats) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack)

Aggregations

FoodStats (net.minecraft.util.FoodStats)7 EntityPlayer (net.minecraft.entity.player.EntityPlayer)5 ItemStack (net.minecraft.item.ItemStack)3 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 ItemFood (net.minecraft.item.ItemFood)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 TileEntity (net.minecraft.tileentity.TileEntity)1 ActionResult (net.minecraft.util.ActionResult)1 EnumActionResult (net.minecraft.util.EnumActionResult)1 BlockPos (net.minecraft.util.math.BlockPos)1 World (net.minecraft.world.World)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1 IItemHandler (net.minecraftforge.items.IItemHandler)1