From 8af8319839280bfe434a04b2cd11a0fa313ab90f Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Sun, 27 Oct 2024 23:25:00 +0100 Subject: [PATCH] Small cleanup --- .../api/ViaBackwardsPlatform.java | 2 +- .../api/rewriters/EntityRewriter.java | 14 +++--- .../api/rewriters/SoundRewriter.java | 17 ++------ .../template/EntityPacketRewriter1_99.java | 43 ++++++++----------- .../rewriter/EntityPacketRewriter1_21.java | 6 ++- gradle/libs.versions.toml | 2 +- settings.gradle.kts | 1 - 7 files changed, 32 insertions(+), 53 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/api/ViaBackwardsPlatform.java b/common/src/main/java/com/viaversion/viabackwards/api/ViaBackwardsPlatform.java index 1e09a521..d878aadb 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/ViaBackwardsPlatform.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/ViaBackwardsPlatform.java @@ -71,7 +71,7 @@ import java.util.logging.Logger; public interface ViaBackwardsPlatform { - String MINIMUM_VV_VERSION = "5.1.0"; + String MINIMUM_VV_VERSION = "5.1.1"; /** * Initialize ViaBackwards. diff --git a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/EntityRewriter.java b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/EntityRewriter.java index 242f4c67..ca85e27c 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/EntityRewriter.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/EntityRewriter.java @@ -25,7 +25,6 @@ import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.remapper.PacketHandler; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; -import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.types.version.Types1_14; @@ -105,14 +104,11 @@ public abstract class EntityRewriter trackAndMapEntity(wrapper)); - } + protocol.registerClientbound(packetType, wrapper -> { + wrapper.passthrough(Types.VAR_INT); // Entity ID + wrapper.passthrough(Types.UUID); // Entity UUID + wrapper.passthrough(Types.VAR_INT); // Entity Type + trackAndMapEntity(wrapper); }); } diff --git a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/SoundRewriter.java b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/SoundRewriter.java index f739f4c4..a86dc273 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/SoundRewriter.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/SoundRewriter.java @@ -23,7 +23,6 @@ import com.viaversion.viaversion.api.minecraft.SoundEvent; import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.remapper.PacketHandler; -import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.type.Types; public class SoundRewriter extends com.viaversion.viaversion.rewriter.SoundRewriter { @@ -36,22 +35,14 @@ public class SoundRewriter extends com.viaversi } public void registerNamedSound(final C packetType) { - protocol.registerClientbound(packetType, new PacketHandlers() { - @Override - public void register() { - map(Types.STRING); // Sound identifier - handler(getNamedSoundHandler()); - } + protocol.registerClientbound(packetType, wrapper -> { + wrapper.passthrough(Types.STRING); // Sound identifier + getNamedSoundHandler().handle(wrapper); }); } public void registerStopSound(final C packetType) { - protocol.registerClientbound(packetType, new PacketHandlers() { - @Override - public void register() { - handler(getStopSoundHandler()); - } - }); + protocol.registerClientbound(packetType, wrapper -> getStopSoundHandler().handle(wrapper)); } public PacketHandler getNamedSoundHandler() { diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/template/EntityPacketRewriter1_99.java b/common/src/main/java/com/viaversion/viabackwards/protocol/template/EntityPacketRewriter1_99.java index 94fc157b..51cfdd3d 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/template/EntityPacketRewriter1_99.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/template/EntityPacketRewriter1_99.java @@ -18,16 +18,14 @@ package com.viaversion.viabackwards.protocol.template; import com.viaversion.viabackwards.api.rewriters.EntityRewriter; -import com.viaversion.viaversion.api.minecraft.RegistryEntry; import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5; -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; import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundConfigurationPackets1_21; import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPacket1_21_2; import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPackets1_21_2; -import com.viaversion.viaversion.util.Key; +import com.viaversion.viaversion.rewriter.RegistryDataRewriter; // Replace if needed // Types1_OLD @@ -44,30 +42,23 @@ final class EntityPacketRewriter1_99 extends EntityRewriter { - final String registryKey = Key.stripMinecraftNamespace(wrapper.passthrough(Types.STRING)); - final RegistryEntry[] entries = wrapper.passthrough(Types.REGISTRY_ENTRY_ARRAY); - handleRegistryData1_20_5(wrapper.user(), registryKey, entries); // Caches dimensions to access data like height later and tracks the amount of biomes sent for chunk data - }); + final RegistryDataRewriter registryDataRewriter = new RegistryDataRewriter(protocol); + protocol.registerClientbound(ClientboundConfigurationPackets1_21.REGISTRY_DATA, registryDataRewriter::handle); - protocol.registerClientbound(ClientboundPackets1_21_2.LOGIN, new PacketHandlers() { - @Override - public void register() { - map(Types.INT); // Entity id - map(Types.BOOLEAN); // Hardcore - map(Types.STRING_ARRAY); // World List - map(Types.VAR_INT); // Max players - map(Types.VAR_INT); // View distance - map(Types.VAR_INT); // Simulation distance - map(Types.BOOLEAN); // Reduced debug info - map(Types.BOOLEAN); // Show death screen - map(Types.BOOLEAN); // Limited crafting - map(Types.VAR_INT); // Dimension key - map(Types.STRING); // World - handler(worldDataTrackerHandlerByKey1_20_5(3)); // Tracks world height and name for chunk data and entity (un)tracking - handler(playerTrackerHandler()); - } + protocol.registerClientbound(ClientboundPackets1_21_2.LOGIN, wrapper -> { + final int entityId = wrapper.passthrough(Types.INT); // Entity id + wrapper.passthrough(Types.BOOLEAN); // Hardcore + wrapper.passthrough(Types.STRING_ARRAY); // World List + wrapper.passthrough(Types.VAR_INT); // Max players + wrapper.passthrough(Types.VAR_INT); // View distance + wrapper.passthrough(Types.VAR_INT); // Simulation distance + wrapper.passthrough(Types.BOOLEAN); // Reduced debug info + wrapper.passthrough(Types.BOOLEAN); // Show death screen + wrapper.passthrough(Types.BOOLEAN); // Limited crafting + final int dimensionId = wrapper.passthrough(Types.VAR_INT); + final String world = wrapper.passthrough(Types.STRING); + trackWorldDataByKey1_20_5(wrapper.user(), dimensionId, world); + trackPlayer(wrapper.user(), entityId); }); protocol.registerClientbound(ClientboundPackets1_21_2.RESPAWN, wrapper -> { 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 98b98000..f04f15a3 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 @@ -40,6 +40,7 @@ import com.viaversion.viaversion.protocols.v1_20_5to1_21.data.Paintings1_20_5; import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundConfigurationPackets1_21; import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPacket1_21; import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPackets1_21; +import com.viaversion.viaversion.rewriter.RegistryDataRewriter; import com.viaversion.viaversion.util.Key; import com.viaversion.viaversion.util.KeyMappings; import java.util.HashMap; @@ -64,6 +65,7 @@ public final class EntityPacketRewriter1_21 extends EntityRewriter { final String key = Key.stripMinecraftNamespace(wrapper.passthrough(Types.STRING)); final RegistryEntry[] entries = wrapper.passthrough(Types.REGISTRY_ENTRY_ARRAY); @@ -99,7 +101,7 @@ public final class EntityPacketRewriter1_21 extends EntityRewriter