LockCode .java

net.minecraft.world.LockCode (record, 33 lines): members: predicate, unlocksWith, canUnlock, TAG_LOCK, addToTag, NO_LOCK, fromTag, CODEC. strings: "lock".

net.minecraft.worldrecord33 linescommon1.1 KB

API Surface (5)

record LockCode(ItemPredicate predicate)
boolean unlocksWith(final ItemStack itemStack)
void addToTag(final ValueOutput parent)
boolean canUnlock(final Player player)
LockCode fromTag(final ValueInput parent)

Fields & Constants (3)

NO_LOCK
CODEC
TAG_LOCK

String literals (1)

"lock"

Code Graph: Dependencies (5)

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

Full Source

LockCode.java33 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world;
2
3
import com.mojang.serialization.Codec;
4
import net.minecraft.advancements.predicates.ItemPredicate;
5
import net.minecraft.world.entity.player.Player;
6
import net.minecraft.world.item.ItemStack;
7
import net.minecraft.world.level.storage.ValueInput;
8
import net.minecraft.world.level.storage.ValueOutput;
9
10
public record LockCode(ItemPredicate predicate) {
11
	public static final LockCode NO_LOCK = new LockCode(ItemPredicate.Builder.item().build());
12
	public static final Codec<LockCode> CODEC = ItemPredicate.CODEC.xmap(LockCode::new, LockCode::predicate);
13
	public static final String TAG_LOCK = "lock";
14
15
	public boolean unlocksWith(final ItemStack itemStack) {
16
		return this.predicate.test(itemStack);
17
	}
18
19
	public void addToTag(final ValueOutput parent) {
20
		if (this != NO_LOCK) {
21
			parent.store("lock", CODEC, this);
22
		}
23
	}
24
25
	public boolean canUnlock(final Player player) {
26
		return player.isSpectator() || this.unlocksWith(player.getMainHandItem());
27
	}
28
29
	public static LockCode fromTag(final ValueInput parent) {
30
		return parent.read("lock", CODEC).orElse(NO_LOCK);
31
	}
32
}
33

Decompiled Minecraft 26.3 source of LockCode (net/minecraft/world/LockCode.java) with Mojang official mappings, stored verbatim on the site.