From d5cac99b5f358b6eed6938ad91984abd699b2e42 Mon Sep 17 00:00:00 2001 From: KennyTV Date: Mon, 31 May 2021 11:51:21 +0200 Subject: [PATCH] Reorder Type instances --- .../viaversion/viaversion/api/type/Type.java | 129 ++++++++---------- .../viaversion/api/type/types/ByteType.java | 3 +- .../viaversion/api/type/types/DoubleType.java | 3 +- .../viaversion/api/type/types/FloatType.java | 3 +- .../viaversion/api/type/types/IntType.java | 3 +- .../viaversion/api/type/types/LongType.java | 3 +- .../viaversion/api/type/types/ShortType.java | 3 +- .../api/type/types/UnsignedByteType.java | 3 +- .../api/type/types/UnsignedShortType.java | 3 +- .../viaversion/api/type/types/VarIntType.java | 3 +- .../api/type/types/VarLongType.java | 3 +- .../data/entity/EntityTrackerBase.java | 2 +- 12 files changed, 70 insertions(+), 91 deletions(-) diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/Type.java b/api/src/main/java/com/viaversion/viaversion/api/type/Type.java index 0218c27a7..a32158b3a 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/Type.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/Type.java @@ -75,99 +75,75 @@ import com.viaversion.viaversion.api.type.types.minecraft.VillagerDataType; import java.util.UUID; +/** + * Type for buffer reading and writing. + * + * @param read/written type + */ public abstract class Type implements ByteBufReader, ByteBufWriter { - /* Defined Types */ + public static final ByteType BYTE = new ByteType(); - /** - * @deprecated unreasonable overhead, use BYTE_ARRAY_PRIMITIVE - */ - @Deprecated - public static final Type BYTE_ARRAY = new ArrayType<>(Type.BYTE); + public static final UnsignedByteType UNSIGNED_BYTE = new UnsignedByteType(); public static final Type BYTE_ARRAY_PRIMITIVE = new ByteArrayType(); public static final Type SHORT_BYTE_ARRAY = new ShortByteArrayType(); public static final Type REMAINING_BYTES = new RemainingBytesType(); - public static final UnsignedByteType UNSIGNED_BYTE = new UnsignedByteType(); - /** - * @deprecated unreasonable overhead - */ - @Deprecated - public static final Type UNSIGNED_BYTE_ARRAY = new ArrayType<>(Type.UNSIGNED_BYTE); + public static final ShortType SHORT = new ShortType(); + public static final UnsignedShortType UNSIGNED_SHORT = new UnsignedShortType(); - public static final BooleanType BOOLEAN = new BooleanType(); - /** - * @deprecated unreasonable overhead - */ - @Deprecated - public static final Type BOOLEAN_ARRAY = new ArrayType<>(Type.BOOLEAN); - /* Number Types */ public static final IntType INT = new IntType(); - /** - * @deprecated unreasonable overhead - */ - @Deprecated - public static final Type INT_ARRAY = new ArrayType<>(Type.INT); - + public static final FloatType FLOAT = new FloatType(); public static final DoubleType DOUBLE = new DoubleType(); - /** - * @deprecated unreasonable overhead - */ - @Deprecated - public static final Type DOUBLE_ARRAY = new ArrayType<>(Type.DOUBLE); public static final LongType LONG = new LongType(); - /** - * @deprecated unreasonable overhead - */ - @Deprecated - public static final Type LONG_ARRAY = new ArrayType<>(Type.LONG); public static final Type LONG_ARRAY_PRIMITIVE = new LongArrayType(); - public static final FloatType FLOAT = new FloatType(); - /** - * @deprecated unreasonable overhead - */ - @Deprecated - public static final Type FLOAT_ARRAY = new ArrayType<>(Type.FLOAT); + public static final BooleanType BOOLEAN = new BooleanType(); - public static final ShortType SHORT = new ShortType(); - /** - * @deprecated unreasonable overhead - */ - @Deprecated - public static final Type SHORT_ARRAY = new ArrayType<>(Type.SHORT); - - public static final UnsignedShortType UNSIGNED_SHORT = new UnsignedShortType(); - /** - * @deprecated unreasonable overhead - */ - @Deprecated - public static final Type UNSIGNED_SHORT_ARRAY = new ArrayType<>(Type.UNSIGNED_SHORT); /* Other Types */ public static final Type COMPONENT = new ComponentType(); + public static final Type OPTIONAL_COMPONENT = new OptionalComponentType(); + public static final Type STRING = new StringType(); public static final Type STRING_ARRAY = new ArrayType<>(Type.STRING); public static final Type UUID = new UUIDType(); + public static final Type OPTIONAL_UUID = new OptUUIDType(); public static final Type UUID_INT_ARRAY = new UUIDIntArrayType(); public static final Type UUID_ARRAY = new ArrayType<>(Type.UUID); - /* Variable Types */ + public static final VarIntType VAR_INT = new VarIntType(); - /** - * @deprecated unreasonable overhead, use VAR_INT_ARRAY_PRIMITIVE - */ + public static final OptionalVarIntType OPTIONAL_VAR_INT = new OptionalVarIntType(); + public static final Type VAR_INT_ARRAY_PRIMITIVE = new VarIntArrayType(); + public static final VarLongType VAR_LONG = new VarLongType(); + + /* Boxed number array types */ + @Deprecated + public static final Type BYTE_ARRAY = new ArrayType<>(Type.BYTE); + @Deprecated + public static final Type UNSIGNED_BYTE_ARRAY = new ArrayType<>(Type.UNSIGNED_BYTE); + @Deprecated + public static final Type BOOLEAN_ARRAY = new ArrayType<>(Type.BOOLEAN); + @Deprecated + public static final Type INT_ARRAY = new ArrayType<>(Type.INT); + @Deprecated + public static final Type SHORT_ARRAY = new ArrayType<>(Type.SHORT); + @Deprecated + public static final Type UNSIGNED_SHORT_ARRAY = new ArrayType<>(Type.UNSIGNED_SHORT); + @Deprecated + public static final Type DOUBLE_ARRAY = new ArrayType<>(Type.DOUBLE); + @Deprecated + public static final Type LONG_ARRAY = new ArrayType<>(Type.LONG); + @Deprecated + public static final Type FLOAT_ARRAY = new ArrayType<>(Type.FLOAT); @Deprecated public static final Type VAR_INT_ARRAY = new ArrayType<>(Type.VAR_INT); - public static final Type VAR_INT_ARRAY_PRIMITIVE = new VarIntArrayType(); - public static final OptionalVarIntType OPTIONAL_VAR_INT = new OptionalVarIntType(); - public static final VarLongType VAR_LONG = new VarLongType(); - /** - * @deprecated unreasonable overhead - */ @Deprecated public static final Type VAR_LONG_ARRAY = new ArrayType<>(Type.VAR_LONG); + /* Special Types */ public static final VoidType NOTHING = new VoidType(); // This is purely used for remapping. + /* MC Types */ public static final Type POSITION = new PositionType(); public static final Type POSITION1_14 = new Position1_14Type(); @@ -176,14 +152,9 @@ public abstract class Type implements ByteBufReader, ByteBufWriter { public static final Type NBT = new NBTType(); public static final Type NBT_ARRAY = new ArrayType<>(Type.NBT); - public static final Type OPTIONAL_UUID = new OptUUIDType(); - public static final Type OPTIONAL_COMPONENT = new OptionalComponentType(); public static final Type OPTIONAL_POSITION = new OptPositionType(); public static final Type OPTIONAL_POSITION_1_14 = new OptPosition1_14Type(); - public static final Type ITEM = new ItemType(); - public static final Type ITEM_ARRAY = new ItemArrayType(); - public static final Type BLOCK_CHANGE_RECORD = new BlockChangeRecordType(); public static final Type BLOCK_CHANGE_RECORD_ARRAY = new ArrayType<>(Type.BLOCK_CHANGE_RECORD); @@ -192,6 +163,9 @@ public abstract class Type implements ByteBufReader, ByteBufWriter { public static final Type VILLAGER_DATA = new VillagerDataType(); + public static final Type ITEM = new ItemType(); + public static final Type ITEM_ARRAY = new ItemArrayType(); + /* 1.13 Flat Item (no data) */ public static final Type FLAT_ITEM = new FlatItemType(); public static final Type FLAT_VAR_INT_ITEM = new FlatVarIntItemType(); @@ -201,7 +175,6 @@ public abstract class Type implements ByteBufReader, ByteBufWriter { public static final Type FLAT_VAR_INT_ITEM_ARRAY_VAR_INT = new ArrayType<>(FLAT_VAR_INT_ITEM); /* Actual Class */ - private final Class outputClass; private final String typeName; @@ -214,14 +187,30 @@ public abstract class Type implements ByteBufReader, ByteBufWriter { this.typeName = typeName; } + /** + * Returns the output class type. + * + * @return output class type + */ public Class getOutputClass() { return outputClass; } + /** + * Returns the type name. + * + * @return type name + */ public String getTypeName() { return typeName; } + /** + * Returns the base class, useful when the output class is insufficient for type comparison. + * One such case are types with {{@link java.util.List}} as their output type. + * + * @return base class + */ public Class getBaseClass() { return this.getClass(); } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/ByteType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/ByteType.java index 4c27c8339..e5de0e7c8 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/ByteType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/ByteType.java @@ -46,8 +46,7 @@ public class ByteType extends Type implements TypeConverter { public Byte from(Object o) { if (o instanceof Number) { return ((Number) o).byteValue(); - } - if (o instanceof Boolean) { + } else if (o instanceof Boolean) { return (Boolean) o ? (byte) 1 : 0; } return (Byte) o; diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/DoubleType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/DoubleType.java index 541cdb54a..8ca637989 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/DoubleType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/DoubleType.java @@ -62,8 +62,7 @@ public class DoubleType extends Type implements TypeConverter { public Double from(Object o) { if (o instanceof Number) { return ((Number) o).doubleValue(); - } - if (o instanceof Boolean) { + } else if (o instanceof Boolean) { return (Boolean) o ? (byte) 1D : 0D; } return (Double) o; diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/FloatType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/FloatType.java index 357fe81b3..695d5d612 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/FloatType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/FloatType.java @@ -62,8 +62,7 @@ public class FloatType extends Type implements TypeConverter { public Float from(Object o) { if (o instanceof Number) { return ((Number) o).floatValue(); - } - if (o instanceof Boolean) { + } else if (o instanceof Boolean) { return ((Boolean) o) ? 1F : 0; } return (Float) o; diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/IntType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/IntType.java index 2a1ae7ba9..fce3b1e93 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/IntType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/IntType.java @@ -45,8 +45,7 @@ public class IntType extends Type implements TypeConverter { public Integer from(Object o) { if (o instanceof Number) { return ((Number) o).intValue(); - } - if (o instanceof Boolean) { + } else if (o instanceof Boolean) { return ((Boolean) o) ? 1 : 0; } return (Integer) o; diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/LongType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/LongType.java index 64ad3f48f..9f8b153ba 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/LongType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/LongType.java @@ -54,8 +54,7 @@ public class LongType extends Type implements TypeConverter { public Long from(Object o) { if (o instanceof Number) { return ((Number) o).longValue(); - } - if (o instanceof Boolean) { + } else if (o instanceof Boolean) { return ((Boolean) o) ? 1L : 0; } return (Long) o; diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/ShortType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/ShortType.java index 8d65502fe..ecbcbd1d2 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/ShortType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/ShortType.java @@ -62,8 +62,7 @@ public class ShortType extends Type implements TypeConverter { public Short from(Object o) { if (o instanceof Number) { return ((Number) o).shortValue(); - } - if (o instanceof Boolean) { + } else if (o instanceof Boolean) { return ((Boolean) o) ? (short) 1 : 0; } return (Short) o; diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/UnsignedByteType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/UnsignedByteType.java index 4c3ba14e5..02adc7758 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/UnsignedByteType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/UnsignedByteType.java @@ -45,8 +45,7 @@ public class UnsignedByteType extends Type implements TypeConverter implements TypeConverter implements TypeConverter public Integer from(Object o) { if (o instanceof Number) { return ((Number) o).intValue(); - } - if (o instanceof Boolean) { + } else if (o instanceof Boolean) { return ((Boolean) o) ? 1 : 0; } return (Integer) o; diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/VarLongType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/VarLongType.java index b4719ff39..5230a9906 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/VarLongType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/VarLongType.java @@ -84,8 +84,7 @@ public class VarLongType extends Type implements TypeConverter { public Long from(Object o) { if (o instanceof Number) { return ((Number) o).longValue(); - } - if (o instanceof Boolean) { + } else if (o instanceof Boolean) { return ((Boolean) o) ? 1L : 0L; } return (Long) o; diff --git a/common/src/main/java/com/viaversion/viaversion/data/entity/EntityTrackerBase.java b/common/src/main/java/com/viaversion/viaversion/data/entity/EntityTrackerBase.java index 76d092c14..a3e72184f 100644 --- a/common/src/main/java/com/viaversion/viaversion/data/entity/EntityTrackerBase.java +++ b/common/src/main/java/com/viaversion/viaversion/data/entity/EntityTrackerBase.java @@ -96,7 +96,7 @@ public class EntityTrackerBase implements EntityTracker, ClientEntityIdChangeLis public void setClientEntityId(int clientEntityId) { Preconditions.checkNotNull(playerType); entityTypes.put(clientEntityId, playerType); - if (entityData != null) { + if (this.clientEntityId != -1 && entityData != null) { StoredEntityData data = entityData.remove(this.clientEntityId); if (data != null) { entityData.put(clientEntityId, data);