Record Class ProbabilisticValue
java.lang.Object
java.lang.Record
johnsmith.enchantmentcore.api.enchantment.value.ProbabilisticValue
- Record Components:
chance- The innerLevelBasedValuethat calculates the probability (0.0 to 1.0) that the intended positive outcome (e.g., saving ammo, avoiding curse destruction) occurs.
- All Implemented Interfaces:
net.minecraft.world.item.enchantment.LevelBasedValue
public record ProbabilisticValue(net.minecraft.world.item.enchantment.LevelBasedValue chance)
extends Record
implements net.minecraft.world.item.enchantment.LevelBasedValue
A specialized implementation of
LevelBasedValue that calculates the success
or failure of a probabilistic event based on an inner chance provider.
This value is intended for use with game mechanics that require a boolean outcome (success/fail)
where 0.0 represents a success/false outcome, and 1.0 represents a failure/true outcome.
Intended Usage Example (Minecraft's minecraft:ammo_use):
- If
calculatereturns0.0: Ammo is saved (Infinite Ammo/Success). - If
calculatereturns1.0: Ammo is consumed (Failure).
-
Nested Class Summary
Nested classes/interfaces inherited from interface net.minecraft.world.item.enchantment.LevelBasedValue
net.minecraft.world.item.enchantment.LevelBasedValue.Clamped, net.minecraft.world.item.enchantment.LevelBasedValue.Constant, net.minecraft.world.item.enchantment.LevelBasedValue.Exponent, net.minecraft.world.item.enchantment.LevelBasedValue.Fraction, net.minecraft.world.item.enchantment.LevelBasedValue.LevelsSquared, net.minecraft.world.item.enchantment.LevelBasedValue.Linear, net.minecraft.world.item.enchantment.LevelBasedValue.Lookup -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final com.mojang.serialization.MapCodec<ProbabilisticValue> The codec responsible for serializing and deserializing instances of this record from JSON.static final StringRegistry path identifier for this level based value.Fields inherited from interface net.minecraft.world.item.enchantment.LevelBasedValue
DISPATCH_CODEC -
Constructor Summary
ConstructorsConstructorDescriptionProbabilisticValue(net.minecraft.world.item.enchantment.LevelBasedValue chance) Creates an instance of aProbabilisticValuerecord class. -
Method Summary
Modifier and TypeMethodDescriptionfloatcalculate(int level) Calculates a resulting float value of0.0For1.0Fbased on a random roll againstsaveChance.net.minecraft.world.item.enchantment.LevelBasedValuechance()Returns the value of thechancerecord component.@NotNull com.mojang.serialization.MapCodec<? extends net.minecraft.world.item.enchantment.LevelBasedValue> codec()final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.final StringtoString()Returns a string representation of this record class.
-
Field Details
-
KEY
-
CODEC
The codec responsible for serializing and deserializing instances of this record from JSON. It maps the nested"chance"field to a genericLevelBasedValue.
-
-
Constructor Details
-
ProbabilisticValue
public ProbabilisticValue(net.minecraft.world.item.enchantment.LevelBasedValue chance) Creates an instance of aProbabilisticValuerecord class.- Parameters:
chance- the value for thechancerecord component
-
-
Method Details
-
calculate
public float calculate(int level) Calculates a resulting float value of0.0For1.0Fbased on a random roll againstsaveChance.- Specified by:
calculatein interfacenet.minecraft.world.item.enchantment.LevelBasedValue- Parameters:
level- The level of the enchantment.- Returns:
0.0Fif a random number is less thansaveChance(Success/False);1.0Fotherwise (Failure/True).
-
codec
@NotNull public @NotNull com.mojang.serialization.MapCodec<? extends net.minecraft.world.item.enchantment.LevelBasedValue> codec()- Specified by:
codecin interfacenet.minecraft.world.item.enchantment.LevelBasedValue- Returns:
- The
MapCodecfor this class.
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
chance
-