2025-11-24 22:52:51 +03:00

77 lines
2.5 KiB
Java

/*
* Decompiled with CFR 0.152.
*
* Could not load the following classes:
* com.google.gson.JsonObject
* com.mojang.brigadier.arguments.FloatArgumentType
*/
package net.minecraft.commands.synchronization.brigadier;
import com.google.gson.JsonObject;
import com.mojang.brigadier.arguments.FloatArgumentType;
import net.minecraft.commands.CommandBuildContext;
import net.minecraft.commands.synchronization.ArgumentTypeInfo;
import net.minecraft.commands.synchronization.ArgumentUtils;
import net.minecraft.network.FriendlyByteBuf;
public class FloatArgumentInfo
implements ArgumentTypeInfo<FloatArgumentType, Template> {
@Override
public void serializeToNetwork(Template template, FriendlyByteBuf out) {
boolean hasMin = template.min != -3.4028235E38f;
boolean hasMax = template.max != Float.MAX_VALUE;
out.writeByte(ArgumentUtils.createNumberFlags(hasMin, hasMax));
if (hasMin) {
out.writeFloat(template.min);
}
if (hasMax) {
out.writeFloat(template.max);
}
}
@Override
public Template deserializeFromNetwork(FriendlyByteBuf in) {
byte flags = in.readByte();
float min = ArgumentUtils.numberHasMin(flags) ? in.readFloat() : -3.4028235E38f;
float max = ArgumentUtils.numberHasMax(flags) ? in.readFloat() : Float.MAX_VALUE;
return new Template(min, max);
}
@Override
public void serializeToJson(Template template, JsonObject out) {
if (template.min != -3.4028235E38f) {
out.addProperty("min", (Number)Float.valueOf(template.min));
}
if (template.max != Float.MAX_VALUE) {
out.addProperty("max", (Number)Float.valueOf(template.max));
}
}
@Override
public Template unpack(FloatArgumentType argument) {
return new Template(argument.getMinimum(), argument.getMaximum());
}
public final class Template
implements ArgumentTypeInfo.Template<FloatArgumentType> {
private final float min;
private final float max;
private Template(float min, float max) {
this.min = min;
this.max = max;
}
@Override
public FloatArgumentType instantiate(CommandBuildContext context) {
return FloatArgumentType.floatArg((float)this.min, (float)this.max);
}
@Override
public ArgumentTypeInfo<FloatArgumentType, ?> type() {
return FloatArgumentInfo.this;
}
}
}