ExplosionCondition .java

net.minecraft.world.level.storage.loot.predicates.ExplosionCondition (class): members: survivesExplosion, getReferencedContextParams, INSTANCE, test.

net.minecraft.world.level.storage.loot.predicatesclass42 linescommon1.2 KB

Implements

API Surface (4)

MapCodec<ExplosionCondition> codec()
Set<ContextKey<?>> getReferencedContextParams()
boolean test(final LootContext context)
LootItemCondition.Builder survivesExplosion()

Fields & Constants (2)

INSTANCE
MAP_CODEC

Code Graph: Dependencies (6)

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

Full Source

ExplosionCondition.java42 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.storage.loot.predicates;
2
3
import com.mojang.serialization.MapCodec;
4
import java.util.Set;
5
import net.minecraft.util.RandomSource;
6
import net.minecraft.util.context.ContextKey;
7
import net.minecraft.world.level.storage.loot.LootContext;
8
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
9
10
public class ExplosionCondition implements LootItemCondition {
11
	private static final ExplosionCondition INSTANCE = new ExplosionCondition();
12
	public static final MapCodec<ExplosionCondition> MAP_CODEC = MapCodec.unit(INSTANCE);
13
14
	private ExplosionCondition() {
15
	}
16
17
	@Override
18
	public MapCodec<ExplosionCondition> codec() {
19
		return MAP_CODEC;
20
	}
21
22
	@Override
23
	public Set<ContextKey<?>> getReferencedContextParams() {
24
		return Set.of(LootContextParams.EXPLOSION_RADIUS);
25
	}
26
27
	public boolean test(final LootContext context) {
28
		Float explosionRadius = context.getOptional(LootContextParams.EXPLOSION_RADIUS);
29
		if (explosionRadius != null) {
30
			RandomSource random = context.getRandom();
31
			float probability = 1.0F / explosionRadius;
32
			return random.nextFloat() <= probability;
33
		} else {
34
			return true;
35
		}
36
	}
37
38
	public static LootItemCondition.Builder survivesExplosion() {
39
		return () -> INSTANCE;
40
	}
41
}
42

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