mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2025-03-30 16:26:22 +02:00
Reorder Type instances
This commit is contained in:
parent
3618914ce9
commit
d5cac99b5f
api/src/main/java/com/viaversion/viaversion/api/type
Type.java
types
common/src/main/java/com/viaversion/viaversion/data/entity
@ -75,99 +75,75 @@ import com.viaversion.viaversion.api.type.types.minecraft.VillagerDataType;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Type for buffer reading and writing.
|
||||
*
|
||||
* @param <T> read/written type
|
||||
*/
|
||||
public abstract class Type<T> implements ByteBufReader<T>, ByteBufWriter<T> {
|
||||
/* Defined Types */
|
||||
|
||||
public static final ByteType BYTE = new ByteType();
|
||||
/**
|
||||
* @deprecated unreasonable overhead, use BYTE_ARRAY_PRIMITIVE
|
||||
*/
|
||||
@Deprecated
|
||||
public static final Type<Byte[]> BYTE_ARRAY = new ArrayType<>(Type.BYTE);
|
||||
public static final UnsignedByteType UNSIGNED_BYTE = new UnsignedByteType();
|
||||
public static final Type<byte[]> BYTE_ARRAY_PRIMITIVE = new ByteArrayType();
|
||||
public static final Type<byte[]> SHORT_BYTE_ARRAY = new ShortByteArrayType();
|
||||
public static final Type<byte[]> REMAINING_BYTES = new RemainingBytesType();
|
||||
|
||||
public static final UnsignedByteType UNSIGNED_BYTE = new UnsignedByteType();
|
||||
/**
|
||||
* @deprecated unreasonable overhead
|
||||
*/
|
||||
@Deprecated
|
||||
public static final Type<Short[]> 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[]> BOOLEAN_ARRAY = new ArrayType<>(Type.BOOLEAN);
|
||||
/* Number Types */
|
||||
public static final IntType INT = new IntType();
|
||||
/**
|
||||
* @deprecated unreasonable overhead
|
||||
*/
|
||||
@Deprecated
|
||||
public static final Type<Integer[]> 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[]> DOUBLE_ARRAY = new ArrayType<>(Type.DOUBLE);
|
||||
|
||||
public static final LongType LONG = new LongType();
|
||||
/**
|
||||
* @deprecated unreasonable overhead
|
||||
*/
|
||||
@Deprecated
|
||||
public static final Type<Long[]> LONG_ARRAY = new ArrayType<>(Type.LONG);
|
||||
public static final Type<long[]> LONG_ARRAY_PRIMITIVE = new LongArrayType();
|
||||
|
||||
public static final FloatType FLOAT = new FloatType();
|
||||
/**
|
||||
* @deprecated unreasonable overhead
|
||||
*/
|
||||
@Deprecated
|
||||
public static final Type<Float[]> 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[]> SHORT_ARRAY = new ArrayType<>(Type.SHORT);
|
||||
|
||||
public static final UnsignedShortType UNSIGNED_SHORT = new UnsignedShortType();
|
||||
/**
|
||||
* @deprecated unreasonable overhead
|
||||
*/
|
||||
@Deprecated
|
||||
public static final Type<Integer[]> UNSIGNED_SHORT_ARRAY = new ArrayType<>(Type.UNSIGNED_SHORT);
|
||||
/* Other Types */
|
||||
public static final Type<JsonElement> COMPONENT = new ComponentType();
|
||||
public static final Type<JsonElement> OPTIONAL_COMPONENT = new OptionalComponentType();
|
||||
|
||||
public static final Type<String> STRING = new StringType();
|
||||
public static final Type<String[]> STRING_ARRAY = new ArrayType<>(Type.STRING);
|
||||
|
||||
public static final Type<UUID> UUID = new UUIDType();
|
||||
public static final Type<UUID> OPTIONAL_UUID = new OptUUIDType();
|
||||
public static final Type<UUID> UUID_INT_ARRAY = new UUIDIntArrayType();
|
||||
public static final Type<UUID[]> 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<int[]> VAR_INT_ARRAY_PRIMITIVE = new VarIntArrayType();
|
||||
public static final VarLongType VAR_LONG = new VarLongType();
|
||||
|
||||
/* Boxed number array types */
|
||||
@Deprecated
|
||||
public static final Type<Byte[]> BYTE_ARRAY = new ArrayType<>(Type.BYTE);
|
||||
@Deprecated
|
||||
public static final Type<Short[]> UNSIGNED_BYTE_ARRAY = new ArrayType<>(Type.UNSIGNED_BYTE);
|
||||
@Deprecated
|
||||
public static final Type<Boolean[]> BOOLEAN_ARRAY = new ArrayType<>(Type.BOOLEAN);
|
||||
@Deprecated
|
||||
public static final Type<Integer[]> INT_ARRAY = new ArrayType<>(Type.INT);
|
||||
@Deprecated
|
||||
public static final Type<Short[]> SHORT_ARRAY = new ArrayType<>(Type.SHORT);
|
||||
@Deprecated
|
||||
public static final Type<Integer[]> UNSIGNED_SHORT_ARRAY = new ArrayType<>(Type.UNSIGNED_SHORT);
|
||||
@Deprecated
|
||||
public static final Type<Double[]> DOUBLE_ARRAY = new ArrayType<>(Type.DOUBLE);
|
||||
@Deprecated
|
||||
public static final Type<Long[]> LONG_ARRAY = new ArrayType<>(Type.LONG);
|
||||
@Deprecated
|
||||
public static final Type<Float[]> FLOAT_ARRAY = new ArrayType<>(Type.FLOAT);
|
||||
@Deprecated
|
||||
public static final Type<Integer[]> VAR_INT_ARRAY = new ArrayType<>(Type.VAR_INT);
|
||||
public static final Type<int[]> 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<Long[]> 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> POSITION = new PositionType();
|
||||
public static final Type<Position> POSITION1_14 = new Position1_14Type();
|
||||
@ -176,14 +152,9 @@ public abstract class Type<T> implements ByteBufReader<T>, ByteBufWriter<T> {
|
||||
public static final Type<CompoundTag> NBT = new NBTType();
|
||||
public static final Type<CompoundTag[]> NBT_ARRAY = new ArrayType<>(Type.NBT);
|
||||
|
||||
public static final Type<UUID> OPTIONAL_UUID = new OptUUIDType();
|
||||
public static final Type<JsonElement> OPTIONAL_COMPONENT = new OptionalComponentType();
|
||||
public static final Type<Position> OPTIONAL_POSITION = new OptPositionType();
|
||||
public static final Type<Position> OPTIONAL_POSITION_1_14 = new OptPosition1_14Type();
|
||||
|
||||
public static final Type<Item> ITEM = new ItemType();
|
||||
public static final Type<Item[]> ITEM_ARRAY = new ItemArrayType();
|
||||
|
||||
public static final Type<BlockChangeRecord> BLOCK_CHANGE_RECORD = new BlockChangeRecordType();
|
||||
public static final Type<BlockChangeRecord[]> BLOCK_CHANGE_RECORD_ARRAY = new ArrayType<>(Type.BLOCK_CHANGE_RECORD);
|
||||
|
||||
@ -192,6 +163,9 @@ public abstract class Type<T> implements ByteBufReader<T>, ByteBufWriter<T> {
|
||||
|
||||
public static final Type<VillagerData> VILLAGER_DATA = new VillagerDataType();
|
||||
|
||||
public static final Type<Item> ITEM = new ItemType();
|
||||
public static final Type<Item[]> ITEM_ARRAY = new ItemArrayType();
|
||||
|
||||
/* 1.13 Flat Item (no data) */
|
||||
public static final Type<Item> FLAT_ITEM = new FlatItemType();
|
||||
public static final Type<Item> FLAT_VAR_INT_ITEM = new FlatVarIntItemType();
|
||||
@ -201,7 +175,6 @@ public abstract class Type<T> implements ByteBufReader<T>, ByteBufWriter<T> {
|
||||
public static final Type<Item[]> FLAT_VAR_INT_ITEM_ARRAY_VAR_INT = new ArrayType<>(FLAT_VAR_INT_ITEM);
|
||||
|
||||
/* Actual Class */
|
||||
|
||||
private final Class<? super T> outputClass;
|
||||
private final String typeName;
|
||||
|
||||
@ -214,14 +187,30 @@ public abstract class Type<T> implements ByteBufReader<T>, ByteBufWriter<T> {
|
||||
this.typeName = typeName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the output class type.
|
||||
*
|
||||
* @return output class type
|
||||
*/
|
||||
public Class<? super T> 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<? extends Type> getBaseClass() {
|
||||
return this.getClass();
|
||||
}
|
||||
|
@ -46,8 +46,7 @@ public class ByteType extends Type<Byte> implements TypeConverter<Byte> {
|
||||
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;
|
||||
|
@ -62,8 +62,7 @@ public class DoubleType extends Type<Double> implements TypeConverter<Double> {
|
||||
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;
|
||||
|
@ -62,8 +62,7 @@ public class FloatType extends Type<Float> implements TypeConverter<Float> {
|
||||
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;
|
||||
|
@ -45,8 +45,7 @@ public class IntType extends Type<Integer> implements TypeConverter<Integer> {
|
||||
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;
|
||||
|
@ -54,8 +54,7 @@ public class LongType extends Type<Long> implements TypeConverter<Long> {
|
||||
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;
|
||||
|
@ -62,8 +62,7 @@ public class ShortType extends Type<Short> implements TypeConverter<Short> {
|
||||
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;
|
||||
|
@ -45,8 +45,7 @@ public class UnsignedByteType extends Type<Short> implements TypeConverter<Short
|
||||
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;
|
||||
|
@ -45,8 +45,7 @@ public class UnsignedShortType extends Type<Integer> implements TypeConverter<In
|
||||
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;
|
||||
|
@ -86,8 +86,7 @@ public class VarIntType extends Type<Integer> implements TypeConverter<Integer>
|
||||
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;
|
||||
|
@ -84,8 +84,7 @@ public class VarLongType extends Type<Long> implements TypeConverter<Long> {
|
||||
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;
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user