123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- /*
- * This file is licensed under the MIT License, part of Roughly Enough Items.
- * Copyright (c) 2018, 2019, 2020 shedaniel
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
- package me.shedaniel.rei;
- import com.google.common.collect.ImmutableSet;
- import net.fabricmc.api.ClientModInitializer;
- import net.fabricmc.api.EnvType;
- import net.fabricmc.api.ModInitializer;
- import net.fabricmc.loader.api.FabricLoader;
- import java.lang.reflect.InvocationTargetException;
- public class RoughlyEnoughItemsInitializer implements ModInitializer {
- @Override
- public void onInitialize() {
- checkRequiredFabricModules();
- checkClothConfig();
-
- if (checkRequiredFabricModules() && checkRequiredFabricModules()) {
- initializeEntryPoint("me.shedaniel.rei.RoughlyEnoughItemsNetwork");
-
- if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
- initializeEntryPoint("me.shedaniel.rei.RoughlyEnoughItemsCore");
- initializeEntryPoint("me.shedaniel.rei.impl.ClientHelperImpl");
- initializeEntryPoint("me.shedaniel.rei.impl.ScreenHelper");
- }
- }
-
- initializeEntryPoint("me.shedaniel.rei.impl.ErrorDisplayer");
- }
-
- public void initializeEntryPoint(String className) {
- try {
- Object instance = Class.forName(className).getConstructor().newInstance();
- if (instance instanceof ModInitializer) {
- ((ModInitializer) instance).onInitialize();
- } else if (instance instanceof ClientModInitializer) {
- ((ClientModInitializer) instance).onInitializeClient();
- }
- } catch (InstantiationException | InvocationTargetException | IllegalAccessException | ClassNotFoundException | NoSuchMethodException e) {
- throw new RuntimeException(e);
- }
- }
-
- public static boolean checkRequiredFabricModules() {
- ImmutableSet<String> requiredModules = FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT ?
- ImmutableSet.<String>builder()
- .add("fabric-api-base")
- .add("fabric-resource-loader-v0")
- .add("fabric-networking-v0")
- .add("fabric-lifecycle-events-v1")
- .add("fabric-rendering-fluids-v1")
- .build() :
- ImmutableSet.<String>builder()
- .add("fabric-api-base")
- .add("fabric-resource-loader-v0")
- .add("fabric-networking-v0")
- .add("fabric-lifecycle-events-v1")
- .build();
- for (String module : requiredModules) {
- boolean moduleLoaded = FabricLoader.getInstance().isModLoaded(module);
- if (!moduleLoaded) {
- RoughlyEnoughItemsState.error("Fabric API is not installed!", "https://www.curseforge.com/minecraft/mc-mods/fabric-api/files/all");
- return false;
- }
- }
-
- return true;
- }
-
- public static boolean checkClothConfig() {
- if (!FabricLoader.getInstance().isModLoaded("cloth-config2")) {
- RoughlyEnoughItemsState.error("Cloth Config is not installed!", "https://www.curseforge.com/minecraft/mc-mods/cloth-config/files/all");
- return false;
- }
-
- return true;
- }
- }
|