WeatherCheck .java

net.minecraft.world.level.storage.loot.predicates.WeatherCheck (record): members: isRaining, isThundering, weather, test, Builder, MAP_CODEC, codec.

net.minecraft.world.level.storage.loot.predicatesrecord53 linescommon1.7 KB

Implements

API Surface (6)

MapCodec<WeatherCheck> codec()
boolean test(final LootContext context)
WeatherCheck.Builder weather()
WeatherCheck.Builder setRaining(final boolean raining)
WeatherCheck.Builder setThundering(final boolean thundering)
WeatherCheck build()

Fields & Constants (1)

MAP_CODEC

String literals (2)

"raining"
"thundering"

Code Graph: Dependencies (4)

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

Full Source

WeatherCheck.java53 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.storage.loot.predicates;
2
3
import com.mojang.serialization.Codec;
4
import com.mojang.serialization.MapCodec;
5
import com.mojang.serialization.codecs.RecordCodecBuilder;
6
import java.util.Optional;
7
import net.minecraft.server.level.ServerLevel;
8
import net.minecraft.world.level.storage.loot.LootContext;
9
10
public record WeatherCheck(Optional<Boolean> isRaining, Optional<Boolean> isThundering) implements LootItemCondition {
11
	public static final MapCodec<WeatherCheck> MAP_CODEC = RecordCodecBuilder.mapCodec(
12
		i -> i.group(
13
				Codec.BOOL.optionalFieldOf("raining").forGetter(WeatherCheck::isRaining), Codec.BOOL.optionalFieldOf("thundering").forGetter(WeatherCheck::isThundering)
14
			)
15
			.apply(i, WeatherCheck::new)
16
	);
17
18
	@Override
19
	public MapCodec<WeatherCheck> codec() {
20
		return MAP_CODEC;
21
	}
22
23
	public boolean test(final LootContext context) {
24
		ServerLevel level = context.getLevel();
25
		return this.isRaining.isPresent() && this.isRaining.get() != level.isRaining()
26
			? false
27
			: !this.isThundering.isPresent() || this.isThundering.get() == level.isThundering();
28
	}
29
30
	public static WeatherCheck.Builder weather() {
31
		return new WeatherCheck.Builder();
32
	}
33
34
	public static class Builder implements LootItemCondition.Builder {
35
		private Optional<Boolean> isRaining = Optional.empty();
36
		private Optional<Boolean> isThundering = Optional.empty();
37
38
		public WeatherCheck.Builder setRaining(final boolean raining) {
39
			this.isRaining = Optional.of(raining);
40
			return this;
41
		}
42
43
		public WeatherCheck.Builder setThundering(final boolean thundering) {
44
			this.isThundering = Optional.of(thundering);
45
			return this;
46
		}
47
48
		public WeatherCheck build() {
49
			return new WeatherCheck(this.isRaining, this.isThundering);
50
		}
51
	}
52
}
53

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