Skip to content

Commit

Permalink
Fix java items getting registered at the wrong index
Browse files Browse the repository at this point in the history
Co-authored-by: AJ Ferguson <[email protected]>
  • Loading branch information
rtm516 and AJ-Ferguson committed May 13, 2023
1 parent 870a838 commit 2b56927
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion core/src/main/java/org/geysermc/geyser/item/Items.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
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;

/**
Expand Down Expand Up @@ -1271,7 +1273,11 @@ private static <T extends Item> T register(T item) {

public static <T extends Item> 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;
}
Expand Down

0 comments on commit 2b56927

Please sign in to comment.