diff --git a/forge/src/main/java/dev/architectury/registry/menu/forge/MenuRegistryImpl.java b/minecraftforge/src/main/java/dev/architectury/registry/menu/forge/MenuRegistryImpl.java similarity index 100% rename from forge/src/main/java/dev/architectury/registry/menu/forge/MenuRegistryImpl.java rename to minecraftforge/src/main/java/dev/architectury/registry/menu/forge/MenuRegistryImpl.java diff --git a/neoforge/src/main/java/dev/architectury/registry/menu/forge/MenuRegistryImpl.java b/neoforge/src/main/java/dev/architectury/registry/menu/forge/MenuRegistryImpl.java new file mode 100644 index 00000000..c1c380eb --- /dev/null +++ b/neoforge/src/main/java/dev/architectury/registry/menu/forge/MenuRegistryImpl.java @@ -0,0 +1,55 @@ +/* + * This file is part of architectury. + * Copyright (C) 2020, 2021, 2022 architectury + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package dev.architectury.registry.menu.forge; + +import dev.architectury.registry.menu.ExtendedMenuProvider; +import dev.architectury.registry.menu.MenuRegistry.ExtendedMenuTypeFactory; +import dev.architectury.registry.menu.MenuRegistry.ScreenFactory; +import dev.architectury.registry.menu.MenuRegistry.SimpleMenuTypeFactory; +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.server.level.ServerPlayer; +import net.minecraft.world.flag.FeatureFlags; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.MenuType; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; +import net.neoforged.neoforge.common.extensions.IMenuTypeExtension; +import net.neoforged.neoforge.network.NetworkHooks; + +public class MenuRegistryImpl { + public static void openExtendedMenu(ServerPlayer player, ExtendedMenuProvider provider) { + NetworkHooks.openScreen(player, provider, provider::saveExtraData); + } + + public static MenuType of(SimpleMenuTypeFactory factory) { + return new MenuType<>(factory::create, FeatureFlags.VANILLA_SET); + } + + public static MenuType ofExtended(ExtendedMenuTypeFactory factory) { + return IMenuTypeExtension.create(factory::create); + } + + @OnlyIn(Dist.CLIENT) + public static > void registerScreenFactory(MenuType type, ScreenFactory factory) { + MenuScreens.register(type, factory::create); + } +}