mirror of
https://github.com/architectury/architectury-api.git
synced 2026-03-28 03:56:59 -05:00
Fix #453
This commit is contained in:
@@ -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 <T extends AbstractContainerMenu> MenuType<T> of(SimpleMenuTypeFactory<T> factory) {
|
||||
return new MenuType<>(factory::create, FeatureFlags.VANILLA_SET);
|
||||
}
|
||||
|
||||
public static <T extends AbstractContainerMenu> MenuType<T> ofExtended(ExtendedMenuTypeFactory<T> factory) {
|
||||
return IMenuTypeExtension.create(factory::create);
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public static <H extends AbstractContainerMenu, S extends Screen & MenuAccess<H>> void registerScreenFactory(MenuType<? extends H> type, ScreenFactory<H, S> factory) {
|
||||
MenuScreens.register(type, factory::create);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user