@Override
  protected void onFoodEaten(ItemStack itemstack, World world, EntityPlayer player) {
    player.extinguish();

    if (!world.isRemote) {
      Random random = player.getRNG();
      int max = random.nextInt(3) + 1;

      for (int i = 0; i < max; ++i) {
        Potion potion = null;

        while (potion == null
            || potion.getEffectiveness() <= 0.5D
            || player.isPotionActive(potion)) {
          potion = Potion.potionTypes[random.nextInt(Potion.potionTypes.length)];
        }

        if (potion != null) {
          player.addPotionEffect(new PotionEffect(potion.getId(), random.nextInt(500) + 150));
        }
      }
    }

    player.getFoodStats().addStats((20 - player.getFoodStats().getFoodLevel()) / 2, 0.5F);
    player.heal((player.getMaxHealth() - player.getHealth()) * 0.5F);
  }
  @Override
  public boolean onBlockActivated(
      World par1World,
      int par2,
      int par3,
      int par4,
      EntityPlayer par5EntityPlayer,
      int par6,
      float par7,
      float par8,
      float par9) {
    boolean didSomething = false;

    if (par5EntityPlayer.getHealth() < 12) {
      par5EntityPlayer.heal(12 - par5EntityPlayer.getHealth());
      didSomething = true;
    }
    if (par5EntityPlayer.getFoodStats().getFoodLevel() < 12) {
      par5EntityPlayer
          .getFoodStats()
          .addStats(12 - par5EntityPlayer.getFoodStats().getFoodLevel(), 0F);
      didSomething = true;
    }

    if (!didSomething && !par1World.isRemote)
      par5EntityPlayer.addChatMessage(
          "The altar can not further heal you. Come back when you're more wounded.");

    return true;
  }
  public static ItemStack chargeHunger(
      ItemStack stack, World world, EntityPlayer player, String tag) {

    if (!stack.hasTagCompound()) {
      stack.setTagCompound(new NBTTagCompound());
    }
    NBTTagCompound nbtData = stack.getTagCompound();
    if (nbtData == null) {
      stack.getTagCompound().setInteger(tag, 0);
    }
    int points = stack.getTagCompound().getInteger(tag);
    if (player.isSneaking()) {
      int hunger = player.getFoodStats().getFoodLevel();

      int usedpoints = 20 - hunger;

      if (!(hunger >= 20)) {
        if (points - usedpoints > 1) {
          points -= usedpoints;
          nbtData.setInteger(tag, points);
          player.getFoodStats().addStats(20, 2.0F);

        } else if (points - usedpoints < 1) {
          nbtData.setInteger(tag, 0);
          player.getFoodStats().addStats(points, 2.0F);
        }
      }
    } else if (!world.isRemote) {
      FontHelper.sendMessage(
          FontHelper.translate("points.hunger") + ": " + stack.getTagCompound().getInteger(tag),
          world,
          player);
    }
    return stack;
  }
 @Override
 protected boolean set(EntityPlayer entity, Map<Key<?>, Object> keyValues) {
   entity.getFoodStats().setFoodLevel((Integer) keyValues.get(Keys.FOOD_LEVEL));
   entity.getFoodStats().foodSaturationLevel =
       ((Double) keyValues.get(Keys.SATURATION)).floatValue();
   entity.getFoodStats().foodExhaustionLevel =
       ((Double) keyValues.get(Keys.EXHAUSTION)).floatValue();
   return true;
 }
 @Override
 protected Map<Key<?>, ?> getValues(EntityPlayer entity) {
   final int food = entity.getFoodStats().getFoodLevel();
   final double saturation = entity.getFoodStats().foodSaturationLevel;
   final double exhaustion = entity.getFoodStats().foodExhaustionLevel;
   return ImmutableMap.<Key<?>, Object>of(
       Keys.FOOD_LEVEL, food,
       Keys.SATURATION, saturation,
       Keys.EXHAUSTION, exhaustion);
 }
 @Override
 public Optional<Double> getValueFromContainer(ValueContainer<?> container) {
   if (supports(container)) {
     final EntityPlayer player = (EntityPlayer) container;
     if (player.getFoodStats() != null) {
       return Optional.of((double) player.getFoodStats().getSaturationLevel());
     }
   }
   return Optional.absent();
 }
