-
-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
RegisterMenuScreensEvent
to replace `MenuScreens#register(MenuT…
…ype, ScreenConstructor)` (#508)
- Loading branch information
1 parent
560b0e7
commit 894da78
Showing
5 changed files
with
68 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/main/java/net/neoforged/neoforge/client/event/RegisterMenuScreensEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright (c) NeoForged and contributors | ||
* SPDX-License-Identifier: LGPL-2.1-only | ||
*/ | ||
|
||
package net.neoforged.neoforge.client.event; | ||
|
||
import java.util.Map; | ||
import net.minecraft.client.gui.screens.MenuScreens; | ||
import net.minecraft.client.gui.screens.Screen; | ||
import net.minecraft.client.gui.screens.inventory.MenuAccess; | ||
import net.minecraft.core.registries.BuiltInRegistries; | ||
import net.minecraft.world.inventory.AbstractContainerMenu; | ||
import net.minecraft.world.inventory.MenuType; | ||
import net.neoforged.bus.api.Event; | ||
import net.neoforged.fml.event.IModBusEvent; | ||
import org.jetbrains.annotations.ApiStatus; | ||
|
||
public class RegisterMenuScreensEvent extends Event implements IModBusEvent { | ||
private final Map<MenuType<?>, MenuScreens.ScreenConstructor<?, ?>> registeredScreens; | ||
|
||
@ApiStatus.Internal | ||
public RegisterMenuScreensEvent(Map<MenuType<?>, MenuScreens.ScreenConstructor<?, ?>> registeredScreens) { | ||
this.registeredScreens = registeredScreens; | ||
} | ||
|
||
public <M extends AbstractContainerMenu, U extends Screen & MenuAccess<M>> void register( | ||
MenuType<? extends M> menuType, MenuScreens.ScreenConstructor<M, U> screenConstructor) { | ||
if (registeredScreens.containsKey(menuType)) { | ||
throw new IllegalStateException("Duplicate attempt to register screen: " + BuiltInRegistries.MENU.getKey(menuType)); | ||
} | ||
registeredScreens.put(menuType, screenConstructor); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters