StoredNumberAccess .java

net.minecraft.world.level.storage.loot.providers.number.StoredNumberAccess (record): members: storage, path, getNumericTag, MAP_CODEC. strings: "storage".

net.minecraft.world.level.storage.loot.providers.numberrecord38 linescommon1.3 KB

API Surface (1)

record StoredNumberAccess(Identifier storage, NbtPathArgument.NbtPath path)

Fields & Constants (1)

MAP_CODEC

String literals (2)

"storage"
"path"

Code Graph: Dependencies (6)

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

Full Source

StoredNumberAccess.java38 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.storage.loot.providers.number;
2
3
import com.mojang.brigadier.exceptions.CommandSyntaxException;
4
import com.mojang.serialization.MapCodec;
5
import com.mojang.serialization.codecs.RecordCodecBuilder;
6
import java.util.List;
7
import net.minecraft.commands.arguments.NbtPathArgument;
8
import net.minecraft.nbt.CompoundTag;
9
import net.minecraft.nbt.NumericTag;
10
import net.minecraft.nbt.Tag;
11
import net.minecraft.resources.Identifier;
12
import net.minecraft.world.level.storage.loot.LootContext;
13
import org.jspecify.annotations.Nullable;
14
15
public record StoredNumberAccess(Identifier storage, NbtPathArgument.NbtPath path) {
16
	public static final MapCodec<StoredNumberAccess> MAP_CODEC = RecordCodecBuilder.mapCodec(
17
		i -> i.group(
18
				Identifier.CODEC.fieldOf("storage").forGetter(StoredNumberAccess::storage),
19
				NbtPathArgument.NbtPath.CODEC.fieldOf("path").forGetter(StoredNumberAccess::path)
20
			)
21
			.apply(i, StoredNumberAccess::new)
22
	);
23
24
	public @Nullable Number getNumericTag(final LootContext context) {
25
		CompoundTag value = context.getLevel().getServer().getCommandStorage().get(this.storage);
26
27
		try {
28
			List<Tag> selectedTags = this.path.get(value);
29
			if (selectedTags.size() == 1 && selectedTags.getFirst() instanceof NumericTag result) {
30
				return result.box();
31
			}
32
		} catch (CommandSyntaxException var6) {
33
		}
34
35
		return null;
36
	}
37
}
38

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