From f914d576785504c54685ecd697fd2158ff10cdf9 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Mon, 28 Oct 2024 11:00:09 +0100 Subject: [PATCH] Small cleanup --- .../template/EntityPacketRewriter1_99.java | 10 +++---- .../rewriter/EntityPacketRewriter1_21.java | 24 ++++++----------- .../viaversion/rewriter/EntityRewriter.java | 26 ------------------- 3 files changed, 11 insertions(+), 49 deletions(-) diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/template/EntityPacketRewriter1_99.java b/common/src/main/java/com/viaversion/viaversion/protocols/template/EntityPacketRewriter1_99.java index 7750da436..56f555e42 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/template/EntityPacketRewriter1_99.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/template/EntityPacketRewriter1_99.java @@ -17,7 +17,6 @@ */ package com.viaversion.viaversion.protocols.template; -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.type.Types; @@ -26,7 +25,7 @@ import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundConfi 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.EntityRewriter; -import com.viaversion.viaversion.util.Key; +import com.viaversion.viaversion.rewriter.RegistryDataRewriter; // Replace if needed // Types1_OLD @@ -44,11 +43,8 @@ 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.LOGIN, wrapper -> { final int entityId = wrapper.passthrough(Types.INT); // Entity id diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/rewriter/EntityPacketRewriter1_21.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/rewriter/EntityPacketRewriter1_21.java index 434e80ea9..cf33e9857 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/rewriter/EntityPacketRewriter1_21.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/rewriter/EntityPacketRewriter1_21.java @@ -40,8 +40,7 @@ import com.viaversion.viaversion.protocols.v1_20_5to1_21.data.Paintings1_20_5; import com.viaversion.viaversion.protocols.v1_20_5to1_21.storage.EfficiencyAttributeStorage; import com.viaversion.viaversion.protocols.v1_20_5to1_21.storage.OnGroundTracker; import com.viaversion.viaversion.rewriter.EntityRewriter; -import com.viaversion.viaversion.util.ArrayUtil; -import com.viaversion.viaversion.util.Key; +import com.viaversion.viaversion.rewriter.RegistryDataRewriter; public final class EntityPacketRewriter1_21 extends EntityRewriter { @@ -55,20 +54,13 @@ public final class EntityPacketRewriter1_21 extends EntityRewriter { - final String type = Key.stripMinecraftNamespace(wrapper.passthrough(Types.STRING)); - final RegistryEntry[] entries = wrapper.passthrough(Types.REGISTRY_ENTRY_ARRAY); - if (type.equals("damage_type")) { - // Add required damage type - final CompoundTag campfireDamageType = new CompoundTag(); - campfireDamageType.putString("scaling", "when_caused_by_living_non_player"); - campfireDamageType.putString("message_id", "inFire"); - campfireDamageType.putFloat("exhaustion", 0.1F); - wrapper.set(Types.REGISTRY_ENTRY_ARRAY, 0, ArrayUtil.add(entries, new RegistryEntry("minecraft:campfire", campfireDamageType))); - } else { - handleRegistryData1_20_5(wrapper.user(), type, entries); - } - }); + final RegistryDataRewriter registryDataRewriter = new RegistryDataRewriter(protocol); + final CompoundTag campfireDamageType = new CompoundTag(); + campfireDamageType.putString("scaling", "when_caused_by_living_non_player"); + campfireDamageType.putString("message_id", "inFire"); + campfireDamageType.putFloat("exhaustion", 0.1F); + registryDataRewriter.addEntries("damage_type", new RegistryEntry("minecraft:campfire", campfireDamageType)); + protocol.registerClientbound(ClientboundConfigurationPackets1_20_5.REGISTRY_DATA, registryDataRewriter::handle); protocol.registerFinishConfiguration(ClientboundConfigurationPackets1_20_5.FINISH_CONFIGURATION, wrapper -> { // Add new registries diff --git a/common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java b/common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java index cf37dee5b..7efdf89a7 100644 --- a/common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java +++ b/common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java @@ -31,7 +31,6 @@ import com.viaversion.viaversion.api.data.entity.DimensionData; import com.viaversion.viaversion.api.data.entity.EntityTracker; import com.viaversion.viaversion.api.data.entity.TrackedEntity; import com.viaversion.viaversion.api.minecraft.Particle; -import com.viaversion.viaversion.api.minecraft.RegistryEntry; import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entitydata.EntityData; import com.viaversion.viaversion.api.minecraft.entitydata.EntityDataType; @@ -50,7 +49,6 @@ import com.viaversion.viaversion.rewriter.entitydata.EntityDataHandlerEventImpl; import com.viaversion.viaversion.util.Key; import com.viaversion.viaversion.util.TagUtil; import java.util.ArrayList; -import java.util.Arrays; import java.util.Comparator; import java.util.HashMap; import java.util.List; @@ -505,23 +503,6 @@ public abstract class EntityRewriter dimensionDataMap = new HashMap<>(entries.length); - for (int i = 0; i < entries.length; i++) { - final RegistryEntry entry = entries[i]; - final String key = Key.stripMinecraftNamespace(entry.key()); - final DimensionData dimensionData = entry.tag() != null - ? new DimensionDataImpl(i, (CompoundTag) entry.tag()) - : DimensionDataImpl.withDefaultsFor(key, i); - dimensionDataMap.put(key, dimensionData); - } - tracker(connection).setDimensions(dimensionDataMap); - } - } - public EntityType trackAndRewrite(final PacketWrapper wrapper, final int typeId, final int entityId) { final int mappedTypeId = newEntityId(typeId); if (mappedTypeId != typeId) { @@ -583,13 +564,6 @@ public abstract class EntityRewriter entityDataList, EntityData entityData) { if (!Via.getConfig().isSuppressMetadataErrors() || Via.getManager().isDebug()) { protocol.getLogger().severe("An error occurred in entity data handler " + this.getClass().getSimpleName()