Exemple #7
0
 @Override
 public void onConsumed(World world, EntityPlayer player) {
   if (SkyFish.tastyfish) {
     player.getFoodStats().addStats(1, 0.05F);
     world.playSoundAtEntity(player, "random.burp", 0.5F, world.rand.nextFloat() * 0.1F + 0.9F);
   } else {
     player.getFoodStats().addStats(1, 0.3F);
     world.playSoundAtEntity(player, "random.burp", 0.5F, world.rand.nextFloat() * 0.1F + 0.9F);
   }
 }
 @Override
 public DataTransactionResult offerToStore(ValueContainer<?> container, Double value) {
   if (supports(container)) {
     final EntityPlayer player = (EntityPlayer) container;
     if (player.getFoodStats() != null) {
       final Double oldValue = (double) player.getFoodStats().getSaturationLevel();
       player.getFoodStats().foodSaturationLevel = value.floatValue();
       return DataTransactionBuilder.successReplaceResult(
           new ImmutableSpongeValue<Double>(Keys.SATURATION, value),
           new ImmutableSpongeValue<Double>(Keys.SATURATION, oldValue));
     }
   }
   return DataTransactionBuilder.failResult(
       new ImmutableSpongeValue<Double>(Keys.SATURATION, value));
 }
  public void onPlayerStoppedUsing(ItemStack var1, World var2, EntityPlayer var3, int var4) {
    int var5 = var3.getFoodStats().getFoodLevel();

    if (var5 > 6) {
      int var6 = this.getMaxItemUseDuration(var1) - var4;
      float var7 = (float) var6 / 20.0F;
      var7 = (var7 * var7 + var7 * 2.0F) / 3.0F;

      if (var7 >= 1.0F && var5 > 7) {
        for (int var18 = 0; var18 < 8; ++var18) {
          double var9 = Math.PI * (double) var18 / 4.0D;
          double var11 = var3.posX + 5.5D * Math.sin(var9);
          double var13 = var3.posZ + 5.5D * Math.cos(var9);
          double var15 = (double) var2.getHeightValue((int) (var11 - 0.5D), (int) (var13 - 0.5D));
          EntityLightningBolt var17 = new EntityLightningBolt(var2, var11, var15, var13);

          //					if (!var2.isRemote)
          //					{
          var2.spawnEntityInWorld(var17);
          //					}
        }

        if (!var3.capabilities.isCreativeMode) {
          var3.getFoodStats().addStats(-1, 1.0f);
        }
      } else {
        double var8 = var3.posX;
        double var10 = var3.posZ;
        var8 -= 6.0D * Math.sin((double) (var3.rotationYaw / 180.0F) * Math.PI);
        var10 += 6.0D * Math.cos((double) (var3.rotationYaw / 180.0F) * Math.PI);
        double var12 = (double) var2.getHeightValue((int) (var8 - 0.5D), (int) (var10 - 0.5D));
        EntityLightningBolt var14 = new EntityLightningBolt(var2, var8, var12, var10);

        //				if (!var2.isRemote)
        //				{
        var2.spawnEntityInWorld(var14);
        //				}

        if (!var3.capabilities.isCreativeMode) {
          var3.getFoodStats().addStats(-1, 1.0f);
        }
      }

      var1.damageItem(1, var3);
      var3.swingItem();
      var2.playSoundAtEntity(var3, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F));
    }
  }
  /** 食べる動作 */
  @Override
  public ItemStack onEaten(ItemStack item, World world, EntityPlayer player) {
    int meta = item.getItemDamage();

    if (!player.capabilities.isCreativeMode) {
      --item.stackSize;
    }
    this.returnItemStack(player, meta);

    if (!world.isRemote) {
      if (this.effectOnEaten(player, meta) != null) {
        ArrayList<PotionEffect> potion = this.effectOnEaten(player, meta);
        if (potion != null && !potion.isEmpty()) {
          for (PotionEffect ret : potion) {
            player.addPotionEffect(ret);
          }
        }
      }

      if (this.hungerOnEaten(meta) != null) {
        int[] h = this.hungerOnEaten(meta);
        player.getFoodStats().addStats(h[0], h[1]);
      }
    }

    return item;
  }
 /* 26:   */
 /* 27:   */ public void onUpdateEquiped(
     ItemStack par1ItemStack, World world, EntityLivingBase entity)
       /* 28:   */ {
   /* 29:29 */ if ((entity instanceof EntityPlayer)) {
     /* 30:31 */ if (entity.ticksExisted % 100 == 0)
     /* 31:   */ {
       /* 32:33 */ EntityPlayer e = (EntityPlayer) entity;
       /* 33:34 */ e.getFoodStats().addStats(1, 6.0F);
       /* 34:   */ }
     /* 35:   */ }
   /* 36:   */ }
  public ItemStack onItemRightClick(ItemStack var1, World var2, EntityPlayer var3) {
    int var4 = var3.getFoodStats().getFoodLevel();

    if (var4 > 6
        && var2.canBlockSeeTheSky(
            (int) (var3.posX - 0.5D), (int) var3.posY, (int) (var3.posZ - 0.5D))) {
      var3.setItemInUse(var1, this.getMaxItemUseDuration(var1));
    }

    return var1;
  }
  public ItemStack onEaten(ItemStack itemstack, World par2World, EntityPlayer entityplayer) {
    --itemstack.stackSize;
    entityplayer.getFoodStats().addStats(this);
    par2World.playSoundAtEntity(
        entityplayer, "random.burp", 0.5F, par2World.rand.nextFloat() * 0.1F + 0.9F);
    if (itemstack.getItemDamage() == 0) {
      entityplayer.addPotionEffect(new PotionEffect(Potion.resistance.id, 200, 2));
    } else if (itemstack.getItemDamage() == 1) {
      entityplayer.addPotionEffect(new PotionEffect(Potion.moveSpeed.id, 200, 2));
    } else if (itemstack.getItemDamage() == 2) {
      entityplayer.addPotionEffect(new PotionEffect(Potion.moveSpeed.id, 200, 1));
      entityplayer.addPotionEffect(new PotionEffect(Potion.digSpeed.id, 200, 1));
    } else if (itemstack.getItemDamage() == 3) {
      entityplayer.addPotionEffect(new PotionEffect(Potion.regeneration.id, 20, 1));
      entityplayer.addPotionEffect(new PotionEffect(Potion.moveSpeed.id, 200, 1));
    } else if (itemstack.getItemDamage() == 4) {
      entityplayer.addPotionEffect(new PotionEffect(Potion.regeneration.id, 40, 1));
    } else if (itemstack.getItemDamage() == 5) {
      entityplayer.clearActivePotions();
      entityplayer.addPotionEffect(new PotionEffect(Potion.regeneration.id, 40, 1));
    } else if (itemstack.getItemDamage() == 6) {
      entityplayer.addPotionEffect(new PotionEffect(Potion.regeneration.id, 20, 1));
      entityplayer.addPotionEffect(new PotionEffect(Potion.resistance.id, 200, 1));
    } else if (itemstack.getItemDamage() == 7) {
      entityplayer.addPotionEffect(new PotionEffect(Potion.moveSpeed.id, 200, 1));
      entityplayer.addPotionEffect(new PotionEffect(Potion.resistance.id, 200, 1));
    } else if (itemstack.getItemDamage() == 9) {
      entityplayer.addPotionEffect(new PotionEffect(Potion.waterBreathing.id, 200, 1));
      entityplayer.addPotionEffect(new PotionEffect(Potion.regeneration.id, 20, 1));
    } else if (itemstack.getItemDamage() == 10) {
      entityplayer.addPotionEffect(new PotionEffect(Potion.damageBoost.id, 200, 1));
      entityplayer.addPotionEffect(new PotionEffect(Potion.regeneration.id, 20, 1));
    } else if (itemstack.getItemDamage() == 11) {
      entityplayer.addPotionEffect(new PotionEffect(Potion.damageBoost.id, 140, 1));
      entityplayer.addPotionEffect(new PotionEffect(Potion.regeneration.id, 20, 1));
      entityplayer.addPotionEffect(new PotionEffect(Potion.digSpeed.id, 140, 1));
    } else if (itemstack.getItemDamage() == 12) {
      entityplayer.addPotionEffect(new PotionEffect(Potion.regeneration.id, 20, 2));
    } else if (itemstack.getItemDamage() == 13) {
      entityplayer.addPotionEffect(new PotionEffect(Potion.damageBoost.id, 200, 1));
      entityplayer.addPotionEffect(new PotionEffect(Potion.regeneration.id, 20, 1));
      entityplayer.addPotionEffect(new PotionEffect(Potion.nightVision.id, 200, 1));
    } else if (itemstack.getItemDamage() == 14) {
      entityplayer.addPotionEffect(new PotionEffect(Potion.damageBoost.id, 200, 1));
      entityplayer.addPotionEffect(new PotionEffect(Potion.regeneration.id, 20, 1));
      entityplayer.addPotionEffect(new PotionEffect(Potion.moveSpeed.id, 200, 1));
    } else if (itemstack.getItemDamage() == 15) {
      entityplayer.addPotionEffect(new PotionEffect(Potion.regeneration.id, 20, 2));
      entityplayer.addPotionEffect(new PotionEffect(Potion.moveSpeed.id, 200, 2));
    }

    return itemstack;
  }
  /** Heals the player and removes a slice from the cake. */
  private void eatCakeSlice(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn) {
    if (playerIn.canEat(false)) {
      playerIn.getFoodStats().addStats(2, 0.1F);
      int i = ((Integer) state.getValue(BITES)).intValue();

      if (i < 6) {
        worldIn.setBlockState(pos, state.withProperty(BITES, Integer.valueOf(i + 1)), 3);
      } else {
        worldIn.setBlockToAir(pos);
      }
    }
  }
  public ItemStack onEaten(ItemStack itemStack, World world, EntityPlayer entityPlayer) {
    entityPlayer.getFoodStats().addStats(this);
    world.playSoundAtEntity(
        entityPlayer, "random.burp", 0.5F, world.rand.nextFloat() * 0.1F + 0.9F);
    itemStack.stackSize--;

    entityPlayer.addPotionEffect(new PotionEffect(Potion.resistance.id, 1 * 2400, 0));
    entityPlayer.addPotionEffect(new PotionEffect(Potion.regeneration.id, 1 * 2400, 0));
    entityPlayer.addPotionEffect(new PotionEffect(Potion.waterBreathing.id, 1 * 2400, 0));

    return new ItemStack(Item.glassBottle);
  }
  public ItemStack onEaten(ItemStack p_77654_1_, World p_77654_2_, EntityPlayer p_77654_3_) {
    if (!p_77654_3_.capabilities.isCreativeMode) {
      --p_77654_1_.stackSize;
    }

    if (!p_77654_2_.isRemote) {
      p_77654_3_.getFoodStats().addStats(2, .4F);
      p_77654_3_.extinguish();
    }

    return p_77654_1_.stackSize <= 0 ? new ItemStack(Items.bucket) : p_77654_1_;
  }
  /** Heals the player and removes a slice from the cake. */
  private void eatCakeSlice(
      World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer) {
    if (par5EntityPlayer.canEat(false)) {
      par5EntityPlayer.getFoodStats().addStats(2, 0.1F);
      final int l = par1World.getBlockMetadata(par2, par3, par4) + 1;

      if (l >= 6) {
        par1World.setBlockToAir(par2, par3, par4);
      } else {
        par1World.setBlockMetadataWithNotify(par2, par3, par4, l, 2);
      }
    }
  }
  public ItemStack onEaten(ItemStack itemStack, World world, EntityPlayer player) {
    NBTTagCompound tags = itemStack.stackTagCompound;
    if (tags.hasKey("meatTier")) {
      int meatTier = tags.getByte("meatTier");
    }

    --itemStack.stackSize;
    player.getFoodStats().addStats(6, 0.8F);
    world.playSoundAtEntity(player, "random.burp", 0.5F, world.rand.nextFloat() * 0.1F + 0.9F);
    // apply potion effects
    onFoodEaten(itemStack, world, player);
    return itemStack;
  }
