2016-03-18 22:18:48 +01:00
|
|
|
package us.myles.ViaVersion.api.type;
|
2016-03-12 00:07:13 +01:00
|
|
|
|
|
|
|
|
2017-05-14 14:34:51 +02:00
|
|
|
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
2020-06-25 16:22:53 +02:00
|
|
|
import com.google.gson.JsonElement;
|
2020-07-08 21:01:18 +02:00
|
|
|
import us.myles.ViaVersion.api.minecraft.BlockChangeRecord;
|
|
|
|
import us.myles.ViaVersion.api.minecraft.EulerAngle;
|
|
|
|
import us.myles.ViaVersion.api.minecraft.Position;
|
|
|
|
import us.myles.ViaVersion.api.minecraft.Vector;
|
|
|
|
import us.myles.ViaVersion.api.minecraft.VillagerData;
|
2016-03-18 22:18:48 +01:00
|
|
|
import us.myles.ViaVersion.api.minecraft.item.Item;
|
2020-07-08 21:01:18 +02:00
|
|
|
import us.myles.ViaVersion.api.type.types.ArrayType;
|
|
|
|
import us.myles.ViaVersion.api.type.types.BooleanType;
|
|
|
|
import us.myles.ViaVersion.api.type.types.ByteArrayType;
|
|
|
|
import us.myles.ViaVersion.api.type.types.ByteType;
|
|
|
|
import us.myles.ViaVersion.api.type.types.ComponentType;
|
|
|
|
import us.myles.ViaVersion.api.type.types.DoubleType;
|
|
|
|
import us.myles.ViaVersion.api.type.types.FloatType;
|
|
|
|
import us.myles.ViaVersion.api.type.types.IntType;
|
2020-12-02 21:57:32 +01:00
|
|
|
import us.myles.ViaVersion.api.type.types.LongArrayType;
|
2020-07-08 21:01:18 +02:00
|
|
|
import us.myles.ViaVersion.api.type.types.LongType;
|
|
|
|
import us.myles.ViaVersion.api.type.types.RemainingBytesType;
|
|
|
|
import us.myles.ViaVersion.api.type.types.ShortType;
|
|
|
|
import us.myles.ViaVersion.api.type.types.StringType;
|
|
|
|
import us.myles.ViaVersion.api.type.types.UUIDIntArrayType;
|
|
|
|
import us.myles.ViaVersion.api.type.types.UUIDType;
|
|
|
|
import us.myles.ViaVersion.api.type.types.UnsignedByteType;
|
|
|
|
import us.myles.ViaVersion.api.type.types.UnsignedShortType;
|
|
|
|
import us.myles.ViaVersion.api.type.types.VarIntArrayType;
|
|
|
|
import us.myles.ViaVersion.api.type.types.VarIntType;
|
|
|
|
import us.myles.ViaVersion.api.type.types.VarLongType;
|
|
|
|
import us.myles.ViaVersion.api.type.types.VoidType;
|
|
|
|
import us.myles.ViaVersion.api.type.types.minecraft.BlockChangeRecordType;
|
|
|
|
import us.myles.ViaVersion.api.type.types.minecraft.EulerAngleType;
|
|
|
|
import us.myles.ViaVersion.api.type.types.minecraft.FlatItemArrayType;
|
|
|
|
import us.myles.ViaVersion.api.type.types.minecraft.FlatItemType;
|
|
|
|
import us.myles.ViaVersion.api.type.types.minecraft.FlatVarIntItemArrayType;
|
|
|
|
import us.myles.ViaVersion.api.type.types.minecraft.FlatVarIntItemType;
|
|
|
|
import us.myles.ViaVersion.api.type.types.minecraft.ItemArrayType;
|
|
|
|
import us.myles.ViaVersion.api.type.types.minecraft.ItemType;
|
|
|
|
import us.myles.ViaVersion.api.type.types.minecraft.NBTType;
|
|
|
|
import us.myles.ViaVersion.api.type.types.minecraft.OptPosition1_14Type;
|
|
|
|
import us.myles.ViaVersion.api.type.types.minecraft.OptPositionType;
|
|
|
|
import us.myles.ViaVersion.api.type.types.minecraft.OptUUIDType;
|
|
|
|
import us.myles.ViaVersion.api.type.types.minecraft.OptionalComponentType;
|
|
|
|
import us.myles.ViaVersion.api.type.types.minecraft.OptionalVarIntType;
|
|
|
|
import us.myles.ViaVersion.api.type.types.minecraft.Position1_14Type;
|
|
|
|
import us.myles.ViaVersion.api.type.types.minecraft.PositionType;
|
|
|
|
import us.myles.ViaVersion.api.type.types.minecraft.VarLongBlockChangeRecordType;
|
|
|
|
import us.myles.ViaVersion.api.type.types.minecraft.VectorType;
|
|
|
|
import us.myles.ViaVersion.api.type.types.minecraft.VillagerDataType;
|
2016-03-12 00:07:13 +01:00
|
|
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
public abstract class Type<T> implements ByteBufReader<T>, ByteBufWriter<T> {
|
|
|
|
/* Defined Types */
|
|
|
|
public static final Type<Byte> BYTE = new ByteType();
|
2019-11-02 14:00:27 +01:00
|
|
|
/**
|
|
|
|
* @deprecated unreasonable overhead, use BYTE_ARRAY_PRIMITIVE
|
|
|
|
*/
|
|
|
|
@Deprecated
|
2016-03-12 00:07:13 +01:00
|
|
|
public static final Type<Byte[]> BYTE_ARRAY = new ArrayType<>(Type.BYTE);
|
2019-11-02 14:00:27 +01:00
|
|
|
public static final Type<byte[]> BYTE_ARRAY_PRIMITIVE = new ByteArrayType();
|
2016-03-12 00:07:13 +01:00
|
|
|
|
2016-03-13 18:01:36 +01:00
|
|
|
public static final Type<byte[]> REMAINING_BYTES = new RemainingBytesType();
|
|
|
|
|
2016-03-12 00:07:13 +01:00
|
|
|
public static final Type<Short> UNSIGNED_BYTE = new UnsignedByteType();
|
2019-11-02 14:00:27 +01:00
|
|
|
/**
|
|
|
|
* @deprecated unreasonable overhead
|
|
|
|
*/
|
|
|
|
@Deprecated
|
2016-03-12 00:07:13 +01:00
|
|
|
public static final Type<Short[]> UNSIGNED_BYTE_ARRAY = new ArrayType<>(Type.UNSIGNED_BYTE);
|
|
|
|
|
|
|
|
public static final Type<Boolean> BOOLEAN = new BooleanType();
|
2019-11-02 14:00:27 +01:00
|
|
|
/**
|
|
|
|
* @deprecated unreasonable overhead
|
|
|
|
*/
|
|
|
|
@Deprecated
|
2016-03-12 00:07:13 +01:00
|
|
|
public static final Type<Boolean[]> BOOLEAN_ARRAY = new ArrayType<>(Type.BOOLEAN);
|
|
|
|
/* Number Types */
|
|
|
|
public static final Type<Integer> INT = new IntType();
|
2019-11-02 14:00:27 +01:00
|
|
|
/**
|
|
|
|
* @deprecated unreasonable overhead
|
|
|
|
*/
|
|
|
|
@Deprecated
|
2016-03-12 00:07:13 +01:00
|
|
|
public static final Type<Integer[]> INT_ARRAY = new ArrayType<>(Type.INT);
|
|
|
|
|
|
|
|
public static final Type<Double> DOUBLE = new DoubleType();
|
2019-11-02 14:00:27 +01:00
|
|
|
/**
|
|
|
|
* @deprecated unreasonable overhead
|
|
|
|
*/
|
|
|
|
@Deprecated
|
2016-03-12 00:07:13 +01:00
|
|
|
public static final Type<Double[]> DOUBLE_ARRAY = new ArrayType<>(Type.DOUBLE);
|
|
|
|
|
2020-12-02 21:57:32 +01:00
|
|
|
public static final LongType LONG = new LongType();
|
2019-11-02 14:00:27 +01:00
|
|
|
/**
|
|
|
|
* @deprecated unreasonable overhead
|
|
|
|
*/
|
|
|
|
@Deprecated
|
2016-03-12 00:07:13 +01:00
|
|
|
public static final Type<Long[]> LONG_ARRAY = new ArrayType<>(Type.LONG);
|
2020-12-02 21:57:32 +01:00
|
|
|
public static final Type<long[]> LONG_ARRAY_PRIMITIVE = new LongArrayType();
|
2016-03-12 00:07:13 +01:00
|
|
|
|
2020-06-18 19:38:47 +02:00
|
|
|
public static final FloatType FLOAT = new FloatType();
|
2019-11-02 14:00:27 +01:00
|
|
|
/**
|
|
|
|
* @deprecated unreasonable overhead
|
|
|
|
*/
|
|
|
|
@Deprecated
|
2016-03-12 00:07:13 +01:00
|
|
|
public static final Type<Float[]> FLOAT_ARRAY = new ArrayType<>(Type.FLOAT);
|
|
|
|
|
2020-06-18 19:38:47 +02:00
|
|
|
public static final ShortType SHORT = new ShortType();
|
2019-11-02 14:00:27 +01:00
|
|
|
/**
|
|
|
|
* @deprecated unreasonable overhead
|
|
|
|
*/
|
|
|
|
@Deprecated
|
2016-03-12 00:07:13 +01:00
|
|
|
public static final Type<Short[]> SHORT_ARRAY = new ArrayType<>(Type.SHORT);
|
2016-03-14 13:40:23 +01:00
|
|
|
|
|
|
|
public static final Type<Integer> UNSIGNED_SHORT = new UnsignedShortType();
|
2019-11-02 14:00:27 +01:00
|
|
|
/**
|
|
|
|
* @deprecated unreasonable overhead
|
|
|
|
*/
|
|
|
|
@Deprecated
|
2016-03-14 13:40:23 +01:00
|
|
|
public static final Type<Integer[]> UNSIGNED_SHORT_ARRAY = new ArrayType<>(Type.UNSIGNED_SHORT);
|
2016-03-12 00:07:13 +01:00
|
|
|
/* Other Types */
|
2020-06-25 16:22:53 +02:00
|
|
|
public static final Type<JsonElement> COMPONENT = new ComponentType();
|
2016-03-12 00:07:13 +01:00
|
|
|
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();
|
2020-03-18 19:15:58 +01:00
|
|
|
public static final Type<UUID> UUID_INT_ARRAY = new UUIDIntArrayType();
|
2016-03-12 00:07:13 +01:00
|
|
|
public static final Type<UUID[]> UUID_ARRAY = new ArrayType<>(Type.UUID);
|
|
|
|
/* Variable Types */
|
2020-06-18 19:38:47 +02:00
|
|
|
public static final VarIntType VAR_INT = new VarIntType();
|
2019-11-02 14:00:27 +01:00
|
|
|
/**
|
|
|
|
* @deprecated unreasonable overhead, use VAR_INT_ARRAY_PRIMITIVE
|
|
|
|
*/
|
|
|
|
@Deprecated
|
2016-03-12 00:07:13 +01:00
|
|
|
public static final Type<Integer[]> VAR_INT_ARRAY = new ArrayType<>(Type.VAR_INT);
|
2019-11-02 14:00:27 +01:00
|
|
|
public static final Type<int[]> VAR_INT_ARRAY_PRIMITIVE = new VarIntArrayType();
|
2019-02-13 19:42:59 +01:00
|
|
|
public static final Type<Integer> OPTIONAL_VAR_INT = new OptionalVarIntType();
|
2020-07-08 21:01:18 +02:00
|
|
|
public static final VarLongType VAR_LONG = new VarLongType();
|
2019-11-02 14:00:27 +01:00
|
|
|
/**
|
|
|
|
* @deprecated unreasonable overhead
|
|
|
|
*/
|
|
|
|
@Deprecated
|
2018-06-27 14:39:38 +02:00
|
|
|
public static final Type<Long[]> VAR_LONG_ARRAY = new ArrayType<>(Type.VAR_LONG);
|
2016-03-12 00:07:13 +01:00
|
|
|
/* Special Types */
|
|
|
|
public static final Type<Void> NOTHING = new VoidType(); // This is purely used for remapping.
|
|
|
|
/* MC Types */
|
2016-03-12 23:33:43 +01:00
|
|
|
public static final Type<Position> POSITION = new PositionType();
|
2018-10-26 18:36:35 +02:00
|
|
|
public static final Type<Position> POSITION1_14 = new Position1_14Type();
|
2016-03-12 23:33:43 +01:00
|
|
|
public static final Type<EulerAngle> ROTATION = new EulerAngleType();
|
|
|
|
public static final Type<Vector> VECTOR = new VectorType();
|
2016-03-14 17:09:50 +01:00
|
|
|
public static final Type<CompoundTag> NBT = new NBTType();
|
2016-06-22 19:20:42 +02:00
|
|
|
public static final Type<CompoundTag[]> NBT_ARRAY = new ArrayType<>(Type.NBT);
|
2016-03-14 17:09:50 +01:00
|
|
|
|
2016-03-15 01:34:20 +01:00
|
|
|
public static final Type<UUID> OPTIONAL_UUID = new OptUUIDType();
|
2020-06-25 16:22:53 +02:00
|
|
|
public static final Type<JsonElement> OPTIONAL_COMPONENT = new OptionalComponentType();
|
2016-05-19 12:18:04 +02:00
|
|
|
public static final Type<Position> OPTIONAL_POSITION = new OptPositionType();
|
2019-02-13 19:42:59 +01:00
|
|
|
public static final Type<Position> OPTIONAL_POSITION_1_14 = new OptPosition1_14Type();
|
2016-03-15 01:34:20 +01:00
|
|
|
|
2016-03-14 17:09:50 +01:00
|
|
|
public static final Type<Item> ITEM = new ItemType();
|
2016-03-13 18:01:36 +01:00
|
|
|
public static final Type<Item[]> ITEM_ARRAY = new ItemArrayType();
|
2017-12-12 00:39:34 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2020-07-08 21:01:18 +02:00
|
|
|
public static final Type<BlockChangeRecord> VAR_LONG_BLOCK_CHANGE_RECORD = new VarLongBlockChangeRecordType();
|
|
|
|
public static final Type<BlockChangeRecord[]> VAR_LONG_BLOCK_CHANGE_RECORD_ARRAY = new ArrayType<>(Type.VAR_LONG_BLOCK_CHANGE_RECORD);
|
|
|
|
|
2019-01-09 19:50:27 +01:00
|
|
|
public static final Type<VillagerData> VILLAGER_DATA = new VillagerDataType();
|
|
|
|
|
2017-12-12 00:39:34 +01:00
|
|
|
/* 1.13 Flat Item (no data) */
|
|
|
|
public static final Type<Item> FLAT_ITEM = new FlatItemType();
|
2018-10-17 15:38:59 +02:00
|
|
|
public static final Type<Item> FLAT_VAR_INT_ITEM = new FlatVarIntItemType();
|
2017-12-12 00:39:34 +01:00
|
|
|
public static final Type<Item[]> FLAT_ITEM_ARRAY = new FlatItemArrayType();
|
2018-10-17 15:38:59 +02:00
|
|
|
public static final Type<Item[]> FLAT_VAR_INT_ITEM_ARRAY = new FlatVarIntItemArrayType();
|
2018-08-22 22:27:21 +02:00
|
|
|
public static final Type<Item[]> FLAT_ITEM_ARRAY_VAR_INT = new ArrayType<>(FLAT_ITEM);
|
2018-10-17 15:38:59 +02:00
|
|
|
public static final Type<Item[]> FLAT_VAR_INT_ITEM_ARRAY_VAR_INT = new ArrayType<>(FLAT_VAR_INT_ITEM);
|
2017-12-12 00:39:34 +01:00
|
|
|
|
2016-03-12 00:07:13 +01:00
|
|
|
/* Actual Class */
|
|
|
|
|
2016-03-12 23:33:43 +01:00
|
|
|
private final Class<? super T> outputClass;
|
2016-03-12 00:07:13 +01:00
|
|
|
private final String typeName;
|
|
|
|
|
2016-03-12 23:33:43 +01:00
|
|
|
public Type(Class<? super T> outputClass) {
|
2016-03-12 00:07:13 +01:00
|
|
|
this(outputClass.getSimpleName(), outputClass);
|
|
|
|
}
|
|
|
|
|
2016-03-12 23:33:43 +01:00
|
|
|
public Type(String typeName, Class<? super T> outputClass) {
|
2016-03-12 00:07:13 +01:00
|
|
|
this.outputClass = outputClass;
|
|
|
|
this.typeName = typeName;
|
2016-05-21 20:54:26 +02:00
|
|
|
}
|
|
|
|
|
2020-03-10 13:22:22 +01:00
|
|
|
public Class<? super T> getOutputClass() {
|
|
|
|
return outputClass;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getTypeName() {
|
|
|
|
return typeName;
|
|
|
|
}
|
|
|
|
|
2016-05-21 21:19:20 +02:00
|
|
|
public Class<? extends Type> getBaseClass() {
|
|
|
|
return this.getClass();
|
2016-03-12 00:07:13 +01:00
|
|
|
}
|
2016-03-30 16:58:31 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
2020-03-10 13:22:22 +01:00
|
|
|
return "Type|" + typeName;
|
2016-03-30 16:58:31 +02:00
|
|
|
}
|
2016-03-12 00:07:13 +01:00
|
|
|
}
|