Class ExperienceHelper

java.lang.Object
net.darkhax.bookshelf.api.util.ExperienceHelper

public final class ExperienceHelper extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    chargeExperiencePoints(net.minecraft.world.entity.player.Player player, int cost)
    Attempts to charge the player an experience point cost.
    static int
    getExperiencePoints(net.minecraft.world.entity.player.Player player)
    Calculates the amount of experience points the player currently has.
    static int
    getPointForLevel(int level)
    Calculates the amount of additional experience points required to reach the given level when starting from the previous level.
    static int
    getPointsForLevel(int startingLevel, int targetLevel)
    Calculates the amount of additional experience points required to reach the target level when starting from the starting level.
    static int
    Calculates the total amount of experience points required to reach a given level when starting at level 0.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ExperienceHelper

      public ExperienceHelper()
  • Method Details

    • chargeExperiencePoints

      public static boolean chargeExperiencePoints(net.minecraft.world.entity.player.Player player, int cost)
      Attempts to charge the player an experience point cost. If the player can not afford the full amount they will not be charged and false will be returned.
      Parameters:
      player - The player to charge.
      cost - The amount to charge the player in experience points.
      Returns:
      True if the amount was paid.
    • getExperiencePoints

      public static int getExperiencePoints(net.minecraft.world.entity.player.Player player)
      Calculates the amount of experience points the player currently has. This should be used in favour of Player.totalExperience which deceptively does not track the amount of experience the player currently has.

      Contrary to popular belief the Player.totalExperience value actually loosely represents how much experience points the player has earned during their current life. This value is akin to the old player score metric and appears to be predominantly legacy code. Relying on this value is often incorrect as negative changes to the player level such as enchanting, the anvil, and the level command will not reduce this value.

      Parameters:
      player - The player to calculate the total experience points of.
      Returns:
      The amount of experience points held by the player.
    • getPointForLevel

      public static int getPointForLevel(int level)
      Calculates the amount of additional experience points required to reach the given level when starting from the previous level. This will also be the amount of experience points that an individual level is worth.
      Parameters:
      level - The level to calculate the point step for.
      Returns:
      The amount of points required to reach the given level when starting from the previous level.
    • getPointsForLevel

      public static int getPointsForLevel(int startingLevel, int targetLevel)
      Calculates the amount of additional experience points required to reach the target level when starting from the starting level.
      Parameters:
      startingLevel - The level to start the calculation at.
      targetLevel - The level to reach.
      Returns:
      The amount of additional experience points required to go from the starting level to the target level.
    • getTotalPointsForLevel

      public static int getTotalPointsForLevel(int level)
      Calculates the total amount of experience points required to reach a given level when starting at level 0.
      Parameters:
      level - The target level to reach.
      Returns:
      The amount of experience points required to reach the target level.