DoubleArgumentInfo .java

net.minecraft.commands.synchronization.brigadier.DoubleArgumentInfo (class, 64 lines): members: deserializeFromNetwork, serializeToJson, Template, unpack.

net.minecraft.commands.synchronization.brigadierclass64 linescommon2.1 KB

Implements

API Surface (6)

void serializeToNetwork(final DoubleArgumentInfo.Template template, final FriendlyByteBuf out)
DoubleArgumentInfo.Template deserializeFromNetwork(final FriendlyByteBuf in)
void serializeToJson(final DoubleArgumentInfo.Template template, final JsonObject out)
DoubleArgumentInfo.Template unpack(final DoubleArgumentType argument)
DoubleArgumentType instantiate(final CommandBuildContext context)
ArgumentTypeInfo<DoubleArgumentType, ?> type()

Code Graph: Dependencies (4)

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

Full Source

DoubleArgumentInfo.java64 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.commands.synchronization.brigadier;
2
3
import com.google.gson.JsonObject;
4
import com.mojang.brigadier.arguments.DoubleArgumentType;
5
import net.minecraft.commands.CommandBuildContext;
6
import net.minecraft.commands.synchronization.ArgumentTypeInfo;
7
import net.minecraft.commands.synchronization.ArgumentUtils;
8
import net.minecraft.network.FriendlyByteBuf;
9
10
public class DoubleArgumentInfo implements ArgumentTypeInfo<DoubleArgumentType, DoubleArgumentInfo.Template> {
11
	public void serializeToNetwork(final DoubleArgumentInfo.Template template, final FriendlyByteBuf out) {
12
		boolean hasMin = template.min != -Double.MAX_VALUE;
13
		boolean hasMax = template.max != Double.MAX_VALUE;
14
		out.writeByte(ArgumentUtils.createNumberFlags(hasMin, hasMax));
15
		if (hasMin) {
16
			out.writeDouble(template.min);
17
		}
18
19
		if (hasMax) {
20
			out.writeDouble(template.max);
21
		}
22
	}
23
24
	public DoubleArgumentInfo.Template deserializeFromNetwork(final FriendlyByteBuf in) {
25
		byte flags = in.readByte();
26
		double min = ArgumentUtils.numberHasMin(flags) ? in.readDouble() : -Double.MAX_VALUE;
27
		double max = ArgumentUtils.numberHasMax(flags) ? in.readDouble() : Double.MAX_VALUE;
28
		return new DoubleArgumentInfo.Template(min, max);
29
	}
30
31
	public void serializeToJson(final DoubleArgumentInfo.Template template, final JsonObject out) {
32
		if (template.min != -Double.MAX_VALUE) {
33
			out.addProperty("min", template.min);
34
		}
35
36
		if (template.max != Double.MAX_VALUE) {
37
			out.addProperty("max", template.max);
38
		}
39
	}
40
41
	public DoubleArgumentInfo.Template unpack(final DoubleArgumentType argument) {
42
		return new DoubleArgumentInfo.Template(argument.getMinimum(), argument.getMaximum());
43
	}
44
45
	public final class Template implements ArgumentTypeInfo.Template<DoubleArgumentType> {
46
		private final double min;
47
		private final double max;
48
49
		private Template(final double min, final double max) {
50
			this.min = min;
51
			this.max = max;
52
		}
53
54
		public DoubleArgumentType instantiate(final CommandBuildContext context) {
55
			return DoubleArgumentType.doubleArg(this.min, this.max);
56
		}
57
58
		@Override
59
		public ArgumentTypeInfo<DoubleArgumentType, ?> type() {
60
			return DoubleArgumentInfo.this;
61
		}
62
	}
63
}
64

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