Class Costs

java.lang.Object
com.soulfiremc.server.pathfinding.Costs

public final class Costs extends Object
This class helps in calculating the costs of different actions. It is used in the pathfinding algorithm to determine the best path to a goal. The heuristic used is the distance in blocks. So getting from point A to point B is calculated using the distance in blocks. The cost of breaking a block is calculated using the time it takes in ticks to break a block and then converted to a relative heuristic.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final record 
     
    static final record 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final double
    Normal player walking speed in blocks per second.
    static final double
    We don't want a bot that frequently tries to break blocks instead of walking around them.
    static final double
    Sliding around a corner is roughly like walking two blocks.
    static final double
    The distance in blocks between two points that are diagonal to each other.
    static final double
    Falling 1 block takes ~5.63 ticks.
    static final double
    Falling 2 blocks takes ~7.79 ticks.
    static final double
    Falling 3 blocks takes ~9.48 ticks.
    static final double
    It takes ~8 ticks for a player to jump up, decelerate and then land on the same y level.
    static final double
    It takes ~9 ticks for a player to jump up, decelerate and then land one block higher.
    static final double
    When you jump a gap you roughly do a full jump and walk 2 blocks in front.
    static final double
    We don't want a bot that frequently tries to place blocks instead of finding smarter paths.
    static final ThreadLocal<net.minecraft.world.item.ItemStack>
     
    static final double
    The distance in blocks between two points that are directly next to each other.
    static final double
    Multiply calculated ticks using this number to get a good relative heuristic.
    static final double
    A normal server runs at 20 ticks per second.
  • Method Summary

    Modifier and Type
    Method
    Description
    static @Nullable Costs.BlockMiningCosts
    calculateBlockBreakCost(net.minecraft.client.player.LocalPlayer entity, ProjectedInventory inventory, net.minecraft.world.level.block.state.BlockState blockState)
     
    getRequiredMiningTicks(net.minecraft.client.player.LocalPlayer entity, net.minecraft.world.item.ItemStack itemStack, net.minecraft.world.level.block.state.BlockState blockState)
     

    Methods inherited from class java.lang.Object

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

    • SELECTED_ITEM_MIXIN_OVERRIDE

      public static final ThreadLocal<net.minecraft.world.item.ItemStack> SELECTED_ITEM_MIXIN_OVERRIDE
    • STRAIGHT

      public static final double STRAIGHT
      The distance in blocks between two points that are directly next to each other.
      See Also:
    • DIAGONAL

      public static final double DIAGONAL
      The distance in blocks between two points that are diagonal to each other. Calculated using the Pythagorean theorem.
    • BREAK_BLOCK_PENALTY

      public static final double BREAK_BLOCK_PENALTY
      We don't want a bot that frequently tries to break blocks instead of walking around them.
    • PLACE_BLOCK_PENALTY

      public static final double PLACE_BLOCK_PENALTY
      We don't want a bot that frequently tries to place blocks instead of finding smarter paths.
    • TICKS_PER_SECOND

      public static final double TICKS_PER_SECOND
      A normal server runs at 20 ticks per second.
      See Also:
    • BLOCKS_PER_SECOND

      public static final double BLOCKS_PER_SECOND
      Normal player walking speed in blocks per second.
      See Also:
    • TICKS_PER_BLOCK

      public static final double TICKS_PER_BLOCK
      Multiply calculated ticks using this number to get a good relative heuristic.
      See Also:
    • JUMP_UP_BLOCK

      public static final double JUMP_UP_BLOCK
      It takes ~9 ticks for a player to jump up, decelerate and then land one block higher.
      See Also:
    • JUMP_LAND_GROUND

      public static final double JUMP_LAND_GROUND
      It takes ~8 ticks for a player to jump up, decelerate and then land on the same y level.
      See Also:
    • ONE_GAP_JUMP

      public static final double ONE_GAP_JUMP
      When you jump a gap you roughly do a full jump and walk 2 blocks in front.
      See Also:
    • FALL_1

      public static final double FALL_1
      Falling 1 block takes ~5.63 ticks.
      See Also:
    • FALL_2

      public static final double FALL_2
      Falling 2 blocks takes ~7.79 ticks.
      See Also:
    • FALL_3

      public static final double FALL_3
      Falling 3 blocks takes ~9.48 ticks.
      See Also:
    • CORNER_SLIDE

      public static final double CORNER_SLIDE
      Sliding around a corner is roughly like walking two blocks. That's why even through the distance from A to B diagonally is DIAGONAL, the cost is actually 2. That is why we need to add 2 - DIAGONAL to the cost of sliding around a corner as that adds up the cost to 2.
  • Method Details

    • calculateBlockBreakCost

      public static @Nullable Costs.BlockMiningCosts calculateBlockBreakCost(net.minecraft.client.player.LocalPlayer entity, ProjectedInventory inventory, net.minecraft.world.level.block.state.BlockState blockState)
    • getRequiredMiningTicks

      public static Costs.TickResult getRequiredMiningTicks(net.minecraft.client.player.LocalPlayer entity, net.minecraft.world.item.ItemStack itemStack, net.minecraft.world.level.block.state.BlockState blockState)