63 lines
		
	
	
	
		
			2 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			63 lines
		
	
	
	
		
			2 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 buffer) {
 | |
| 		boolean bl = template.min != Long.MIN_VALUE;
 | |
| 		boolean bl2 = template.max != Long.MAX_VALUE;
 | |
| 		buffer.writeByte(ArgumentUtils.createNumberFlags(bl, bl2));
 | |
| 		if (bl) {
 | |
| 			buffer.writeLong(template.min);
 | |
| 		}
 | |
| 
 | |
| 		if (bl2) {
 | |
| 			buffer.writeLong(template.max);
 | |
| 		}
 | |
| 	}
 | |
| 
 | |
| 	public LongArgumentInfo.Template deserializeFromNetwork(FriendlyByteBuf buffer) {
 | |
| 		byte b = buffer.readByte();
 | |
| 		long l = ArgumentUtils.numberHasMin(b) ? buffer.readLong() : Long.MIN_VALUE;
 | |
| 		long m = ArgumentUtils.numberHasMax(b) ? buffer.readLong() : Long.MAX_VALUE;
 | |
| 		return new LongArgumentInfo.Template(l, m);
 | |
| 	}
 | |
| 
 | |
| 	public void serializeToJson(LongArgumentInfo.Template template, JsonObject json) {
 | |
| 		if (template.min != Long.MIN_VALUE) {
 | |
| 			json.addProperty("min", template.min);
 | |
| 		}
 | |
| 
 | |
| 		if (template.max != Long.MAX_VALUE) {
 | |
| 			json.addProperty("max", template.max);
 | |
| 		}
 | |
| 	}
 | |
| 
 | |
| 	public LongArgumentInfo.Template unpack(LongArgumentType argument) {
 | |
| 		return new LongArgumentInfo.Template(argument.getMinimum(), argument.getMaximum());
 | |
| 	}
 | |
| 
 | |
| 	public final class Template implements 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 context) {
 | |
| 			return LongArgumentType.longArg(this.min, this.max);
 | |
| 		}
 | |
| 
 | |
| 		@Override
 | |
| 		public ArgumentTypeInfo<LongArgumentType, ?> type() {
 | |
| 			return LongArgumentInfo.this;
 | |
| 		}
 | |
| 	}
 | |
| }
 |