From 95e3446e8cfb1d3493768137b13f6a73197076a9 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Fri, 11 Aug 2023 16:08:10 +1000 Subject: [PATCH] Add mappings for changed block states and sounds --- .../Protocol1_20To1_20_2.java | 14 ++++++ .../BlockItemPacketRewriter1_20_2.java | 42 +++++++++++++----- .../rewriter/EntityPacketRewriter1_20_2.java | 7 +++ .../data/mappings-1.19.3to1.19.nbt | Bin 11972 -> 11964 bytes .../data/mappings-1.20.2to1.20.nbt | Bin 0 -> 209 bytes 5 files changed, 53 insertions(+), 10 deletions(-) create mode 100644 common/src/main/resources/assets/viabackwards/data/mappings-1.20.2to1.20.nbt diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20to1_20_2/Protocol1_20To1_20_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20to1_20_2/Protocol1_20To1_20_2.java index 1c28a790..17b24eec 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20to1_20_2/Protocol1_20To1_20_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20to1_20_2/Protocol1_20To1_20_2.java @@ -18,6 +18,8 @@ package com.viaversion.viabackwards.protocol.protocol1_20to1_20_2; import com.viaversion.viabackwards.api.BackwardsProtocol; +import com.viaversion.viabackwards.api.data.BackwardsMappings; +import com.viaversion.viabackwards.api.rewriters.SoundRewriter; import com.viaversion.viabackwards.protocol.protocol1_20to1_20_2.rewriter.BlockItemPacketRewriter1_20_2; import com.viaversion.viabackwards.protocol.protocol1_20to1_20_2.rewriter.EntityPacketRewriter1_20_2; import com.viaversion.viabackwards.protocol.protocol1_20to1_20_2.storage.ConfigurationPacketStorage; @@ -36,6 +38,7 @@ import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets; import com.viaversion.viaversion.protocols.base.ServerboundLoginPackets; import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.ClientboundPackets1_19_4; import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.ServerboundPackets1_19_4; +import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.Protocol1_20_2To1_20; import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ClientboundConfigurationPackets1_20_2; import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ClientboundPackets1_20_2; import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ServerboundConfigurationPackets1_20_2; @@ -44,6 +47,7 @@ import java.util.UUID; public final class Protocol1_20To1_20_2 extends BackwardsProtocol { + public static final BackwardsMappings MAPPINGS = new BackwardsMappings("1.20.2", "1.20", Protocol1_20_2To1_20.class); private final EntityPacketRewriter1_20_2 entityPacketRewriter = new EntityPacketRewriter1_20_2(this); private final BlockItemPacketRewriter1_20_2 itemPacketRewriter = new BlockItemPacketRewriter1_20_2(this); @@ -55,6 +59,11 @@ public final class Protocol1_20To1_20_2 extends BackwardsProtocol soundRewriter = new SoundRewriter<>(this); + soundRewriter.register1_19_3Sound(ClientboundPackets1_20_2.SOUND); + soundRewriter.registerSound(ClientboundPackets1_20_2.ENTITY_SOUND); + soundRewriter.registerStopSound(ClientboundPackets1_20_2.STOP_SOUND); + registerClientbound(ClientboundPackets1_20_2.SCOREBOARD_OBJECTIVE, wrapper -> { final int slot = wrapper.read(Type.VAR_INT); wrapper.write(Type.BYTE, (byte) slot); @@ -146,6 +155,11 @@ public final class Protocol1_20To1_20_2 extends BackwardsProtocol getEntityRewriter() { return entityPacketRewriter; diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20to1_20_2/rewriter/BlockItemPacketRewriter1_20_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20to1_20_2/rewriter/BlockItemPacketRewriter1_20_2.java index 8b7c9713..74035137 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20to1_20_2/rewriter/BlockItemPacketRewriter1_20_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20to1_20_2/rewriter/BlockItemPacketRewriter1_20_2.java @@ -23,6 +23,9 @@ import com.viaversion.viaversion.api.data.ParticleMappings; import com.viaversion.viaversion.api.data.entity.EntityTracker; import com.viaversion.viaversion.api.minecraft.blockentity.BlockEntity; import com.viaversion.viaversion.api.minecraft.chunks.Chunk; +import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; +import com.viaversion.viaversion.api.minecraft.chunks.DataPalette; +import com.viaversion.viaversion.api.minecraft.chunks.PaletteType; import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.metadata.ChunkPosition; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; @@ -40,6 +43,7 @@ import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.Serverbou import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.rewriter.RecipeRewriter1_20_2; import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.type.ChunkType1_20_2; import com.viaversion.viaversion.protocols.protocol1_20to1_19_4.Protocol1_20To1_19_4; +import com.viaversion.viaversion.rewriter.BlockRewriter; import com.viaversion.viaversion.util.Key; import com.viaversion.viaversion.util.MathUtil; import java.util.Arrays; @@ -96,6 +100,12 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter blockRewriter = new BlockRewriter<>(protocol, Type.POSITION1_14); + blockRewriter.registerBlockAction(ClientboundPackets1_20_2.BLOCK_ACTION); + blockRewriter.registerBlockChange(ClientboundPackets1_20_2.BLOCK_CHANGE); + blockRewriter.registerVarLongMultiBlockChange1_20(ClientboundPackets1_20_2.MULTI_BLOCK_CHANGE); + blockRewriter.registerEffect(ClientboundPackets1_20_2.EFFECT, 1010, 2001); + protocol.cancelClientbound(ClientboundPackets1_20_2.CHUNK_BATCH_START); protocol.registerClientbound(ClientboundPackets1_20_2.CHUNK_BATCH_FINISHED, null, wrapper -> { wrapper.cancel(); @@ -125,15 +135,23 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter { final EntityTracker tracker = protocol.getEntityRewriter().tracker(wrapper.user()); final Type chunkType = new ChunkType1_20_2(tracker.currentWorldSectionHeight(), - MathUtil.ceilLog2(Protocol1_20To1_19_4.MAPPINGS.getBlockStateMappings().mappedSize()), + MathUtil.ceilLog2(protocol.getMappingData().getBlockStateMappings().size()), MathUtil.ceilLog2(tracker.biomesSent())); final Chunk chunk = wrapper.read(chunkType); final Type newChunkType = new Chunk1_18Type(tracker.currentWorldSectionHeight(), - MathUtil.ceilLog2(Protocol1_20To1_19_4.MAPPINGS.getBlockStateMappings().mappedSize()), + MathUtil.ceilLog2(protocol.getMappingData().getBlockStateMappings().mappedSize()), MathUtil.ceilLog2(tracker.biomesSent())); wrapper.write(newChunkType, chunk); + for (final ChunkSection section : chunk.getSections()) { + final DataPalette blockPalette = section.palette(PaletteType.BLOCKS); + for (int i = 0; i < blockPalette.size(); i++) { + final int id = blockPalette.idByIndex(i); + blockPalette.setIdByIndex(i, protocol.getMappingData().getNewBlockStateId(id)); + } + } + for (final BlockEntity blockEntity : chunk.blockEntities()) { handleBlockEntity(blockEntity.tag()); } @@ -169,7 +187,7 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter { wrapper.passthrough(Type.BOOLEAN); // Reset/clear - int size = wrapper.passthrough(Type.VAR_INT); // Mapping size + final int size = wrapper.passthrough(Type.VAR_INT); // Mapping size for (int i = 0; i < size; i++) { wrapper.passthrough(Type.STRING); // Identifier @@ -183,7 +201,7 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter { // Affected items - int length = wrapper.passthrough(Type.VAR_INT); + final int length = wrapper.passthrough(Type.VAR_INT); for (int i = 0; i < length; i++) { wrapper.passthrough(Type.SHORT); // Slot wrapper.write(Type.ITEM1_20_2, wrapper.read(Type.FLAT_VAR_INT_ITEM)); @@ -239,7 +257,7 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter { wrapper.cancel(); wrapper.passthrough(Type.VAR_INT); // Container id - int size = wrapper.passthrough(Type.VAR_INT); + final int size = wrapper.passthrough(Type.VAR_INT); for (int i = 0; i < size; i++) { wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.ITEM1_20_2)); // Input wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.ITEM1_20_2)); // Output @@ -275,9 +293,13 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter { - int id = wrapper.get(Type.VAR_INT, 0); - ParticleMappings mappings = Protocol1_20To1_19_4.MAPPINGS.getParticleMappings(); - if (mappings.isItemParticle(id)) { + final int id = wrapper.get(Type.VAR_INT, 0); + // Use 1.19.4->1.20 mappings + final ParticleMappings mappings = Protocol1_20To1_19_4.MAPPINGS.getParticleMappings(); + if (mappings.isBlockParticle(id)) { + final int data = wrapper.read(Type.VAR_INT); + wrapper.write(Type.VAR_INT, protocol.getMappingData().getNewBlockStateId(data)); + } else if (mappings.isItemParticle(id)) { wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.ITEM1_20_2)); } }); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20to1_20_2/rewriter/EntityPacketRewriter1_20_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20to1_20_2/rewriter/EntityPacketRewriter1_20_2.java index 3441f958..1440a1ef 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20to1_20_2/rewriter/EntityPacketRewriter1_20_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20to1_20_2/rewriter/EntityPacketRewriter1_20_2.java @@ -132,7 +132,14 @@ public final class EntityPacketRewriter1_20_2 extends EntityRewriter meta.setMetaType(Types1_20.META_TYPES.byId(meta.metaType().typeId()))); + registerMetaTypeHandler(null, Types1_20.META_TYPES.blockStateType, Types1_20.META_TYPES.optionalBlockStateType, Types1_20.META_TYPES.particleType, null, null); + filter().filterFamily(Entity1_19_4Types.DISPLAY).removeIndex(10); + + filter().filterFamily(Entity1_19_4Types.MINECART_ABSTRACT).index(11).handler((event, meta) -> { + final int blockState = meta.value(); + meta.setValue(protocol.getMappingData().getNewBlockStateId(blockState)); + }); } @Override diff --git a/common/src/main/resources/assets/viabackwards/data/mappings-1.19.3to1.19.nbt b/common/src/main/resources/assets/viabackwards/data/mappings-1.19.3to1.19.nbt index 0e55290694d1e8938204e624fd658e8f8b7a78ab..66271b0f57300bf628b81ed999cf88a0527d3b6e 100644 GIT binary patch delta 30 lcmX>SyC-(T8!<-R$#2D)Czps@0$Jlsxx8%azO0|3a03t9jG delta 36 rcmdlJdn9(l8!<+`$#2D)8676)irWC$tHkSB)fgCQUyvH*% literal 0 HcmV?d00001