From fc9d5b6d9dcb7116a60b84a8afda016d7fbb491b Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Sun, 5 May 2024 13:33:21 +0200 Subject: [PATCH] Clean up entriesLength usage --- .../data/DamageTypes1_20_3.java | 2 +- .../rewriter/EntityPacketRewriter1_20_5.java | 25 +++++++++++-------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/data/DamageTypes1_20_3.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/data/DamageTypes1_20_3.java index e036b69d0..7b7dfeb99 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/data/DamageTypes1_20_3.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/data/DamageTypes1_20_3.java @@ -24,7 +24,7 @@ import it.unimi.dsi.fastutil.objects.ObjectSet; public final class DamageTypes1_20_3 { - private final static Object2ObjectMap DAMAGE_TYPES = new Object2ObjectOpenHashMap<>(); + private static final Object2ObjectMap DAMAGE_TYPES = new Object2ObjectOpenHashMap<>(); static { DAMAGE_TYPES.put("in_fire", create("inFire", 0.1F)); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/EntityPacketRewriter1_20_5.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/EntityPacketRewriter1_20_5.java index 18bb56e7f..65d7e11ed 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/EntityPacketRewriter1_20_5.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/EntityPacketRewriter1_20_5.java @@ -121,15 +121,15 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter e.getInt("id")).distinct().toArray().length]; boolean requiresDummyValues = false; - int entriesLength = registryEntries.length; - IntSet ids = new IntArraySet(); + int highestId = -1; + final IntSet ids = new IntArraySet(); for (final CompoundTag tag : valueTag) { final String name = tag.getString("name"); final int id = tag.getInt("id"); if (ids.add(id)) { // Override duplicated id without incrementing entries length - entriesLength = Math.max(entriesLength, id + 1); + highestId = Math.max(highestId, id); if (id >= registryEntries.length) { - // It was previously possible to have arbitrary ids + // It was previously possible to have arbitrary ids, increase array length if needed registryEntries = Arrays.copyOf(registryEntries, Math.max(registryEntries.length * 2, id + 1)); requiresDummyValues = true; } @@ -140,13 +140,13 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter registryEntryKeys = Arrays.stream(registryEntries).map(e -> Key.stripMinecraftNamespace(e.key())).collect(Collectors.toSet()); @@ -154,15 +154,18 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter