Advertisement
Earthcomputer

Untitled

Sep 9th, 2021
866
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.43 KB | None | 0 0
  1. package net.earthcomputer.multiconnect.packets;
  2.  
  3. import it.unimi.dsi.fastutil.ints.IntList;
  4. import net.earthcomputer.multiconnect.ap.Message;
  5. import net.earthcomputer.multiconnect.ap.OnlyIf;
  6. import net.earthcomputer.multiconnect.ap.Polymorphic;
  7. import net.earthcomputer.multiconnect.ap.Type;
  8. import net.earthcomputer.multiconnect.ap.Types;
  9. import net.minecraft.util.Identifier;
  10.  
  11. import java.util.List;
  12.  
  13. @Message
  14. public class SPacketCommandTree {
  15.     public List<Node> nodes;
  16.     public int rootIndex;
  17.  
  18.     public static class Node {
  19.         public int flags;
  20.         public IntList children;
  21.         @OnlyIf(field = "flags", condition = "isRedirect")
  22.         public int redirectNode;
  23.         @OnlyIf(field = "flags", condition = "isArgumentOrLiteral")
  24.         public String name;
  25.         @OnlyIf(field = "flags", condition = "isArgument")
  26.         public Argument argument;
  27.         @OnlyIf(field = "flags", condition = "hasSuggestions")
  28.         public Identifier suggestionsProvider;
  29.  
  30.         public static boolean isRedirect(int flags) {
  31.             return (flags & 8) != 0;
  32.         }
  33.  
  34.         public static boolean isArgumentOrLiteral(int flags) {
  35.             int type = flags & 3;
  36.             return type == 1 || type == 2;
  37.         }
  38.  
  39.         public static boolean isArgument(int flags) {
  40.             return (flags & 3) == 2;
  41.         }
  42.  
  43.         public static boolean hasSuggestions(int flags) {
  44.             return (flags & 16) != 0;
  45.         }
  46.     }
  47.  
  48.     @Polymorphic
  49.     public static abstract class Argument {
  50.         public Identifier parser;
  51.     }
  52.  
  53.     @Polymorphic(stringValue = "brigadier:double")
  54.     public static class DoubleArgument extends Argument {
  55.         public byte flags;
  56.         @OnlyIf(field = "flags", condition = "hasMin")
  57.         public double min;
  58.         @OnlyIf(field = "flags", condition = "hasMax")
  59.         public double max;
  60.  
  61.         public static boolean hasMin(byte flags) {
  62.             return (flags & 1) != 0;
  63.         }
  64.  
  65.         public static boolean hasMax(byte flags) {
  66.             return (flags & 2) != 0;
  67.         }
  68.     }
  69.  
  70.     @Polymorphic(stringValue = "brigadier:float")
  71.     public static class FloatArgument extends Argument {
  72.         public byte flags;
  73.         @OnlyIf(field = "flags", condition = "hasMin")
  74.         public float min;
  75.         @OnlyIf(field = "flags", condition = "hasMax")
  76.         public float max;
  77.  
  78.         public static boolean hasMin(byte flags) {
  79.             return (flags & 1) != 0;
  80.         }
  81.  
  82.         public static boolean hasMax(byte flags) {
  83.             return (flags & 2) != 0;
  84.         }
  85.     }
  86.  
  87.     @Polymorphic(stringValue = "brigadier:integer")
  88.     public static class IntArgument extends Argument {
  89.         public byte flags;
  90.         @OnlyIf(field = "flags", condition = "hasMin")
  91.         @Type(Types.INT)
  92.         public int min;
  93.         @OnlyIf(field = "flags", condition = "hasMax")
  94.         @Type(Types.INT)
  95.         public int max;
  96.  
  97.         public static boolean hasMin(byte flags) {
  98.             return (flags & 1) != 0;
  99.         }
  100.  
  101.         public static boolean hasMax(byte flags) {
  102.             return (flags & 2) != 0;
  103.         }
  104.     }
  105.  
  106.     @Polymorphic(stringValue = "brigadier:long")
  107.     public static class LongArgument extends Argument {
  108.         public byte flags;
  109.         @OnlyIf(field = "flags", condition = "hasMin")
  110.         public long min;
  111.         @OnlyIf(field = "flags", condition = "hasMax")
  112.         public long max;
  113.  
  114.         public static boolean hasMin(byte flags) {
  115.             return (flags & 1) != 0;
  116.         }
  117.  
  118.         public static boolean hasMax(byte flags) {
  119.             return (flags & 2) != 0;
  120.         }
  121.     }
  122.  
  123.     @Polymorphic(stringValue = "brigadier:string")
  124.     public static class StringArgument extends Argument {
  125.         public Type type;
  126.         public enum Type {
  127.             SINGLE_WORD, QUOTABLE_PHRASE, GREEDY_PHRASE
  128.         }
  129.     }
  130.  
  131.     @Polymorphic(stringValue = "minecraft:entity")
  132.     public static class EntityArgument extends Argument {
  133.         public byte flags;
  134.     }
  135.  
  136.     @Polymorphic(stringValue = "minecraft:score_holder")
  137.     public static class ScoreHolderArgument extends Argument {
  138.         public byte flags;
  139.     }
  140.  
  141.     @Polymorphic(stringValue = "minecraft:range")
  142.     public static class RangeArgument extends Argument {
  143.         public boolean decimals;
  144.     }
  145.  
  146.     @Polymorphic(otherwise = true)
  147.     public static class ConstantArgument extends Argument {
  148.     }
  149. }
  150.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement