Exemplo n.º 1
0
  public static ItemStack chargeHealth(
      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);
    }
    if (player.isSneaking()) {
      int points = stack.getTagCompound().getInteger(tag);
      if (points != 0) {
        int current = (int) player.getHealth();
        int max = (int) player.getMaxHealth();
        if (current != max & (current < max)) {
          int used = max - current;
          if (!(points - used < 0)) {
            nbtData.setInteger(tag, points - used);
            player.setHealth(player.getMaxHealth());
          } else if ((points - used < 0)) {
            nbtData.setInteger(tag, 0);
            player.setHealth(nbtData.getInteger(tag) + current);
          }
        }
      }
    } else {
      FontHelper.sendMessage(
          FontHelper.translate("points.health") + ": " + stack.getTagCompound().getInteger(tag),
          world,
          player);
    }
    return stack;
  }
Exemplo n.º 2
0
  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;
  }