SlotArgument .java

net.minecraft.commands.arguments.SlotArgument (class): members: ERROR_ONLY_SINGLE_SLOT_ALLOWED, getSlot, slot, listSuggestions, getExamples, EXAMPLES.

net.minecraft.commands.argumentsclass52 linescommon1.9 KB

Implements

API Surface (5)

SlotArgument slot()
int getSlot(final CommandContext<CommandSourceStack> context, final String name)
Integer parse(final StringReader reader)
<S> CompletableFuture<Suggestions> listSuggestions(final CommandContext<S> contextBuilder, final SuggestionsBuilder builder)
Collection<String> getExamples()

Fields & Constants (2)

EXAMPLES
ERROR_ONLY_SINGLE_SLOT_ALLOWED

String literals (3)

"container.5"
"weapon"
"slot.only_single_allowed"

Code Graph: Dependencies (5)

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

Full Source

SlotArgument.java52 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.commands.arguments;
2
3
import com.mojang.brigadier.StringReader;
4
import com.mojang.brigadier.arguments.ArgumentType;
5
import com.mojang.brigadier.context.CommandContext;
6
import com.mojang.brigadier.exceptions.CommandSyntaxException;
7
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
8
import com.mojang.brigadier.suggestion.Suggestions;
9
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
10
import java.util.Arrays;
11
import java.util.Collection;
12
import java.util.concurrent.CompletableFuture;
13
import net.minecraft.commands.CommandSourceStack;
14
import net.minecraft.commands.SharedSuggestionProvider;
15
import net.minecraft.network.chat.Component;
16
import net.minecraft.world.inventory.SlotRange;
17
import net.minecraft.world.inventory.SlotRanges;
18
19
public class SlotArgument implements ArgumentType<Integer> {
20
	private static final Collection<String> EXAMPLES = Arrays.asList("container.5", "weapon");
21
	private static final DynamicCommandExceptionType ERROR_ONLY_SINGLE_SLOT_ALLOWED = new DynamicCommandExceptionType(
22
		id -> Component.translatableEscape("slot.only_single_allowed", id)
23
	);
24
25
	public static SlotArgument slot() {
26
		return new SlotArgument();
27
	}
28
29
	public static int getSlot(final CommandContext<CommandSourceStack> context, final String name) {
30
		return context.getArgument(name, Integer.class);
31
	}
32
33
	public Integer parse(final StringReader reader) throws CommandSyntaxException {
34
		SlotRange result = SlotRanges.read(reader);
35
		if (result.size() != 1) {
36
			throw ERROR_ONLY_SINGLE_SLOT_ALLOWED.createWithContext(reader, result.getSerializedName());
37
		} else {
38
			return result.slots().getInt(0);
39
		}
40
	}
41
42
	@Override
43
	public <S> CompletableFuture<Suggestions> listSuggestions(final CommandContext<S> contextBuilder, final SuggestionsBuilder builder) {
44
		return SharedSuggestionProvider.suggest(SlotRanges.singleSlotNames(), builder);
45
	}
46
47
	@Override
48
	public Collection<String> getExamples() {
49
		return EXAMPLES;
50
	}
51
}
52

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