Move serializer constants to appropriate class

This commit is contained in:
filoghost 2021-08-20 08:56:06 +02:00
parent 614a56ca8a
commit ad1cfe3f1f
2 changed files with 13 additions and 14 deletions

View File

@ -9,19 +9,12 @@ import net.minecraft.server.v1_8_R3.ItemStack;
class DataWatcherKey<T> {
private static final DataWatcherSerializer<Byte> BYTE_SERIALIZER =
new DataWatcherSerializer<>(0, PacketByteBuffer::writeByte);
private static final DataWatcherSerializer<String> STRING_SERIALIZER =
new DataWatcherSerializer<>(4, PacketByteBuffer::writeString);
private static final DataWatcherSerializer<ItemStack> ITEM_STACK_SERIALIZER =
new DataWatcherSerializer<>(5, PacketByteBuffer::writeItemStack);
static final DataWatcherKey<Byte> ENTITY_STATUS = new DataWatcherKey<>(0, BYTE_SERIALIZER);
static final DataWatcherKey<String> CUSTOM_NAME = new DataWatcherKey<>(2, STRING_SERIALIZER);
static final DataWatcherKey<Byte> CUSTOM_NAME_VISIBILITY = new DataWatcherKey<>(3, BYTE_SERIALIZER);
static final DataWatcherKey<ItemStack> ITEM_STACK = new DataWatcherKey<>(10, ITEM_STACK_SERIALIZER);
static final DataWatcherKey<Byte> ARMOR_STAND_STATUS = new DataWatcherKey<>(10, BYTE_SERIALIZER);
static final DataWatcherKey<Byte> SLIME_SIZE = new DataWatcherKey<>(16, BYTE_SERIALIZER);
static final DataWatcherKey<Byte> ENTITY_STATUS = new DataWatcherKey<>(0, DataWatcherSerializer.BYTE);
static final DataWatcherKey<String> CUSTOM_NAME = new DataWatcherKey<>(2, DataWatcherSerializer.STRING);
static final DataWatcherKey<Byte> CUSTOM_NAME_VISIBILITY = new DataWatcherKey<>(3, DataWatcherSerializer.BYTE);
static final DataWatcherKey<ItemStack> ITEM_STACK = new DataWatcherKey<>(10, DataWatcherSerializer.ITEM_STACK);
static final DataWatcherKey<Byte> ARMOR_STAND_STATUS = new DataWatcherKey<>(10, DataWatcherSerializer.BYTE);
static final DataWatcherKey<Byte> SLIME_SIZE = new DataWatcherKey<>(16, DataWatcherSerializer.BYTE);
private final int index;
private final DataWatcherSerializer<T> serializer;

View File

@ -5,14 +5,20 @@
*/
package me.filoghost.holographicdisplays.nms.v1_8_R3;
import net.minecraft.server.v1_8_R3.ItemStack;
import java.util.function.BiConsumer;
class DataWatcherSerializer<T> {
static final DataWatcherSerializer<Byte> BYTE = new DataWatcherSerializer<>(0, PacketByteBuffer::writeByte);
static final DataWatcherSerializer<String> STRING = new DataWatcherSerializer<>(4, PacketByteBuffer::writeString);
static final DataWatcherSerializer<ItemStack> ITEM_STACK = new DataWatcherSerializer<>(5, PacketByteBuffer::writeItemStack);
private final int typeID;
private final BiConsumer<PacketByteBuffer, T> serializeFunction;
DataWatcherSerializer(int typeID, BiConsumer<PacketByteBuffer, T> serializeFunction) {
private DataWatcherSerializer(int typeID, BiConsumer<PacketByteBuffer, T> serializeFunction) {
this.typeID = typeID;
this.serializeFunction = serializeFunction;
}