minecraft-src/net/minecraft/commands/synchronization/brigadier/LongArgumentInfo.java
2025-07-04 03:15:13 +03:00

63 lines
2.1 KiB
Java

package net.minecraft.commands.synchronization.brigadier;
import com.google.gson.JsonObject;
import com.mojang.brigadier.arguments.LongArgumentType;
import net.minecraft.commands.CommandBuildContext;
import net.minecraft.commands.synchronization.ArgumentTypeInfo;
import net.minecraft.commands.synchronization.ArgumentUtils;
import net.minecraft.network.FriendlyByteBuf;
public class LongArgumentInfo implements ArgumentTypeInfo<LongArgumentType, LongArgumentInfo.Template> {
public void serializeToNetwork(LongArgumentInfo.Template template, FriendlyByteBuf friendlyByteBuf) {
boolean bl = template.min != Long.MIN_VALUE;
boolean bl2 = template.max != Long.MAX_VALUE;
friendlyByteBuf.writeByte(ArgumentUtils.createNumberFlags(bl, bl2));
if (bl) {
friendlyByteBuf.writeLong(template.min);
}
if (bl2) {
friendlyByteBuf.writeLong(template.max);
}
}
public LongArgumentInfo.Template deserializeFromNetwork(FriendlyByteBuf friendlyByteBuf) {
byte b = friendlyByteBuf.readByte();
long l = ArgumentUtils.numberHasMin(b) ? friendlyByteBuf.readLong() : Long.MIN_VALUE;
long m = ArgumentUtils.numberHasMax(b) ? friendlyByteBuf.readLong() : Long.MAX_VALUE;
return new LongArgumentInfo.Template(l, m);
}
public void serializeToJson(LongArgumentInfo.Template template, JsonObject jsonObject) {
if (template.min != Long.MIN_VALUE) {
jsonObject.addProperty("min", template.min);
}
if (template.max != Long.MAX_VALUE) {
jsonObject.addProperty("max", template.max);
}
}
public LongArgumentInfo.Template unpack(LongArgumentType longArgumentType) {
return new LongArgumentInfo.Template(longArgumentType.getMinimum(), longArgumentType.getMaximum());
}
public final class Template implements net.minecraft.commands.synchronization.ArgumentTypeInfo.Template<LongArgumentType> {
final long min;
final long max;
Template(final long min, final long max) {
this.min = min;
this.max = max;
}
public LongArgumentType instantiate(CommandBuildContext commandBuildContext) {
return LongArgumentType.longArg(this.min, this.max);
}
@Override
public ArgumentTypeInfo<LongArgumentType, ?> type() {
return LongArgumentInfo.this;
}
}
}