### Create Main Fragment Source: https://github.com/blocamlimb/modernui/wiki/Forge-1.18 Example of creating a custom UI fragment by extending the Fragment class. This involves overriding onCreateView to define the fragment's layout and appearance. ```java public class MyFragment extends Fragment { @Nullable @Override public View onCreateView(@Nullable ViewGroup container, @Nullable DataSet savedInstanceState) { var base = new ScrollView(); { var content = new TestLinearLayout(); var params = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); base.addView(content, params); } base.setBackground(new Drawable() { @Override public void draw(@Nonnull Canvas canvas) { Paint paint = Paint.get(); Rect b = getBounds(); paint.setRGBA(8, 8, 8, 80); canvas.drawRoundRect(b.left, b.top, b.right, b.bottom, 8, paint); } }); { var params = new FrameLayout.LayoutParams(dp(480), dp(360)); params.gravity = Gravity.CENTER; base.setLayoutParams(params); } return base; } } ``` -------------------------------- ### Open Menu Server Side Source: https://github.com/blocamlimb/modernui/wiki/Forge-1.18 Use MuiForgeApi.openMenu to open a menu on the server side. Ensure the block entity implements MenuProvider. ```java public class MyBlock extends Block { @Override public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { if (!level.isClientSide && level.getBlockEntity(pos) instanceof MyBlockEntity e) { // we assume MyBlockEntity implements MenuProvider MuiForgeApi.openMenu(e, pos); } return InteractionResult.sidedSuccess(level.isClientSide); } } ``` -------------------------------- ### Configure LWJGL OpenGL Library Path for macOS Source: https://github.com/blocamlimb/modernui/wiki/OpenGL-4.5-support Set this JVM argument to specify the path to the libGL.1.dylib from Mesa on macOS. ```java -Dorg.lwjgl.opengl.libname=.../mesa/lib/libGL.1.dylib ``` -------------------------------- ### Configure LWJGL OpenGL Library Path for Windows Source: https://github.com/blocamlimb/modernui/wiki/OpenGL-4.5-support Set this JVM argument to specify the path to the OpenGL32.dll from Mesa on Windows. ```java -Dorg.lwjgl.opengl.libname=.../mesa/x64/opengl32.dll ``` -------------------------------- ### Configure LWJGL OpenGL Library Path for Linux Source: https://github.com/blocamlimb/modernui/wiki/OpenGL-4.5-support Set this JVM argument to specify the path to the libGL.so.1 from Mesa on Linux. ```java -Dorg.lwjgl.opengl.libname=.../mesa/lib/libGL.so.1 ``` -------------------------------- ### Set Environment Variables for Gallium Zink Source: https://github.com/blocamlimb/modernui/wiki/OpenGL-4.5-support Set these environment variables to enable Gallium Zink driver for LWJGL. This is typically used in conjunction with setting the OpenGL library path. ```bash GALLIUM_DRIVER=zink MESA_LOADER_DRIVER_OVERRIDE=zink ``` -------------------------------- ### Register MenuType with Forge Source: https://github.com/blocamlimb/modernui/wiki/Forge-1.18 Subscribe to the MOD event bus to register your custom MenuType. Use IContainerFactory to define the menu's creation logic. Ensure the MenuType is registered with a unique registry name. ```java @Mod.EventBusSubscriber(modid = "my_modid", bus = Mod.EventBusSubscriber.Bus.MOD) public class Registration { @SubscribeEvent public static void registerMenus(@Nonnull RegistryEvent.Register> event) { IContainerFactory factory = (containerId, inventory, extraData) -> { return new MyMenu(containerId, ...); }; event.getRegistry().register(IForgeMenuType.create(factory).setRegistryName("my_menu")); } } ``` -------------------------------- ### Handle OpenMenuEvent Client Side Source: https://github.com/blocamlimb/modernui/wiki/Forge-1.18 Subscribe to OpenMenuEvent on the client-side event bus to handle menu opening. This event provides the menu and allows setting a custom fragment as the UI lifecycle owner. ```java @Mod.EventBusSubscriber(value = Dist.CLIENT, modid = "my_modid", bus = Mod.EventBusSubscriber.Bus.MOD) public class Registration { @OnlyIn(Dist.CLIENT) @SubscribeEvent static void onMenuOpen(@Nonnull OpenMenuEvent event) { if (event.getMenu().getType() == MyRegistry.MY_MENU.get()) { // create main fragment var fragment = new MyFragment(); // pass arguments (optional) var args = new DataSet(); args.putInt("token", event.getMenu().containerId); fragment.setArguments(args); // finish the event with a result event.set(fragment); } } } ``` -------------------------------- ### Reference Registered MenuType Source: https://github.com/blocamlimb/modernui/wiki/Forge-1.18 Use RegistryObject to reference a registered MenuType. This provides a type-safe way to access your menu registration using its ResourceLocation. ```java public class MyRegistry { public static final RegistryObject> MY_MENU = RegistryObject.of(new ResourceLocation("my_modid", "my_menu"), ForgeRegistries.CONTAINERS); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.