Exemple #19
0
  @Override
  public boolean onBlockActivated(
      World world,
      int x,
      int y,
      int z,
      EntityPlayer player,
      int side,
      float hitX,
      float hitY,
      float hitZ) {
    if (world.isRemote) return true;
    TileEntityJarOHoney tile = Utils.getTileEntity(world, x, y, z, TileEntityJarOHoney.class);
    if (tile == null) return false;

    ItemStack stack = player.getCurrentEquippedItem();
    if (FluidContainerRegistry.isFilledContainer(stack)) {
      FluidStack fluidStack = FluidContainerRegistry.getFluidForFilledItem(stack);
      if (fluidStack.isFluidEqual(tile.getHoney()))
        if (fluidStack.amount + tile.getHoney().amount > TileEntityJarOHoney.HONEY_MAX_AMOUNT)
          return true;
        else {
          tile.addHoney(fluidStack.amount);
          ItemStack container = stack.getItem().getContainerItem(stack);
          stack.stackSize--;
          if (stack.stackSize <= 0) player.setCurrentItemOrArmor(0, container);
          else if (!player.inventory.addItemStackToInventory(container))
            Utils.dropStack(world, x, y, z, container);

          return true;
        }
    } else if (FluidContainerRegistry.isEmptyContainer(stack)) {
      ItemStack filledContainer = FluidContainerRegistry.fillFluidContainer(tile.getHoney(), stack);
      if (filledContainer != null) {
        stack.stackSize--;
        if (stack.stackSize <= 0) player.setCurrentItemOrArmor(0, filledContainer);
        else if (!player.inventory.addItemStackToInventory(filledContainer))
          Utils.dropStack(world, x, y, z, filledContainer);

        tile.drainHoney(FluidContainerRegistry.getFluidForFilledItem(filledContainer).amount);
        return true;
      }
    } else {
      player.getFoodStats().addStats(1, 0.8F);
      player.addPotionEffect(new PotionEffect(Potion.regeneration.id, 100, 1));
      tile.drainHoney(100);
    }
    return false;
  }
  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;
    boolean unused = false; // Unused flag in vanilla, seems to be part of a 'fade out' mechanic

    FoodStats stats = mc.thePlayer.getFoodStats();
    int level = stats.getFoodLevel();
    int levelLast = stats.getPrevFoodLevel();

    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 backgound = 0;

      if (mc.thePlayer.isPotionActive(Potion.hunger)) {
        icon += 36;
        backgound = 13;
      }
      if (unused) backgound = 1; // Probably should be a += 1 but vanilla never uses this

      if (player.getFoodStats().getSaturationLevel() <= 0.0F
          && updateCounter % (level * 3 + 1) == 0) {
        y = top + (rand.nextInt(3) - 1);
      }

      drawTexturedModalRect(x, y, 16 + backgound * 9, 27, 9, 9);

      if (unused) {
        if (idx < levelLast) drawTexturedModalRect(x, y, icon + 54, 27, 9, 9);
        else if (idx == levelLast) drawTexturedModalRect(x, y, icon + 63, 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);
  }
