Class RandomChanceWithLootingCondition

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

public class RandomChanceWithLootingCondition extends LootCondition
A loot condition that evaluates to true based on a probability that increases with the Looting enchantment level.

This condition calculates success using the formula: chance + (looting_level * multiplier). It is primarily used for rare mob drops where the probability of the drop is intended to scale with the player's equipment.

  • Field Details

    • CODEC

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

      It maps the "chance" base probability and the "looting_multiplier" float which is added per level of the Looting enchantment.

    • TYPE

      The registered type definition for the random chance with looting loot condition.
  • Constructor Details

    • RandomChanceWithLootingCondition

      public RandomChanceWithLootingCondition(float chance, float multiplier)
      Constructs a new RandomChanceWithLootingCondition.
      Parameters:
      chance - The base success probability.
      multiplier - The probability increase per level of the Looting enchantment.
  • Method Details

    • test

      public boolean test(LootContext context)
      Performs a random check against the base chance plus the looting bonus.

      The level of the Enchantment.LOOTING is retrieved from the tool present in the LootContext. If no tool is present, the level defaults to 0.

      Specified by:
      test in class LootCondition
      Parameters:
      context - The LootContext providing the tool and random source.
      Returns:
      true if a random float [0, 1) is less than the calculated threshold; 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 RandomChanceWithLootingCondition.