ContextIntProvider .java

net.minecraft.world.level.storage.loot.providers.number.ints.ContextIntProvider (interface): members: floatToIntSafe, longToIntSafe, getInt, getIntUnsafe.

net.minecraft.world.level.storage.loot.providers.number.intsinterface37 linescommonextends Validatable1016 B

API Surface (0)

No public/protected methods detected (fields or constants only).

String literals (2)

"Value "
" can't be safely converted to int"

Code Graph: Dependencies (2)

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

Full Source

ContextIntProvider.java37 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.storage.loot.providers.number.ints;
2
3
import com.mojang.serialization.MapCodec;
4
import net.minecraft.world.level.storage.loot.LootContext;
5
import net.minecraft.world.level.storage.loot.Validatable;
6
7
public interface ContextIntProvider extends Validatable {
8
	int getIntUnsafe(LootContext context) throws ArithmeticException;
9
10
	default int getInt(final LootContext context) {
11
		try {
12
			return this.getIntUnsafe(context);
13
		} catch (ArithmeticException var3) {
14
			return 0;
15
		}
16
	}
17
18
	MapCodec<? extends ContextIntProvider> codec();
19
20
	static int floatToIntSafe(final float value) {
21
		if (!Float.isFinite(value)) {
22
			throw new ArithmeticException("Value " + value + " can't be safely converted to int");
23
		} else {
24
			return longToIntSafe((long)value);
25
		}
26
	}
27
28
	static int longToIntSafe(final long value) {
29
		int result = (int)value;
30
		if (result != value) {
31
			throw new ArithmeticException("Value " + value + " can't be safely converted to int");
32
		} else {
33
			return result;
34
		}
35
	}
36
}
37

Decompiled Minecraft 26.3 source of ContextIntProvider (net/minecraft/world/level/storage/loot/providers/number/ints/ContextIntProvider.java) with Mojang official mappings, stored verbatim on the site.