Skip to content

Commit

Permalink
Add a method to build menu types without causing them to be registered.
Browse files Browse the repository at this point in the history
  • Loading branch information
shartte committed Dec 17, 2024
1 parent 5b884a3 commit 26e5c24
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/main/java/appeng/menu/implementations/MenuTypeBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,17 +188,26 @@ public MenuType<M> build(String id) {
/**
* Creates a menu type that uses this helper as a factory and network deserializer.
*/
public MenuType<M> build(ResourceLocation id) {
public MenuType<M> buildUnregistered(ResourceLocation id) {
Preconditions.checkState(menuType == null, "build was already called");
Preconditions.checkState(this.id == null, "id should not be set");

this.id = id;
menuType = IMenuTypeExtension.create(this::fromNetwork);
InitMenuTypes.queueRegistration(this.id, menuType);
MenuOpener.addOpener(menuType, this::open);
return menuType;
}

/**
* Creates a menu type that uses this helper as a factory and network deserializer, and queues it for registration
* with Vanilla.
*/
public MenuType<M> build(ResourceLocation id) {
var menuType = buildUnregistered(id);
InitMenuTypes.queueRegistration(this.id, menuType);
return menuType;
}

@FunctionalInterface
public interface MenuFactory<C, I> {
C create(int containerId, Inventory playerInv, I menuHost);
Expand Down

0 comments on commit 26e5c24

Please sign in to comment.