RemoveBinomial .java

net.minecraft.world.item.enchantment.effects.RemoveBinomial (record): members: chance, process, codec, CODEC. strings: "chance". imports: LevelBasedValue.

net.minecraft.world.item.enchantment.effectsrecord38 linescommon1.1 KB

Implements

API Surface (2)

float process(final int level, final RandomSource random, final float n)
MapCodec<RemoveBinomial> codec()

Fields & Constants (1)

CODEC

String literals (1)

"chance"

Code Graph: Dependencies (3)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

RemoveBinomial.java38 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.item.enchantment.effects;
2
3
import com.mojang.serialization.MapCodec;
4
import com.mojang.serialization.codecs.RecordCodecBuilder;
5
import net.minecraft.util.RandomSource;
6
import net.minecraft.world.item.enchantment.LevelBasedValue;
7
8
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.