Class RandomChanceCondition

java.lang.Object
com.github.darksoulq.abyssallib.world.data.loot.LootCondition
com.github.darksoulq.abyssallib.world.data.loot.condition.RandomChanceCondition

public class RandomChanceCondition extends LootCondition
A loot condition that evaluates to true based on a random probability check.

This is the standard condition used to create rare drops or optional loot by defining a success rate between 0.0 and 1.0.

  • Field Details

    • CODEC

      public static final Codec<RandomChanceCondition> CODEC
      The codec used for serializing and deserializing the random chance condition.

      It requires a "chance" float field representing the probability of success.

    • TYPE

      public static final LootConditionType<RandomChanceCondition> TYPE
      The registered type definition for the random chance loot condition.
  • Constructor Details

    • RandomChanceCondition

      public RandomChanceCondition(float chance)
      Constructs a new RandomChanceCondition.
      Parameters:
      chance - The success probability, where 0.0 is never and 1.0 is always.
  • Method Details

    • test

      public boolean test(LootContext context)
      Performs a random check against the configured chance.

      This uses the Random instance provided by the LootContext to ensure consistent behavior with the rest of the loot generation cycle.

      Specified by:
      test in class LootCondition
      Parameters:
      context - The LootContext providing the random source.
      Returns:
      true if a random float [0, 1) is less than the chance; false otherwise.
    • getType

      public LootConditionType<?> getType()
      Retrieves the specific type definition for this loot condition.
      Specified by:
      getType in class LootCondition
      Returns:
      The LootConditionType associated with RandomChanceCondition.