public record RemoveBinomial(LevelBasedValue chance) implements EnchantmentValueEffect {
9
public static final MapCodec<RemoveBinomial> CODEC = RecordCodecBuilder.mapCodec(
10
i -> i.group(LevelBasedValue.CODEC.fieldOf("chance").forGetter(RemoveBinomial::chance)).apply(i, RemoveBinomial::new)
11
);
12
13
@Override
14
public float process(final int level, final RandomSource random, final float n) {
15
float p = this.chance.calculate(level);
16
int drop = 0;
17
if (!(n <= 128.0F) && !(n * p < 20.0F) && !(n * (1.0F - p) < 20.0F)) {
18
double miu = Math.floor(n * p);
19
double sigma = Math.sqrt(n * p * (1.0F - p));
20
drop = (int)Math.round(miu + random.nextGaussian() * sigma);
21
drop = Math.clamp(drop, 0, (int)n);
22
} else {
23
for (int y = 0; y < n; y++) {
24
if (random.nextFloat() < p) {
25
drop++;
26
}
27
}
28
}
29
30
return n - drop;
31
}
32
33
@Override
34
public MapCodec<RemoveBinomial> codec() {
35
return CODEC;
36
}
37
}
38
Decompiled Minecraft 26.3 source of RemoveBinomial (net/minecraft/world/item/enchantment/effects/RemoveBinomial.java) with Mojang official mappings, stored verbatim on the site.