Search in sources :

Example 1 with FoodStats

use of net.minecraft.util.FoodStats in project MinecraftForge by MinecraftForge.

the class GuiIngameForge method renderFood.

public void renderFood(int width, int height) {
    if (pre(FOOD))
        return;
    mc.mcProfiler.startSection("food");
    EntityPlayer player = (EntityPlayer) this.mc.getRenderViewEntity();
    GlStateManager.enableBlend();
    int left = width / 2 + 91;
    int top = height - right_height;
    right_height += 10;
    // Unused flag in vanilla, seems to be part of a 'fade out' mechanic
    boolean unused = false;
    FoodStats stats = mc.player.getFoodStats();
    int level = stats.getFoodLevel();
    for (int i = 0; i < 10; ++i) {
        int idx = i * 2 + 1;
        int x = left - i * 8 - 9;
        int y = top;
        int icon = 16;
        byte background = 0;
        if (mc.player.isPotionActive(MobEffects.HUNGER)) {
            icon += 36;
            background = 13;
        }
        //Probably should be a += 1 but vanilla never uses this
        if (unused)
            background = 1;
        if (player.getFoodStats().getSaturationLevel() <= 0.0F && updateCounter % (level * 3 + 1) == 0) {
            y = top + (rand.nextInt(3) - 1);
        }
        drawTexturedModalRect(x, y, 16 + background * 9, 27, 9, 9);
        if (idx < level)
            drawTexturedModalRect(x, y, icon + 36, 27, 9, 9);
        else if (idx == level)
            drawTexturedModalRect(x, y, icon + 45, 27, 9, 9);
    }
    GlStateManager.disableBlend();
    mc.mcProfiler.endSection();
    post(FOOD);
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) FoodStats(net.minecraft.util.FoodStats)

Example 2 with FoodStats

use of net.minecraft.util.FoodStats in project SilentGems by SilentChaos512.

the class ItemDebug method clOnItemRightClick.

@Override
protected ActionResult<ItemStack> clOnItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand hand) {
    // playerIn.attackEntityFrom(DamageSource.inWall, 1.0f);
    FoodStats food = playerIn.getFoodStats();
    food.setFoodLevel(food.getFoodLevel() - 2);
    food.setFoodSaturationLevel(food.getSaturationLevel() - 0.2f);
    return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, playerIn.getHeldItem(hand));
}
Also used : ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) FoodStats(net.minecraft.util.FoodStats)

Example 3 with FoodStats

use of net.minecraft.util.FoodStats in project VoodooCraft by Mod-DevCafeTeam.

the class HexHandler method attackEvent.

/**
     * Fire Aura Hex
     * Water Breathing Hex
     */
@SubscribeEvent
public static void attackEvent(LivingAttackEvent event) {
    EntityLivingBase entity = event.getEntityLiving();
    ItemStack stack = null;
    //Fire Aura - Sets attacking entity on fire
    if (event.getSource().getSourceOfDamage() != null && (stack = getDollWithHex(entity, "fireAura")) != null)
        event.getSource().getSourceOfDamage().setFire(2);
    //Water Breathing - Uses player's hunger if possible when they're drowning
    if (event.getSource().equals(DamageSource.drown) && (stack = getDollWithHex(entity, "waterBreathing")) != null) {
        FoodStats food = ((EntityPlayer) entity).getFoodStats();
        if (food.getFoodLevel() > 0) {
            food.addStats(-1, 0);
            event.setCanceled(true);
        }
    }
    //Damage the doll
    if (stack != null)
        stack.damageItem(1, entity);
}
Also used : EntityLivingBase(net.minecraft.entity.EntityLivingBase) FoodStats(net.minecraft.util.FoodStats) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 4 with FoodStats

use of net.minecraft.util.FoodStats in project ConvenientAdditions by Necr0.

the class ItemSaturationRing method onWornTick.

@Override
public void onWornTick(ItemStack itemstack, EntityLivingBase player) {
    if (player.getEntityWorld().isRemote)
        return;
    EntityPlayer p = (EntityPlayer) player;
    FoodStats s = p.getFoodStats();
    if (s.needFood() && p.ticksExisted % 1100 == 0) {
        int foodLevel = Math.min((20 - s.getFoodLevel()), (1 + (p.world.rand.nextInt(8) == 0 ? 1 : 0)));
        s.addStats(foodLevel, 2f + (p.world.rand.nextFloat() * 2));
        p.world.playSound(null, p.posX, p.posY, p.posZ, SoundEvents.ENTITY_PLAYER_BURP, SoundCategory.PLAYERS, .05f, .95f);
    }
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) FoodStats(net.minecraft.util.FoodStats)

Example 5 with FoodStats

use of net.minecraft.util.FoodStats in project Bewitchment by Um-Mitternacht.

the class ItemFilledBowl method onFoodEaten.

@Override
public void onFoodEaten(ItemStack stack, World worldIn, EntityPlayer player) {
    if (stack.getTagCompound() == null) {
        // not really supposed to happen ingame since you only get the stews with NBT values assigned but it prevents crashing
        stack.setTagCompound(new NBTTagCompound());
    }
    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));
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) FoodStats(net.minecraft.util.FoodStats) 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