IntegerArgumentInfo .java

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

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

Implements

API Surface (6)

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

Code Graph: Dependencies (5)

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

Full Source

IntegerArgumentInfo.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.IntegerArgumentType;
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 IntegerArgumentInfo implements ArgumentTypeInfo<IntegerArgumentType, IntegerArgumentInfo.Template> {
11
	public void serializeToNetwork(final IntegerArgumentInfo.Template template, final FriendlyByteBuf out) {
12
		boolean hasMin = template.min != Integer.MIN_VALUE;
13
		boolean hasMax = template.max != Integer.MAX_VALUE;
14
		out.writeByte(ArgumentUtils.createNumberFlags(hasMin, hasMax));
15
		if (hasMin) {
16
			out.writeInt(template.min);
17
		}
18
19
		if (hasMax) {
20
			out.writeInt(template.max);
21
		}
22
	}
23
24
	public IntegerArgumentInfo.Template deserializeFromNetwork(final FriendlyByteBuf in) {
25
		byte flags = in.readByte();
26
		int min = ArgumentUtils.numberHasMin(flags) ? in.readInt() : Integer.MIN_VALUE;
27
		int max = ArgumentUtils.numberHasMax(flags) ? in.readInt() : Integer.MAX_VALUE;
28
		return new IntegerArgumentInfo.Template(min, max);
29
	}
30
31
	public void serializeToJson(final IntegerArgumentInfo.Template template, final JsonObject out) {
32
		if (template.min != Integer.MIN_VALUE) {
33
			out.addProperty("min", template.min);
34
		}
35
36
		if (template.max != Integer.MAX_VALUE) {
37
			out.addProperty("max", template.max);
38
		}
39
	}
40
41
	public IntegerArgumentInfo.Template unpack(final IntegerArgumentType argument) {
42
		return new IntegerArgumentInfo.Template(argument.getMinimum(), argument.getMaximum());
43
	}
44
45
	public final class Template implements ArgumentTypeInfo.Template<IntegerArgumentType> {
46
		private final int min;
47
		private final int max;
48
49
		private Template(final int min, final int max) {
50
			this.min = min;
51
			this.max = max;
52
		}
53
54
		public IntegerArgumentType instantiate(final CommandBuildContext context) {
55
			return IntegerArgumentType.integer(this.min, this.max);
56
		}
57
58
		@Override
59
		public ArgumentTypeInfo<IntegerArgumentType, ?> type() {
60
			return IntegerArgumentInfo.this;
61
		}
62
	}
63
}
64

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