From 2b56927d27041229715b295fb305abf1dfabf909 Mon Sep 17 00:00:00 2001 From: rtm516 Date: Sat, 13 May 2023 19:54:16 +0100 Subject: [PATCH] Fix java items getting registered at the wrong index Co-authored-by: AJ Ferguson --- core/src/main/java/org/geysermc/geyser/item/Items.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/geysermc/geyser/item/Items.java b/core/src/main/java/org/geysermc/geyser/item/Items.java index 68c7cf786..e0e9a256b 100644 --- a/core/src/main/java/org/geysermc/geyser/item/Items.java +++ b/core/src/main/java/org/geysermc/geyser/item/Items.java @@ -29,6 +29,8 @@ import org.geysermc.geyser.item.components.ToolTier; import org.geysermc.geyser.item.type.*; import org.geysermc.geyser.registry.Registries; +import java.util.Collections; + import static org.geysermc.geyser.item.type.Item.builder; /** @@ -1271,7 +1273,11 @@ public final class Items { public static T register(T item, int id) { item.setJavaId(id); - Registries.JAVA_ITEMS.get().add(item); + // This makes sure that the array is large enough to put the java item at the correct location + if (Registries.JAVA_ITEMS.get().size() <= id) { + Registries.JAVA_ITEMS.get().addAll(Collections.nCopies(id - Registries.JAVA_ITEMS.get().size() + 1, AIR)); + } + Registries.JAVA_ITEMS.get().set(id, item); Registries.JAVA_ITEM_IDENTIFIERS.register(item.javaIdentifier(), item); return item; }