Exemple #21
0
  @Override
  public ItemStack onEaten(
      ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) {
    if (par1ItemStack.getItemDamage() > 14 && par1ItemStack.getItemDamage() < 19) {
      --par1ItemStack.stackSize;
      par3EntityPlayer
          .getFoodStats()
          .addStats(this.getHealAmount(par1ItemStack), this.getSaturationModifier(par1ItemStack));
      par2World.playSoundAtEntity(
          par3EntityPlayer, "random.burp", 0.5F, par2World.rand.nextFloat() * 0.1F + 0.9F);
      if (!par2World.isRemote) {
        par3EntityPlayer.entityDropItem(new ItemStack(GCItems.canister, 1, 0), 0.0F);
      }
      return par1ItemStack;
    }

    return super.onEaten(par1ItemStack, par2World, par3EntityPlayer);
  }
  @Override
  public void onUpdate(ItemStack is, World w, Entity e, int itemSlot, boolean isSelected) {

    if (e.ticksExisted % 40 != 0) return;

    if (!is.hasTagCompound()) {
      is.setTagCompound(new NBTTagCompound());
      is.getTagCompound().setFloat("SAT", 0);
      is.getTagCompound().setInteger("H", 0);
    }
    EntityPlayer player = (EntityPlayer) e;

    if (is.getTagCompound().getInteger("H") < 100 && is.getItemDamage() == 1) {
      for (int i = 0; i < player.inventory.getSizeInventory(); i++) {

        ItemStack c = player.inventory.getStackInSlot(i);

        if (c == null) continue;

        if (c.getItem() instanceof ItemFood) {

          ItemFood f = (ItemFood) c.getItem();
          float sat = f.getSaturationModifier(c);
          int food = f.getHealAmount(c);

          is.getTagCompound()
              .setFloat("SAT", Math.min(100, sat + is.getTagCompound().getFloat("SAT")));
          is.getTagCompound()
              .setInteger("H", Math.min(100, food + is.getTagCompound().getInteger("H")));

          player.inventory.getStackInSlot(i).stackSize--;
          break;
        }
      }
    }

    if (player.canEat(false)) {

      int foodNeeded = 20 - player.getFoodStats().getFoodLevel();

      if (foodNeeded <= is.getTagCompound().getInteger("H")) {

        player.getFoodStats().setFoodLevel(foodNeeded + player.getFoodStats().getFoodLevel());
        is.getTagCompound().setInteger("H", is.getTagCompound().getInteger("H") - foodNeeded);
      } else {

        player
            .getFoodStats()
            .setFoodLevel(
                player.getFoodStats().getFoodLevel() + is.getTagCompound().getInteger("H"));
        is.getTagCompound().setInteger("H", 0);
      }

      int satNeeded = Math.min(player.getFoodStats().getFoodLevel(), 20);

      if (satNeeded <= is.getTagCompound().getFloat("SAT")) {

        player
            .getFoodStats()
            .setFoodSaturationLevel(player.getFoodStats().getSaturationLevel() + satNeeded);

        is.getTagCompound().setFloat("SAT", is.getTagCompound().getFloat("SAT") - satNeeded);

      } else {

        player.getFoodStats().setFoodSaturationLevel(is.getTagCompound().getFloat("SAT"));

        is.getTagCompound().setFloat("SAT", 0);
      }
    }
  }
 public static void healPlayer(EntityPlayer player) {
   player.heal(20);
   player.getFoodStats().addStats(20, 1);
   player.extinguish();
 }
  @SuppressWarnings("rawtypes")
  @SubscribeEvent
  public void onPlayerUpdate(TickEvent.PlayerTickEvent event) {
    EntityPlayer player = event.player;
    if (Utilities.isServerSide()) {
      if (player.isPotionActive(ZombieInfection.potionInfection)
          && !player.isPotionActive(ZombieInfection.potionCure)) {
        int timeInfected = TimeInfectedTracking.getSecondsInfected(player);
        for (CustomInfectionEffect customEffect : ZombieInfectionAPI.getCustomInfectionEffects()) {
          customEffect.run(player, timeInfected);
        }

        player.addPotionEffect(PotionHelper.createInfection(timeInfected < 60 ? 0 : 1));
        if (ConfigurationHandler.enableSlowness())
          player.addPotionEffect(PotionHelper.createSlowness(timeInfected < 60 ? 0 : 1));
        if (ConfigurationHandler.enableHunger() && timeInfected >= 20)
          player.addPotionEffect(PotionHelper.createHunger(timeInfected < 80 ? 0 : 1));
        if (ConfigurationHandler.enableMiningFatigue() && timeInfected >= 40)
          player.addPotionEffect(PotionHelper.createMiningFatigue(timeInfected < 100 ? 0 : 1));
        if (ConfigurationHandler.enableWeakness() && timeInfected >= 60)
          player.addPotionEffect(PotionHelper.createWeakness(timeInfected < 120 ? 0 : 1));
        if (ConfigurationHandler.enableWither() && timeInfected >= 480)
          player.addPotionEffect(PotionHelper.createWither(0));

        if (player.getFoodStats().getFoodLevel() > FoodTracking.get(player)) {
          player
              .getFoodStats()
              .addStats(FoodTracking.get(player) - player.getFoodStats().getFoodLevel(), 0);
          EntityPlayerMP playerMP =
              FMLCommonHandler.instance()
                  .getMinecraftServerInstance()
                  .getConfigurationManager()
                  .getPlayerByUsername(player.getCommandSenderName());
          PacketHandler.INSTANCE.sendTo(
              PacketHandler.getFoodChangePacket(
                  player.getFoodStats().getFoodLevel(), player.getFoodStats().getSaturationLevel()),
              playerMP);
        }

        FoodTracking.put(player);

        int curSecond = Calendar.getInstance().get(Calendar.SECOND);
        if (curSecond != lastSecond) {
          lastSecond = curSecond;
          TimeInfectedTracking.update(player);
        }

        if (player.worldObj.canBlockSeeTheSky(
                (int) player.posX, (int) player.posY, (int) player.posZ)
            && player.worldObj.isDaytime()
            && !player.worldObj.isRaining()
            && !player.worldObj.isThundering()
            && timeInfected >= 80
            && player.inventory.armorInventory[3] == null) {
          player.setFire(1);
        }

        if (!FMLCommonHandler.instance().getMinecraftServerInstance().isPVPEnabled()
            && ConfigurationHandler.getSpreadEnabled()) {
          Iterator players =
              FMLCommonHandler.instance()
                  .getMinecraftServerInstance()
                  .getConfigurationManager()
                  .playerEntityList
                  .iterator();

          while (players.hasNext()) {
            Object thing = players.next();
            if (thing instanceof EntityPlayer) {
              EntityPlayer anotherPlayer = (EntityPlayer) thing;
              if (anotherPlayer.getDistanceToEntity(player)
                  < ConfigurationHandler.getSpreadDistance()) {
                if (anotherPlayer.getUniqueID() != player.getUniqueID()) {
                  if (!anotherPlayer.isPotionActive(ZombieInfection.potionInfection)) {
                    anotherPlayer.addChatMessage(
                        new ChatComponentTranslation("zombieinfection.chat.playerinfected"));
                    anotherPlayer.addPotionEffect(PotionHelper.createInfection(0));
                  }
                }
              }
            }
          }
        }
      } else {
        TimeInfectedTracking.remove(player);
        FoodTracking.remove(player);
      }
    }
  }
  @Override
  public void performEffect(IMasterRitualStone ritualStone) {
    String owner = ritualStone.getOwner();

    int currentEssence = SoulNetworkHandler.getCurrentEssence(owner);
    World world = ritualStone.getWorld();
    int x = ritualStone.getXCoord();
    int y = ritualStone.getYCoord();
    int z = ritualStone.getZCoord();

    if (world.getWorldTime() % 20 != 0) {
      return;
    }

    double horizRange = 16;
    double vertRange = 16;

    List<EntityPlayer> playerList =
        SpellHelper.getPlayersInRange(world, x + 0.5, y + 0.5, z + 0.5, horizRange, vertRange);

    if (playerList == null) {
      return;
    }

    if (currentEssence < this.getCostPerRefresh() * playerList.size()) {
      SoulNetworkHandler.causeNauseaToPlayer(owner);
    } else {
      TileEntity tile = world.getTileEntity(x, y + 1, z);
      IInventory inventory = null;
      if (tile instanceof IInventory) {
        inventory = (IInventory) tile;
      } else {
        tile = world.getTileEntity(x, y - 1, z);
        if (tile instanceof IInventory) {
          inventory = (IInventory) tile;
        }
      }

      int count = 0;

      if (inventory != null) {
        for (EntityPlayer player : playerList) {
          FoodStats foodStats = player.getFoodStats();
          float satLevel = foodStats.getSaturationLevel();

          for (int i = 0; i < inventory.getSizeInventory(); i++) {
            ItemStack stack = inventory.getStackInSlot(i);

            if (stack != null && stack.getItem() instanceof ItemFood) {
              ItemFood foodItem = (ItemFood) stack.getItem();

              int regularHeal = foodItem.func_150905_g(stack);
              float saturatedHeal = foodItem.func_150906_h(stack) * regularHeal * 2.0f;

              if (saturatedHeal + satLevel <= 20) {
                NBTTagCompound nbt = new NBTTagCompound();
                foodStats.writeNBT(nbt);
                nbt.setFloat("foodSaturationLevel", saturatedHeal + satLevel);
                foodStats.readNBT(nbt);

                inventory.decrStackSize(i, 1);
                count++;
                break;
              }
            }
          }
        }
      }

      SoulNetworkHandler.syphonFromNetwork(owner, this.getCostPerRefresh() * count);
    }
  }
 @Override
 protected boolean set(EntityPlayer container, Double value) {
   container.getFoodStats().foodExhaustionLevel = value.floatValue();
   return true;
 }
 @Override
 protected Optional<Double> getVal(EntityPlayer container) {
   return Optional.of((double) container.getFoodStats().foodExhaustionLevel);
 }
Exemple #28
0
  private void func_180477_d(ScaledResolution p_180477_1_) {
    if (this.mc.func_175606_aa() instanceof EntityPlayer) {
      EntityPlayer var2 = (EntityPlayer) this.mc.func_175606_aa();
      int var3 = MathHelper.ceiling_float_int(var2.getHealth());
      boolean var4 =
          this.field_175191_F > (long) this.updateCounter
              && (this.field_175191_F - (long) this.updateCounter) / 3L % 2L == 1L;

      if (var3 < this.field_175194_C && var2.hurtResistantTime > 0) {
        this.field_175190_E = Minecraft.getSystemTime();
        this.field_175191_F = (long) (this.updateCounter + 20);
      } else if (var3 > this.field_175194_C && var2.hurtResistantTime > 0) {
        this.field_175190_E = Minecraft.getSystemTime();
        this.field_175191_F = (long) (this.updateCounter + 10);
      }

      if (Minecraft.getSystemTime() - this.field_175190_E > 1000L) {
        this.field_175194_C = var3;
        this.field_175189_D = var3;
        this.field_175190_E = Minecraft.getSystemTime();
      }

      this.field_175194_C = var3;
      int var5 = this.field_175189_D;
      this.rand.setSeed((long) (this.updateCounter * 312871));
      boolean var6 = false;
      FoodStats var7 = var2.getFoodStats();
      int var8 = var7.getFoodLevel();
      int var9 = var7.getPrevFoodLevel();
      IAttributeInstance var10 = var2.getEntityAttribute(SharedMonsterAttributes.maxHealth);
      int var11 = p_180477_1_.getScaledWidth() / 2 - 91;
      int var12 = p_180477_1_.getScaledWidth() / 2 + 91;
      int var13 = p_180477_1_.getScaledHeight() - 39;
      float var14 = (float) var10.getAttributeValue();
      float var15 = var2.getAbsorptionAmount();
      int var16 = MathHelper.ceiling_float_int((var14 + var15) / 2.0F / 10.0F);
      int var17 = Math.max(10 - (var16 - 2), 3);
      int var18 = var13 - (var16 - 1) * var17 - 10;
      float var19 = var15;
      int var20 = var2.getTotalArmorValue();
      int var21 = -1;

      if (var2.isPotionActive(Potion.regeneration)) {
        var21 = this.updateCounter % MathHelper.ceiling_float_int(var14 + 5.0F);
      }

      this.mc.mcProfiler.startSection("armor");
      int var22;
      int var23;

      for (var22 = 0; var22 < 10; ++var22) {
        if (var20 > 0) {
          var23 = var11 + var22 * 8;

          if (var22 * 2 + 1 < var20) {
            this.drawTexturedModalRect(var23, var18, 34, 9, 9, 9);
          }

          if (var22 * 2 + 1 == var20) {
            this.drawTexturedModalRect(var23, var18, 25, 9, 9, 9);
          }

          if (var22 * 2 + 1 > var20) {
            this.drawTexturedModalRect(var23, var18, 16, 9, 9, 9);
          }
        }
      }

      this.mc.mcProfiler.endStartSection("health");
      int var25;
      int var26;
      int var27;

      for (var22 = MathHelper.ceiling_float_int((var14 + var15) / 2.0F) - 1; var22 >= 0; --var22) {
        var23 = 16;

        if (var2.isPotionActive(Potion.poison)) {
          var23 += 36;
        } else if (var2.isPotionActive(Potion.wither)) {
          var23 += 72;
        }

        byte var24 = 0;

        if (var4) {
          var24 = 1;
        }

        var25 = MathHelper.ceiling_float_int((float) (var22 + 1) / 10.0F) - 1;
        var26 = var11 + var22 % 10 * 8;
        var27 = var13 - var25 * var17;

        if (var3 <= 4) {
          var27 += this.rand.nextInt(2);
        }

        if (var22 == var21) {
          var27 -= 2;
        }

        byte var28 = 0;

        if (var2.worldObj.getWorldInfo().isHardcoreModeEnabled()) {
          var28 = 5;
        }

        this.drawTexturedModalRect(var26, var27, 16 + var24 * 9, 9 * var28, 9, 9);

        if (var4) {
          if (var22 * 2 + 1 < var5) {
            this.drawTexturedModalRect(var26, var27, var23 + 54, 9 * var28, 9, 9);
          }

          if (var22 * 2 + 1 == var5) {
            this.drawTexturedModalRect(var26, var27, var23 + 63, 9 * var28, 9, 9);
          }
        }

        if (var19 > 0.0F) {
          if (var19 == var15 && var15 % 2.0F == 1.0F) {
            this.drawTexturedModalRect(var26, var27, var23 + 153, 9 * var28, 9, 9);
          } else {
            this.drawTexturedModalRect(var26, var27, var23 + 144, 9 * var28, 9, 9);
          }

          var19 -= 2.0F;
        } else {
          if (var22 * 2 + 1 < var3) {
            this.drawTexturedModalRect(var26, var27, var23 + 36, 9 * var28, 9, 9);
          }

          if (var22 * 2 + 1 == var3) {
            this.drawTexturedModalRect(var26, var27, var23 + 45, 9 * var28, 9, 9);
          }
        }
      }

      Entity var34 = var2.ridingEntity;
      int var36;

      if (var34 == null) {
        this.mc.mcProfiler.endStartSection("food");

        for (var23 = 0; var23 < 10; ++var23) {
          var36 = var13;
          var25 = 16;
          byte var38 = 0;

          if (var2.isPotionActive(Potion.hunger)) {
            var25 += 36;
            var38 = 13;
          }

          if (var2.getFoodStats().getSaturationLevel() <= 0.0F
              && this.updateCounter % (var8 * 3 + 1) == 0) {
            var36 = var13 + (this.rand.nextInt(3) - 1);
          }

          if (var6) {
            var38 = 1;
          }

          var27 = var12 - var23 * 8 - 9;
          this.drawTexturedModalRect(var27, var36, 16 + var38 * 9, 27, 9, 9);

          if (var6) {
            if (var23 * 2 + 1 < var9) {
              this.drawTexturedModalRect(var27, var36, var25 + 54, 27, 9, 9);
            }

            if (var23 * 2 + 1 == var9) {
              this.drawTexturedModalRect(var27, var36, var25 + 63, 27, 9, 9);
            }
          }

          if (var23 * 2 + 1 < var8) {
            this.drawTexturedModalRect(var27, var36, var25 + 36, 27, 9, 9);
          }

          if (var23 * 2 + 1 == var8) {
            this.drawTexturedModalRect(var27, var36, var25 + 45, 27, 9, 9);
          }
        }
      } else if (var34 instanceof EntityLivingBase) {
        this.mc.mcProfiler.endStartSection("mountHealth");
        EntityLivingBase var35 = (EntityLivingBase) var34;
        var36 = (int) Math.ceil((double) var35.getHealth());
        float var37 = var35.getMaxHealth();
        var26 = (int) (var37 + 0.5F) / 2;

        if (var26 > 30) {
          var26 = 30;
        }

        var27 = var13;

        for (int var39 = 0; var26 > 0; var39 += 20) {
          int var29 = Math.min(var26, 10);
          var26 -= var29;

          for (int var30 = 0; var30 < var29; ++var30) {
            byte var31 = 52;
            byte var32 = 0;

            if (var6) {
              var32 = 1;
            }

            int var33 = var12 - var30 * 8 - 9;
            this.drawTexturedModalRect(var33, var27, var31 + var32 * 9, 9, 9, 9);

            if (var30 * 2 + 1 + var39 < var36) {
              this.drawTexturedModalRect(var33, var27, var31 + 36, 9, 9, 9);
            }

            if (var30 * 2 + 1 + var39 == var36) {
              this.drawTexturedModalRect(var33, var27, var31 + 45, 9, 9, 9);
            }
          }

          var27 -= 10;
        }
      }

      this.mc.mcProfiler.endStartSection("air");

      if (var2.isInsideOfMaterial(Material.water)) {
        var23 = this.mc.thePlayer.getAir();
        var36 = MathHelper.ceiling_double_int((double) (var23 - 2) * 10.0D / 300.0D);
        var25 = MathHelper.ceiling_double_int((double) var23 * 10.0D / 300.0D) - var36;

        for (var26 = 0; var26 < var36 + var25; ++var26) {
          if (var26 < var36) {
            this.drawTexturedModalRect(var12 - var26 * 8 - 9, var18, 16, 18, 9, 9);
          } else {
            this.drawTexturedModalRect(var12 - var26 * 8 - 9, var18, 25, 18, 9, 9);
          }
        }
      }

      this.mc.mcProfiler.endSection();
    }
  }