CacheableFunction .java

net.minecraft.commands.CacheableFunction (class): members: resolved, function, getId, hashCode, equals, get, CODEC. imports: ServerFunctionManager, Codec.

net.minecraft.commandsclass43 linescommon1.2 KB

API Surface (4)

Optional<CommandFunction<CommandSourceStack>> get(final ServerFunctionManager manager)
Identifier getId()
boolean equals(final Object obj)
int hashCode()

Fields & Constants (4)

CODEC
id
resolved
function

Code Graph: Dependencies (4)

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

Full Source

CacheableFunction.java43 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.commands;
2
3
import com.mojang.serialization.Codec;
4
import java.util.Objects;
5
import java.util.Optional;
6
import net.minecraft.commands.functions.CommandFunction;
7
import net.minecraft.resources.Identifier;
8
import net.minecraft.server.ServerFunctionManager;
9
10
public class CacheableFunction {
11
	public static final Codec<CacheableFunction> CODEC = Identifier.CODEC.xmap(CacheableFunction::new, CacheableFunction::getId);
12
	private final Identifier id;
13
	private boolean resolved;
14
	private Optional<CommandFunction<CommandSourceStack>> function = Optional.empty();
15
16
	public CacheableFunction(final Identifier id) {
17
		this.id = id;
18
	}
19
20
	public Optional<CommandFunction<CommandSourceStack>> get(final ServerFunctionManager manager) {
21
		if (!this.resolved) {
22
			this.function = manager.get(this.id);
23
			this.resolved = true;
24
		}
25
26
		return this.function;
27
	}
28
29
	public Identifier getId() {
30
		return this.id;
31
	}
32
33
	@Override
34
	public boolean equals(final Object obj) {
35
		return obj == this ? true : obj instanceof CacheableFunction cacheableFunction && this.getId().equals(cacheableFunction.getId());
36
	}
37
38
	@Override
39
	public int hashCode() {
40
		return Objects.hash(this.id);
41
	}
42
}
43

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