From 1a24ce6d8798b9fba8529adead6a6f41ee00de24 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Wed, 15 May 2024 16:50:07 +0200 Subject: [PATCH] 24w20a --- .../rewriter/BlockItemPacketRewriter1_21.java | 8 +++ .../rewriter/EntityPacketRewriter1_21.java | 53 ++++++++++++------- gradle.properties | 2 +- gradle/libs.versions.toml | 2 +- 4 files changed, 43 insertions(+), 22 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/BlockItemPacketRewriter1_21.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/BlockItemPacketRewriter1_21.java index 6bb9d1b5..eec85715 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/BlockItemPacketRewriter1_21.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/BlockItemPacketRewriter1_21.java @@ -32,6 +32,7 @@ import com.viaversion.viaversion.api.minecraft.data.StructuredDataContainer; import com.viaversion.viaversion.api.minecraft.data.StructuredDataKey; import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.item.data.Enchantments; +import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_20_2; import com.viaversion.viaversion.api.type.types.version.Types1_20_5; import com.viaversion.viaversion.api.type.types.version.Types1_21; @@ -78,6 +79,13 @@ public final class BlockItemPacketRewriter1_21 extends BackwardsStructuredItemRe registerLevelParticles1_20_5(ClientboundPackets1_20_5.LEVEL_PARTICLES, Types1_21.PARTICLE, Types1_20_5.PARTICLE); registerExplosion(ClientboundPackets1_20_5.EXPLODE, Types1_21.PARTICLE, Types1_20_5.PARTICLE); + protocol.registerServerbound(ServerboundPackets1_20_5.USE_ITEM, wrapper -> { + wrapper.passthrough(Types.VAR_INT); // Hand + wrapper.passthrough(Types.VAR_INT); // Sequence + wrapper.write(Types.FLOAT, 0f); // Y rotation + wrapper.write(Types.FLOAT, 0f); // X rotation + }); + new RecipeRewriter1_20_3<>(protocol).register1_20_5(ClientboundPackets1_20_5.UPDATE_RECIPES); } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/EntityPacketRewriter1_21.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/EntityPacketRewriter1_21.java index dd3add0a..32391da9 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/EntityPacketRewriter1_21.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/EntityPacketRewriter1_21.java @@ -22,9 +22,13 @@ import com.viaversion.nbt.tag.Tag; import com.viaversion.viabackwards.api.rewriters.EntityRewriter; import com.viaversion.viabackwards.protocol.v1_21to1_20_5.Protocol1_21To1_20_5; import com.viaversion.viabackwards.protocol.v1_21to1_20_5.storage.EnchantmentsPaintingsStorage; +import com.viaversion.viaversion.api.minecraft.Holder; +import com.viaversion.viaversion.api.minecraft.PaintingVariant; import com.viaversion.viaversion.api.minecraft.RegistryEntry; +import com.viaversion.viaversion.api.minecraft.WolfVariant; import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5; +import com.viaversion.viaversion.api.minecraft.entitydata.EntityDataType; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.types.version.Types1_20_5; @@ -46,8 +50,8 @@ public final class EntityPacketRewriter1_21 extends EntityRewriter { + final EntityDataType type = data.dataType(); + if (type == Types1_21.ENTITY_DATA_TYPES.wolfVariantType) { + final Holder variant = data.value(); + if (variant.hasId()) { + data.setTypeAndValue(Types1_20_5.ENTITY_DATA_TYPES.wolfVariantType, variant); + } else { + event.cancel(); + } + } else if (type == Types1_21.ENTITY_DATA_TYPES.paintingVariantType) { + final Holder variant = data.value(); + if (variant.hasId()) { + final EnchantmentsPaintingsStorage storage = event.user().get(EnchantmentsPaintingsStorage.class); + final int mappedId = storage.mappedPainting(variant.id()); + data.setTypeAndValue(Types1_20_5.ENTITY_DATA_TYPES.paintingVariantType, mappedId); + } else { + event.cancel(); + } + } else { + data.setDataType(Types1_20_5.ENTITY_DATA_TYPES.byId(type.typeId())); + } + }); filter().mapDataType(Types1_20_5.ENTITY_DATA_TYPES::byId); registerMetaTypeHandler1_20_3( @@ -154,15 +180,9 @@ public final class EntityPacketRewriter1_21 extends EntityRewriter { - final EnchantmentsPaintingsStorage storage = event.user().get(EnchantmentsPaintingsStorage.class); - final int id = meta.value(); - meta.setValue(storage.mappedPainting(id)); - }); - - filter().type(EntityTypes1_20_5.ABSTRACT_MINECART).index(11).handler((event, meta) -> { - final int blockState = meta.value(); - meta.setValue(protocol.getMappingData().getNewBlockStateId(blockState)); + filter().type(EntityTypes1_20_5.ABSTRACT_MINECART).index(11).handler((event, data) -> { + final int blockState = data.value(); + data.setValue(protocol.getMappingData().getNewBlockStateId(blockState)); }); } @@ -171,13 +191,6 @@ public final class EntityPacketRewriter1_21 extends EntityRewriter