Update entity data serializers to 1.21.5
This commit is contained in:
11 files changed
+223
-7
No files matched your search
+9
@@ -27,12 +27,21 @@ import com.github.retrooper.packetevents.protocol.nbt.NBTString;
|
||||
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
|
||||
import com.github.retrooper.packetevents.resources.ResourceLocation;
|
||||
import com.github.retrooper.packetevents.util.mappings.TypesBuilderData;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface CatVariant extends MappedEntity, CopyableEntity<CatVariant>, DeepComparableEntity {
|
||||
|
||||
ResourceLocation getAssetId();
|
||||
|
||||
static CatVariant read(PacketWrapper<?> wrapper) {
|
||||
return wrapper.readMappedEntity(CatVariants.getRegistry());
|
||||
}
|
||||
|
||||
static void write(PacketWrapper<?> wrapper, CatVariant variant) {
|
||||
wrapper.writeMappedEntity(variant);
|
||||
}
|
||||
|
||||
static CatVariant decode(NBT nbt, ClientVersion version, @Nullable TypesBuilderData data) {
|
||||
NBTCompound compound = (NBTCompound) nbt;
|
||||
ResourceLocation assetId = new ResourceLocation(compound.getStringTagValueOrThrow("asset_id"));
|
||||
|
||||
+9
@@ -28,6 +28,7 @@ import com.github.retrooper.packetevents.protocol.player.ClientVersion;
|
||||
import com.github.retrooper.packetevents.resources.ResourceLocation;
|
||||
import com.github.retrooper.packetevents.util.adventure.AdventureIndexUtil;
|
||||
import com.github.retrooper.packetevents.util.mappings.TypesBuilderData;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import net.kyori.adventure.util.Index;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -37,6 +38,14 @@ public interface ChickenVariant extends MappedEntity, CopyableEntity<ChickenVari
|
||||
|
||||
ResourceLocation getAssetId();
|
||||
|
||||
static ChickenVariant read(PacketWrapper<?> wrapper) {
|
||||
return wrapper.readMappedEntity(ChickenVariants.getRegistry());
|
||||
}
|
||||
|
||||
static void write(PacketWrapper<?> wrapper, ChickenVariant variant) {
|
||||
wrapper.writeMappedEntity(variant);
|
||||
}
|
||||
|
||||
static ChickenVariant decode(NBT nbt, ClientVersion version, @Nullable TypesBuilderData data) {
|
||||
NBTCompound compound = (NBTCompound) nbt;
|
||||
String modelTypeString = compound.getStringTagValueOrNull("model");
|
||||
|
||||
+9
@@ -28,6 +28,7 @@ import com.github.retrooper.packetevents.protocol.player.ClientVersion;
|
||||
import com.github.retrooper.packetevents.resources.ResourceLocation;
|
||||
import com.github.retrooper.packetevents.util.adventure.AdventureIndexUtil;
|
||||
import com.github.retrooper.packetevents.util.mappings.TypesBuilderData;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import net.kyori.adventure.util.Index;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -37,6 +38,14 @@ public interface CowVariant extends MappedEntity, CopyableEntity<CowVariant>, De
|
||||
|
||||
ResourceLocation getAssetId();
|
||||
|
||||
static CowVariant read(PacketWrapper<?> wrapper) {
|
||||
return wrapper.readMappedEntity(CowVariants.getRegistry());
|
||||
}
|
||||
|
||||
static void write(PacketWrapper<?> wrapper, CowVariant variant) {
|
||||
wrapper.writeMappedEntity(variant);
|
||||
}
|
||||
|
||||
static CowVariant decode(NBT nbt, ClientVersion version, @Nullable TypesBuilderData data) {
|
||||
NBTCompound compound = (NBTCompound) nbt;
|
||||
String modelTypeString = compound.getStringTagValueOrNull("model");
|
||||
|
||||
+1
-1
@@ -52,4 +52,4 @@ public class EntityData {
|
||||
public void setValue(Object value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
+75
-6
@@ -20,15 +20,23 @@ package com.github.retrooper.packetevents.protocol.entity.data;
|
||||
|
||||
import com.github.retrooper.packetevents.manager.server.ServerVersion;
|
||||
import com.github.retrooper.packetevents.protocol.entity.armadillo.ArmadilloState;
|
||||
import com.github.retrooper.packetevents.protocol.entity.cat.CatVariant;
|
||||
import com.github.retrooper.packetevents.protocol.entity.chicken.ChickenVariant;
|
||||
import com.github.retrooper.packetevents.protocol.entity.cow.CowVariant;
|
||||
import com.github.retrooper.packetevents.protocol.entity.frog.FrogVariant;
|
||||
import com.github.retrooper.packetevents.protocol.entity.pig.PigVariant;
|
||||
import com.github.retrooper.packetevents.protocol.entity.pose.EntityPose;
|
||||
import com.github.retrooper.packetevents.protocol.entity.sniffer.SnifferState;
|
||||
import com.github.retrooper.packetevents.protocol.entity.villager.VillagerData;
|
||||
import com.github.retrooper.packetevents.protocol.entity.wolfvariant.WolfSoundVariant;
|
||||
import com.github.retrooper.packetevents.protocol.entity.wolfvariant.WolfVariant;
|
||||
import com.github.retrooper.packetevents.protocol.item.ItemStack;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
|
||||
import com.github.retrooper.packetevents.protocol.particle.Particle;
|
||||
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
|
||||
import com.github.retrooper.packetevents.protocol.world.BlockFace;
|
||||
import com.github.retrooper.packetevents.protocol.world.WorldBlockPosition;
|
||||
import com.github.retrooper.packetevents.protocol.world.painting.PaintingVariant;
|
||||
import com.github.retrooper.packetevents.resources.ResourceLocation;
|
||||
import com.github.retrooper.packetevents.util.Quaternion4f;
|
||||
import com.github.retrooper.packetevents.util.Vector3f;
|
||||
@@ -72,10 +80,16 @@ public final class EntityDataTypes {
|
||||
|
||||
public static final EntityDataType<String> STRING = define("string", PacketWrapper::readString, PacketWrapper::writeString);
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #ADV_COMPONENT} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public static final EntityDataType<String> COMPONENT = define("component", PacketWrapper::readComponentJSON, PacketWrapper::writeComponentJSON);
|
||||
public static final EntityDataType<Component> ADV_COMPONENT = define("component", PacketWrapper::readComponent, PacketWrapper::writeComponent);
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #OPTIONAL_ADV_COMPONENT} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public static final EntityDataType<Optional<String>> OPTIONAL_COMPONENT = define("optional_component", readOptionalComponentJSONDeserializer(), writeOptionalComponentJSONSerializer());
|
||||
public static final EntityDataType<Optional<Component>> OPTIONAL_ADV_COMPONENT = define("optional_component", readOptionalComponentDeserializer(), writeOptionalComponentSerializer());
|
||||
@@ -155,9 +169,23 @@ public final class EntityDataTypes {
|
||||
return EntityPose.getById(wrapper.getServerVersion().toClientVersion(), id);
|
||||
}, (PacketWrapper<?> wrapper, EntityPose value) -> wrapper.writeVarInt(value.getId(wrapper.getServerVersion().toClientVersion())));
|
||||
|
||||
public static final EntityDataType<Integer> CAT_VARIANT = define("cat_variant_type", readIntDeserializer(), writeIntSerializer());
|
||||
/**
|
||||
* @deprecated use {@link #TYPED_CAT_VARIANT} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public static final EntityDataType<Integer> CAT_VARIANT =
|
||||
define("cat_variant_type", readIntDeserializer(), writeIntSerializer());
|
||||
public static final EntityDataType<CatVariant> TYPED_CAT_VARIANT =
|
||||
define("cat_variant_type", CatVariant::read, CatVariant::write);
|
||||
|
||||
public static final EntityDataType<Integer> FROG_VARIANT = define("frog_variant_type", readIntDeserializer(), writeIntSerializer());
|
||||
/**
|
||||
* @deprecated use {@link #TYPED_FROG_VARIANT} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public static final EntityDataType<Integer> FROG_VARIANT =
|
||||
define("frog_variant_type", readIntDeserializer(), writeIntSerializer());
|
||||
public static final EntityDataType<FrogVariant> TYPED_FROG_VARIANT =
|
||||
define("frog_variant_type", FrogVariant::read, FrogVariant::write);
|
||||
|
||||
public static final EntityDataType<Optional<WorldBlockPosition>> OPTIONAL_GLOBAL_POSITION = define("optional_global_position",
|
||||
(PacketWrapper<?> wrapper) -> Optional.ofNullable(wrapper.readOptional(w -> new WorldBlockPosition(new ResourceLocation(w.readString(32767)), w.readBlockPosition()))),
|
||||
@@ -166,7 +194,14 @@ public final class EntityDataTypes {
|
||||
w.writeBlockPosition(globalPos.getBlockPosition());
|
||||
}));
|
||||
|
||||
public static final EntityDataType<Integer> PAINTING_VARIANT_TYPE = define("painting_variant_type", readIntDeserializer(), writeIntSerializer());
|
||||
/**
|
||||
* @deprecated use {@link #PAINTING_VARIANT} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public static final EntityDataType<Integer> PAINTING_VARIANT_TYPE =
|
||||
define("painting_variant_type", readIntDeserializer(), writeIntSerializer());
|
||||
public static final EntityDataType<PaintingVariant> PAINTING_VARIANT =
|
||||
define("painting_variant_type", PaintingVariant::read, PaintingVariant::write);
|
||||
|
||||
public static final EntityDataType<SnifferState> SNIFFER_STATE = define("sniffer_state", (PacketWrapper<?> wrapper) -> {
|
||||
int id = wrapper.readVarInt();
|
||||
@@ -190,19 +225,53 @@ public final class EntityDataTypes {
|
||||
wrapper.writeFloat(value.getW());
|
||||
});
|
||||
|
||||
// Added in 1.20.5
|
||||
/**
|
||||
* Added with 1.20.5
|
||||
*/
|
||||
public static final EntityDataType<ArmadilloState> ARMADILLO_STATE = define("armadillo_state",
|
||||
(PacketWrapper<?> wrapper) -> ArmadilloState.values()[wrapper.readVarInt()],
|
||||
(PacketWrapper<?> wrapper, ArmadilloState value) -> wrapper.writeVarInt(value.ordinal())
|
||||
);
|
||||
|
||||
/**
|
||||
* Added with 1.20.5
|
||||
*/
|
||||
public static final EntityDataType<List<Particle<?>>> PARTICLES = define("particles",
|
||||
wrapper -> wrapper.readList(Particle::read),
|
||||
(wrapper, particles) -> wrapper.writeList(particles, Particle::write)
|
||||
);
|
||||
|
||||
/**
|
||||
* Added with 1.20.5
|
||||
*
|
||||
* @deprecated use {@link #TYPED_WOLF_VARIANT} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public static final EntityDataType<Integer> WOLF_VARIANT =
|
||||
define("wolf_variant_type", readIntDeserializer(), writeIntSerializer());
|
||||
/**
|
||||
* Added with 1.20.5
|
||||
*/
|
||||
public static final EntityDataType<WolfVariant> TYPED_WOLF_VARIANT =
|
||||
define("wolf_variant_type", WolfVariant::read, WolfVariant::write);
|
||||
/**
|
||||
* Added with 1.21.5
|
||||
*/
|
||||
public static final EntityDataType<CowVariant> COW_VARIANT =
|
||||
define("cow_variant_type", CowVariant::read, CowVariant::write);
|
||||
/**
|
||||
* Added with 1.21.5
|
||||
*/
|
||||
public static final EntityDataType<WolfSoundVariant> WOLF_SOUND_VARIANT =
|
||||
define("wolf_sound_variant_type", WolfSoundVariant::read, WolfSoundVariant::write);
|
||||
/**
|
||||
* Added with 1.21.5
|
||||
*/
|
||||
public static final EntityDataType<PigVariant> PIG_VARIANT =
|
||||
define("pig_variant", PigVariant::read, PigVariant::write);
|
||||
/**
|
||||
* Added with 1.21.5
|
||||
*/
|
||||
public static final EntityDataType<ChickenVariant> CHICKEN_VARIANT =
|
||||
define("chicken_variant", ChickenVariant::read, ChickenVariant::write);
|
||||
|
||||
private EntityDataTypes() {
|
||||
}
|
||||
|
||||
+9
@@ -27,12 +27,21 @@ import com.github.retrooper.packetevents.protocol.nbt.NBTString;
|
||||
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
|
||||
import com.github.retrooper.packetevents.resources.ResourceLocation;
|
||||
import com.github.retrooper.packetevents.util.mappings.TypesBuilderData;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface FrogVariant extends MappedEntity, CopyableEntity<FrogVariant>, DeepComparableEntity {
|
||||
|
||||
ResourceLocation getAssetId();
|
||||
|
||||
static FrogVariant read(PacketWrapper<?> wrapper) {
|
||||
return wrapper.readMappedEntity(FrogVariants.getRegistry());
|
||||
}
|
||||
|
||||
static void write(PacketWrapper<?> wrapper, FrogVariant variant) {
|
||||
wrapper.writeMappedEntity(variant);
|
||||
}
|
||||
|
||||
static FrogVariant decode(NBT nbt, ClientVersion version, @Nullable TypesBuilderData data) {
|
||||
NBTCompound compound = (NBTCompound) nbt;
|
||||
ResourceLocation assetId = new ResourceLocation(compound.getStringTagValueOrThrow("asset_id"));
|
||||
|
||||
+9
@@ -28,6 +28,7 @@ import com.github.retrooper.packetevents.protocol.player.ClientVersion;
|
||||
import com.github.retrooper.packetevents.resources.ResourceLocation;
|
||||
import com.github.retrooper.packetevents.util.adventure.AdventureIndexUtil;
|
||||
import com.github.retrooper.packetevents.util.mappings.TypesBuilderData;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import net.kyori.adventure.util.Index;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -37,6 +38,14 @@ public interface PigVariant extends MappedEntity, CopyableEntity<PigVariant>, De
|
||||
|
||||
ResourceLocation getAssetId();
|
||||
|
||||
static PigVariant read(PacketWrapper<?> wrapper) {
|
||||
return wrapper.readMappedEntity(PigVariants.getRegistry());
|
||||
}
|
||||
|
||||
static void write(PacketWrapper<?> wrapper, PigVariant variant) {
|
||||
wrapper.writeMappedEntity(variant);
|
||||
}
|
||||
|
||||
static PigVariant decode(NBT nbt, ClientVersion version, @Nullable TypesBuilderData data) {
|
||||
NBTCompound compound = (NBTCompound) nbt;
|
||||
String modelTypeString = compound.getStringTagValueOrNull("model");
|
||||
|
||||
+9
@@ -26,6 +26,7 @@ import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
|
||||
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
|
||||
import com.github.retrooper.packetevents.protocol.sound.Sound;
|
||||
import com.github.retrooper.packetevents.util.mappings.TypesBuilderData;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface WolfSoundVariant extends MappedEntity, CopyableEntity<WolfSoundVariant>, DeepComparableEntity {
|
||||
@@ -42,6 +43,14 @@ public interface WolfSoundVariant extends MappedEntity, CopyableEntity<WolfSound
|
||||
|
||||
Sound getWhineSound();
|
||||
|
||||
static WolfSoundVariant read(PacketWrapper<?> wrapper) {
|
||||
return wrapper.readMappedEntity(WolfSoundVariants.getRegistry());
|
||||
}
|
||||
|
||||
static void write(PacketWrapper<?> wrapper, WolfSoundVariant variant) {
|
||||
wrapper.writeMappedEntity(variant);
|
||||
}
|
||||
|
||||
static WolfSoundVariant decode(NBT nbt, ClientVersion version, @Nullable TypesBuilderData data) {
|
||||
NBTCompound compound = (NBTCompound) nbt;
|
||||
Sound ambientSound = Sound.decode(compound.getTagOrThrow("ambient_sound"), version);
|
||||
|
||||
+40
@@ -18,6 +18,7 @@
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.entity.wolfvariant;
|
||||
|
||||
import com.github.retrooper.packetevents.manager.server.ServerVersion;
|
||||
import com.github.retrooper.packetevents.protocol.mapper.CopyableEntity;
|
||||
import com.github.retrooper.packetevents.protocol.mapper.DeepComparableEntity;
|
||||
import com.github.retrooper.packetevents.protocol.mapper.MappedEntity;
|
||||
@@ -30,6 +31,7 @@ import com.github.retrooper.packetevents.protocol.world.biome.Biome;
|
||||
import com.github.retrooper.packetevents.protocol.world.biome.Biomes;
|
||||
import com.github.retrooper.packetevents.resources.ResourceLocation;
|
||||
import com.github.retrooper.packetevents.util.mappings.TypesBuilderData;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -47,6 +49,44 @@ public interface WolfVariant extends MappedEntity, CopyableEntity<WolfVariant>,
|
||||
@ApiStatus.Obsolete
|
||||
MappedEntitySet<Biome> getBiomes();
|
||||
|
||||
static WolfVariant read(PacketWrapper<?> wrapper) {
|
||||
if (wrapper.getServerVersion().isNewerThanOrEquals(ServerVersion.V_1_21_5)) {
|
||||
return wrapper.readMappedEntity(WolfVariants.getRegistry());
|
||||
}
|
||||
return wrapper.readMappedEntityOrDirect(WolfVariants.getRegistry(), WolfVariant::readDirect);
|
||||
}
|
||||
|
||||
static void write(PacketWrapper<?> wrapper, WolfVariant variant) {
|
||||
if (wrapper.getServerVersion().isNewerThanOrEquals(ServerVersion.V_1_21_5)) {
|
||||
wrapper.writeMappedEntity(variant);
|
||||
} else {
|
||||
wrapper.writeMappedEntityOrDirect(variant, WolfVariant::writeDirect);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removed with 1.21.5
|
||||
*/
|
||||
@ApiStatus.Obsolete
|
||||
static WolfVariant readDirect(PacketWrapper<?> wrapper) {
|
||||
ResourceLocation wildTexture = wrapper.readIdentifier();
|
||||
ResourceLocation tameTexture = wrapper.readIdentifier();
|
||||
ResourceLocation angryTexture = wrapper.readIdentifier();
|
||||
MappedEntitySet<Biome> biomes = MappedEntitySet.read(wrapper, Biomes.getRegistry());
|
||||
return new StaticWolfVariant(wildTexture, tameTexture, angryTexture, biomes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removed with 1.21.5
|
||||
*/
|
||||
@ApiStatus.Obsolete
|
||||
static void writeDirect(PacketWrapper<?> wrapper, WolfVariant variant) {
|
||||
wrapper.writeIdentifier(variant.getWildTexture());
|
||||
wrapper.writeIdentifier(variant.getTameTexture());
|
||||
wrapper.writeIdentifier(variant.getAngryTexture());
|
||||
MappedEntitySet.write(wrapper, variant.getBiomes());
|
||||
}
|
||||
|
||||
static WolfVariant decode(NBT nbt, ClientVersion version, @Nullable TypesBuilderData data) {
|
||||
NBTCompound compound = (NBTCompound) nbt;
|
||||
if (version.isOlderThan(ClientVersion.V_1_21_5)) {
|
||||
|
||||
+16
@@ -18,6 +18,7 @@
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.world.painting;
|
||||
|
||||
import com.github.retrooper.packetevents.manager.server.ServerVersion;
|
||||
import com.github.retrooper.packetevents.protocol.mapper.CopyableEntity;
|
||||
import com.github.retrooper.packetevents.protocol.mapper.DeepComparableEntity;
|
||||
import com.github.retrooper.packetevents.protocol.mapper.MappedEntity;
|
||||
@@ -39,6 +40,21 @@ public interface PaintingVariant extends MappedEntity, CopyableEntity<PaintingVa
|
||||
|
||||
ResourceLocation getAssetId();
|
||||
|
||||
static PaintingVariant read(PacketWrapper<?> wrapper) {
|
||||
if (wrapper.getServerVersion().isNewerThanOrEquals(ServerVersion.V_1_21)) {
|
||||
return wrapper.readMappedEntityOrDirect(PaintingVariants.getRegistry(), PaintingVariant::readDirect);
|
||||
}
|
||||
return wrapper.readMappedEntity(PaintingVariants.getRegistry());
|
||||
}
|
||||
|
||||
static void write(PacketWrapper<?> wrapper, PaintingVariant variant) {
|
||||
if (wrapper.getServerVersion().isNewerThanOrEquals(ServerVersion.V_1_21)) {
|
||||
wrapper.writeMappedEntityOrDirect(variant, PaintingVariant::writeDirect);
|
||||
} else {
|
||||
wrapper.writeMappedEntity(variant);
|
||||
}
|
||||
}
|
||||
|
||||
static PaintingVariant readDirect(PacketWrapper<?> wrapper) {
|
||||
int width = wrapper.readVarInt();
|
||||
int height = wrapper.readVarInt();
|
||||
|
||||
@@ -1,4 +1,41 @@
|
||||
{
|
||||
"V_1_21_5": [
|
||||
"byte",
|
||||
"int",
|
||||
"long",
|
||||
"float",
|
||||
"string",
|
||||
"component",
|
||||
"optional_component",
|
||||
"itemstack",
|
||||
"boolean",
|
||||
"rotation",
|
||||
"block_position",
|
||||
"optional_block_position",
|
||||
"block_face",
|
||||
"optional_uuid",
|
||||
"block_state",
|
||||
"optional_block_state",
|
||||
"nbt",
|
||||
"particle",
|
||||
"particles",
|
||||
"villager_data",
|
||||
"optional_int",
|
||||
"entity_pose",
|
||||
"cat_variant_type",
|
||||
"cow_variant_type",
|
||||
"wolf_variant_type",
|
||||
"wolf_sound_variant_type",
|
||||
"frog_variant_type",
|
||||
"pig_variant_type",
|
||||
"chicken_variant_type",
|
||||
"optional_global_position",
|
||||
"painting_variant_type",
|
||||
"sniffer_state",
|
||||
"armadillo_state",
|
||||
"vector3f",
|
||||
"quaternion"
|
||||
],
|
||||
"V_1_20_5": [
|
||||
"byte",
|
||||
"int",
|
||||
|
||||
Reference in new issue
Block a user