From 3e896414488de27666c7106657a54e26c8ba6974 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Wed, 24 Jan 2024 18:51:06 +0100 Subject: [PATCH] 24w04a --- .../Protocol1_20_3To1_20_5.java | 13 +++- .../rewriter/EntityPacketRewriter1_20_5.java | 62 ++++++++++++++++-- .../storage/RegistryDataStorage.java | 45 +++++++++++++ .../data/mappings-1.20.5to1.20.3.nbt | Bin 1885 -> 1927 bytes gradle.properties | 2 +- gradle/libs.versions.toml | 2 +- settings.gradle.kts | 1 + .../rewriter/EntityPacketRewriter1_99.java | 14 ++-- 8 files changed, 125 insertions(+), 14 deletions(-) create mode 100644 common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_3to1_20_5/storage/RegistryDataStorage.java diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_3to1_20_5/Protocol1_20_3To1_20_5.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_3to1_20_5/Protocol1_20_3To1_20_5.java index e3b7500b..adf7dd8c 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_3to1_20_5/Protocol1_20_3To1_20_5.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_3to1_20_5/Protocol1_20_3To1_20_5.java @@ -25,6 +25,7 @@ import com.viaversion.viabackwards.protocol.protocol1_20_3to1_20_5.provider.Tran import com.viaversion.viabackwards.protocol.protocol1_20_3to1_20_5.rewriter.BlockItemPacketRewriter1_20_5; import com.viaversion.viabackwards.protocol.protocol1_20_3to1_20_5.rewriter.EntityPacketRewriter1_20_5; import com.viaversion.viabackwards.protocol.protocol1_20_3to1_20_5.storage.CookieStorage; +import com.viaversion.viabackwards.protocol.protocol1_20_3to1_20_5.storage.RegistryDataStorage; import com.viaversion.viabackwards.protocol.protocol1_20_3to1_20_5.storage.SecureChatStorage; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.connection.UserConnection; @@ -69,7 +70,16 @@ public final class Protocol1_20_3To1_20_5 extends BackwardsProtocol tagRewriter = new TagRewriter<>(this); tagRewriter.registerGeneric(ClientboundPackets1_20_5.TAGS); - tagRewriter.registerGeneric(State.CONFIGURATION, ClientboundConfigurationPackets1_20_5.UPDATE_TAGS); + registerClientbound(State.CONFIGURATION, ClientboundConfigurationPackets1_20_5.UPDATE_TAGS, wrapper -> { + // Send off registry data first + final PacketWrapper registryDataPacket = wrapper.create(ClientboundConfigurationPackets1_20_3.REGISTRY_DATA); + registryDataPacket.write(Type.COMPOUND_TAG, wrapper.user().get(RegistryDataStorage.class).registryData().copy()); + registryDataPacket.send(Protocol1_20_3To1_20_5.class); + + tagRewriter.getGenericHandler().handle(wrapper); + }); + + registerClientbound(ClientboundPackets1_20_5.START_CONFIGURATION, wrapper -> wrapper.user().get(RegistryDataStorage.class).registryData().clear()); final SoundRewriter soundRewriter = new SoundRewriter<>(this); soundRewriter.register1_19_3Sound(ClientboundPackets1_20_5.SOUND); @@ -151,6 +161,7 @@ public final class Protocol1_20_3To1_20_5 extends BackwardsProtocol { @@ -46,9 +55,45 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter { + final String registryKey = Key.stripMinecraftNamespace(wrapper.read(Type.STRING)); + final RegistryEntry[] entries = wrapper.read(Type.REGISTRY_ENTRY_ARRAY); + + // Track data + final RegistryDataStorage registryDataStorage = wrapper.user().get(RegistryDataStorage.class); + if (registryKey.equals("worldgen/biome")) { + tracker(wrapper.user()).setBiomesSent(entries.length); + } else if (registryKey.equals("dimension_type")) { + final Map dimensionDataMap = new HashMap<>(entries.length); + final String[] keys = new String[entries.length]; + for (int i = 0; i < entries.length; i++) { + final RegistryEntry entry = entries[i]; + final String dimensionKey = Key.stripMinecraftNamespace(entry.key()); + dimensionDataMap.put(dimensionKey, new DimensionDataImpl(i, (CompoundTag) entry.tag())); + keys[i] = dimensionKey; + } + registryDataStorage.setDimensionKeys(keys); + tracker(wrapper.user()).setDimensions(dimensionDataMap); + } + + // Write to old format + final CompoundTag registryTag = new CompoundTag(); + final ListTag entriesTag = new ListTag(); + registryTag.putString("type", registryKey); + registryTag.put("value", entriesTag); + for (int i = 0; i < entries.length; i++) { + final RegistryEntry entry = entries[i]; + final CompoundTag entryCompoundTag = new CompoundTag(); + entryCompoundTag.putString("name", entry.key()); + entryCompoundTag.putInt("id", i); + entryCompoundTag.put("element", entry.tag()); + entriesTag.add(entryCompoundTag); + } + + // Store and send together with the rest later + registryDataStorage.registryData().put(registryKey, registryTag); + wrapper.cancel(); + }); } }); @@ -64,6 +109,11 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter { + final int dimensionId = wrapper.read(Type.VAR_INT); + final RegistryDataStorage storage = wrapper.user().get(RegistryDataStorage.class); + wrapper.write(Type.STRING, storage.dimensionKeys()[dimensionId]); + }); map(Type.STRING); // Dimension key map(Type.STRING); // World map(Type.LONG); // Seed @@ -84,7 +134,11 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter { + final int dimensionId = wrapper.read(Type.VAR_INT); + final RegistryDataStorage storage = wrapper.user().get(RegistryDataStorage.class); + wrapper.write(Type.STRING, storage.dimensionKeys()[dimensionId]); + }); map(Type.STRING); // World handler(worldDataTrackerHandlerByKey()); // Tracks world height and name for chunk data and entity (un)tracking } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_3to1_20_5/storage/RegistryDataStorage.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_3to1_20_5/storage/RegistryDataStorage.java new file mode 100644 index 00000000..b438eac1 --- /dev/null +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_3to1_20_5/storage/RegistryDataStorage.java @@ -0,0 +1,45 @@ +/* + * This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards + * Copyright (C) 2016-2024 ViaVersion and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.viaversion.viabackwards.protocol.protocol1_20_3to1_20_5.storage; + +import com.viaversion.viaversion.api.connection.StorableObject; +import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; +import org.checkerframework.checker.nullness.qual.Nullable; + +public final class RegistryDataStorage implements StorableObject { + + private final CompoundTag registryData = new CompoundTag(); + private String[] dimensionKeys; + + public CompoundTag registryData() { + return registryData; + } + + public String @Nullable [] dimensionKeys() { + return dimensionKeys; + } + + public void setDimensionKeys(final String[] dimensionKeys) { + this.dimensionKeys = dimensionKeys; + } + + public void clear() { + registryData.clear(); + dimensionKeys = null; + } +} diff --git a/common/src/main/resources/assets/viabackwards/data/mappings-1.20.5to1.20.3.nbt b/common/src/main/resources/assets/viabackwards/data/mappings-1.20.5to1.20.3.nbt index cc79581120fe32dcb53873c3ce0d512f7e449808..09f42be94476c4b3f3b03091e6b2466f028f8437 100644 GIT binary patch delta 117 zcmcc1*UmrTB9|~X15;uN0|SG|#M}C2jzESN5PJi$4-jt#;w?bD6^Qo%@qVD{l6)XT zgn@zOD+2@5+y6kY*@97-O@)I&HZ`v#v!qflu_!k&B{L@{UoWGys3g89HKjB;H3g`P F0RT7C9&`Wz delta 75 zcmZqYzson_B9{<115;uN0|SHb#M}CMo