RotationArgument .java

net.minecraft.commands.arguments.coordinates.RotationArgument (class): members: ERROR_NOT_COMPLETE, getRotation, getExamples, EXAMPLES, rotation, parse.

net.minecraft.commands.arguments.coordinatesclass47 linescommon1.7 KB

Implements

API Surface (4)

RotationArgument rotation()
Coordinates getRotation(final CommandContext<CommandSourceStack> context, final String name)
Coordinates parse(final StringReader reader)
Collection<String> getExamples()

Fields & Constants (2)

EXAMPLES
ERROR_NOT_COMPLETE

String literals (1)

"argument.rotation.incomplete"

Code Graph: Dependencies (5)

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

Full Source

RotationArgument.java47 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.commands.arguments.coordinates;
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.SimpleCommandExceptionType;
8
import java.util.Arrays;
9
import java.util.Collection;
10
import net.minecraft.commands.CommandSourceStack;
11
import net.minecraft.network.chat.Component;
12
13
public class RotationArgument implements ArgumentType<Coordinates> {
14
	private static final Collection<String> EXAMPLES = Arrays.asList("0 0", "~ ~", "~-5 ~5");
15
	public static final SimpleCommandExceptionType ERROR_NOT_COMPLETE = new SimpleCommandExceptionType(Component.translatable("argument.rotation.incomplete"));
16
17
	public static RotationArgument rotation() {
18
		return new RotationArgument();
19
	}
20
21
	public static Coordinates getRotation(final CommandContext<CommandSourceStack> context, final String name) {
22
		return context.getArgument(name, Coordinates.class);
23
	}
24
25
	public Coordinates parse(final StringReader reader) throws CommandSyntaxException {
26
		int start = reader.getCursor();
27
		if (!reader.canRead()) {
28
			throw ERROR_NOT_COMPLETE.createWithContext(reader);
29
		} else {
30
			WorldCoordinate y = WorldCoordinate.parseDouble(reader, false);
31
			if (reader.canRead() && reader.peek() == ' ') {
32
				reader.skip();
33
				WorldCoordinate x = WorldCoordinate.parseDouble(reader, false);
34
				return new WorldCoordinates(x, y, new WorldCoordinate(true, 0.0));
35
			} else {
36
				reader.setCursor(start);
37
				throw ERROR_NOT_COMPLETE.createWithContext(reader);
38
			}
39
		}
40
	}
41
42
	@Override
43
	public Collection<String> getExamples() {
44
		return EXAMPLES;
45
	}
46
}
47

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