net.fabricmc.loader.api.FabricLoader Java Examples

The following examples show how to use net.fabricmc.loader.api.FabricLoader. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MineLittlePony.java    From MineLittlePony with MIT License 6 votes vote down vote up
@Override
public void onInitializeClient() {
    hasHdSkins = FabricLoader.getInstance().isModLoaded("hdskins");
    hasModMenu = FabricLoader.getInstance().isModLoaded("modmenu");

    config = new ClientPonyConfig(GamePaths.getConfigDirectory().resolve("minelp.json"));
    ponyManager = new PonyManager(config);

    KeyBindingHelper.registerKeyBinding(keyBinding);

    ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(ponyManager);

    // convert legacy pony skins
    SkinFilterCallback.EVENT.register(new LegacySkinConverter());

    // general events
    ClientReadyCallback.Handler.register();
    ClientTickCallback.EVENT.register(this::onTick);
    ClientReadyCallback.EVENT.register(this::onClientReady);
    ScreenInitCallback.EVENT.register(this::onScreenInit);
    config.ponyskulls.onChanged(PonySkullRenderer::resolve);

    config.load();

    ModelType.bootstrap();
}
 
Example #2
Source File: CarpetServer.java    From fabric-carpet with MIT License 6 votes vote down vote up
public static void registerCarpetCommands(CommandDispatcher<ServerCommandSource> dispatcher)
{
    TickCommand.register(dispatcher);
    ProfileCommand.register(dispatcher);
    CounterCommand.register(dispatcher);
    LogCommand.register(dispatcher);
    SpawnCommand.register(dispatcher);
    PlayerCommand.register(dispatcher);
    CameraModeCommand.register(dispatcher);
    InfoCommand.register(dispatcher);
    DistanceCommand.register(dispatcher);
    PerimeterInfoCommand.register(dispatcher);
    DrawCommand.register(dispatcher);
    ScriptCommand.register(dispatcher);
    MobAICommand.register(dispatcher);
    // registering command of extensions that has registered before either server is created
    // for all other, they will have them registered when they add themselves
    extensions.forEach(e -> e.registerCommands(dispatcher));
    currentCommandDispatcher = dispatcher;
    
    if (FabricLoader.getInstance().isDevelopmentEnvironment())
        TestCommand.register(dispatcher);
}
 
Example #3
Source File: LibGuiClient.java    From LibGui with MIT License 6 votes vote down vote up
public static LibGuiConfig loadConfig() {
	try {
		File file = new File(FabricLoader.getInstance().getConfigDirectory(),"libgui.json5");
		
		if (!file.exists()) saveConfig(new LibGuiConfig());
		
		JsonObject json = jankson.load(file);
		config =  jankson.fromJson(json, LibGuiConfig.class);
		
		/*
		JsonElement jsonElementNew = jankson.toJson(new LibGuiConfig());
		if(jsonElementNew instanceof JsonObject) {
			JsonObject jsonNew = (JsonObject) jsonElementNew;
			if(json.getDelta(jsonNew).size()>= 0) { //TODO: Insert new keys as defaults into `json` IR object instead of writing the config out, so comments are preserved
				saveConfig(config);
			}
		}*/
	} catch (Exception e) {
		logger.error("[LibGui] Error loading config: {}", e.getMessage());
	}
	return config;
}
 
Example #4
Source File: ViaFabric.java    From ViaFabric with MIT License 6 votes vote down vote up
@Override
public void onInitialize() {
    Via.init(ViaManager.builder()
            .injector(new VRInjector())
            .loader(new VRLoader())
            .commandHandler(new VRCommandHandler())
            .platform(new VRPlatform()).build());

    FabricLoader.getInstance().getModContainer("viabackwards").ifPresent(mod -> MappingDataLoader.enableMappingsCache());

    Via.getManager().init();

    FabricLoader.getInstance().getEntrypoints("viafabric:via_api_initialized", Runnable.class).forEach(Runnable::run);

    CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> dispatcher.register(command("viaversion")));
    CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> dispatcher.register(command("viaver")));
    CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> dispatcher.register(command("vvfabric")));

    config = new VRConfig(FabricLoader.getInstance().getConfigDirectory().toPath().resolve("ViaFabric")
            .resolve("viafabric.yml").toFile());
}
 
Example #5
Source File: VRPlatform.java    From ViaFabric with MIT License 6 votes vote down vote up
@Override
public JsonObject getDump() {
    JsonObject platformSpecific = new JsonObject();
    List<PluginInfo> mods = new ArrayList<>();
    for (ModContainer mod : FabricLoader.getInstance().getAllMods()) {
        mods.add(new PluginInfo(true,
                mod.getMetadata().getId() + " (" + mod.getMetadata().getName() + ")",
                mod.getMetadata().getVersion().getFriendlyString(),
                null,
                mod.getMetadata().getAuthors().stream()
                        .map(info -> info.getName()
                                + (info.getContact().asMap().isEmpty() ? "" : " " + info.getContact().asMap()))
                        .collect(Collectors.toList())
        ));
    }

    platformSpecific.add("mods", GsonUtil.getGson().toJsonTree(mods));
    return platformSpecific;
}
 
Example #6
Source File: ModList.java    From patchwork-api with GNU Lesser General Public License v2.1 6 votes vote down vote up
public List<ModFileScanData> getAllScanData() {
	if (allScanDataCache == null) {
		// Even though ModFileScanData lacks an implementation of Object#equals, the default implementation tests
		// for equality using object identity (a == b). In this case there is only one instance of ModFileScanData
		// for a given mod file (mod files can be shared by multiple mod containers), therefore comparison by object
		// identity alone (`==`) is sufficient.

		allScanDataCache = Collections.unmodifiableList(FabricLoader.getInstance().getAllMods()
				.stream()
				.map(modContainer -> modContainer.getMetadata().getId())
				.map(modid -> getModFileById(modid).getFile().getScanResult())
				.distinct()
				.collect(Collectors.toList()));
	}

	return allScanDataCache;
}
 
Example #7
Source File: SandboxHooks.java    From Sandbox with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void setupGlobal() {
    Set<String> supportedMods = Sets.newHashSet("minecraft", "sandbox", "sandboxapi", "fabricloader");
    Sandbox.unsupportedModsLoaded = FabricLoader.getInstance().getAllMods().stream()
            .map(ModContainer::getMetadata)
            .map(ModMetadata::getId)
            .anyMatch(((Predicate<String>) supportedMods::contains).negate());
    Policy.setPolicy(new AddonSecurityPolicy());

    Registry.REGISTRIES.add(new Identifier("sandbox", "container"), SandboxRegistries.CONTAINER_FACTORIES);

    ((SandboxInternal.Registry) Registry.BLOCK).set(new BasicRegistry<>(Registry.BLOCK, Block.class, WrappingUtil::convert, WrappingUtil::convert));
    ((SandboxInternal.Registry) Registry.ITEM).set(new BasicRegistry<>(Registry.ITEM, Item.class, WrappingUtil::convert, WrappingUtil::convert));
    ((SandboxInternal.Registry) Registry.ENCHANTMENT).set(new BasicRegistry<>((SimpleRegistry<net.minecraft.enchantment.Enchantment>) Registry.ENCHANTMENT, Enchantment.class, WrappingUtil::convert, b -> (Enchantment) b));
    ((SandboxInternal.Registry) Registry.FLUID).set(new BasicRegistry<>(Registry.FLUID, Fluid.class, WrappingUtil::convert, WrappingUtil::convert));
    ((SandboxInternal.Registry) Registry.ENTITY_TYPE).set(new BasicRegistry<>(Registry.ENTITY_TYPE, Entity.Type.class, WrappingUtil::convert, WrappingUtil::convert));
    ((SandboxInternal.Registry) Registry.BLOCK_ENTITY).set(new BasicRegistry((SimpleRegistry) Registry.BLOCK_ENTITY, BlockEntity.Type.class, (Function<BlockEntity.Type, BlockEntityType>) WrappingUtil::convert, (Function<BlockEntityType, BlockEntity.Type>) WrappingUtil::convert, true)); // DONT TOUCH THIS FOR HEAVENS SAKE PLEASE GOD NO
    ((SandboxInternal.Registry) SandboxRegistries.CONTAINER_FACTORIES).set(new BasicRegistry<>(SandboxRegistries.CONTAINER_FACTORIES, ContainerFactory.class, a -> a, a -> a));
}
 
Example #8
Source File: OldLanguageManager.java    From multiconnect with MIT License 5 votes vote down vote up
public static void reloadLanguages() {
    MinecraftClient.getInstance().getLanguageManager().apply(MinecraftClient.getInstance().getResourceManager());
    if (FabricLoader.getInstance().isModLoaded("optifabric")) {
        try {
            Class.forName("net.optifine.Lang").getMethod("resourcesReloaded").invoke(null);
        } catch (ReflectiveOperationException e) {
            LOGGER.error("Failed to force OptiFine to reload language files!", e);
        }
    }
}
 
Example #9
Source File: JavaLanguageAdapter.java    From fabric-loader with Apache License 2.0 5 votes vote down vote up
private static boolean canApplyInterface(String itfString) throws IOException {
	String className = itfString + ".class";

	// TODO: Be a bit more involved
	switch (itfString) {
		case "net/fabricmc/api/ClientModInitializer":
			if (FabricLoader.getInstance().getEnvironmentType() == EnvType.SERVER) {
				return false;
			}
			break;
		case "net/fabricmc/api/DedicatedServerModInitializer":
			if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
				return false;
			}
	}

	InputStream stream = FabricLauncherBase.getLauncher().getResourceAsStream(className);
	if (stream == null) {
		return false;
	}
	ClassReader reader = new ClassReader(stream);

	for (String s : reader.getInterfaces()) {
		if (!canApplyInterface(s)) {
			stream.close();
			return false;
		}
	}

	stream.close();
	return true;
}
 
Example #10
Source File: FabricSparkMod.java    From spark with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onInitialize() {
    FabricSparkMod.mod = this;

    FabricLoader loader = FabricLoader.getInstance();
    this.container = loader.getModContainer("spark")
            .orElseThrow(() -> new IllegalStateException("Unable to get container for spark"));
    this.configDirectory = loader.getConfigDirectory().toPath().resolve("spark");

    // load hooks
    ServerStartCallback.EVENT.register(server -> FabricServerSparkPlugin.register(this, server));
}
 
Example #11
Source File: BleachMainMenu.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
public void render(int p_render_1_, int p_render_2_, float p_render_3_) {
	this.renderBackground();
	fill(0, 0, width, height, 0xff008080);
	
	int copyWidth = this.font.getStringWidth("Copyright Mojang AB. Do not distribute!") + 2;
	
	font.drawWithShadow("Copyright Mojang AB. Do not distribute!", width - copyWidth, height - 24, -1);
	font.drawWithShadow("Fabric: " + FabricLoader.getInstance().getModContainer("fabricloader").get().getMetadata().getVersion().getFriendlyString(), 4, height - 44, -1);
	font.drawWithShadow("Minecraft " + SharedConstants.getGameVersion().getName(), 4, height - 34, -1);
	font.drawWithShadow("Logged in as: §a" + minecraft.getSession().getUsername(), 4, height - 24, -1);
	
	try {
		if (Integer.parseInt(versions.get(1)) > BleachHack.INTVERSION) {
			drawCenteredString(this.font, "§cOutdated BleachHack Version!", width/2, 2, -1);
			drawCenteredString(this.font,"§4[" + versions.get(0) + " > " + BleachHack.VERSION + "]", width/2, 11, -1);
		}
	} catch (Exception e) { }
	
	drawButton("", 0, height - 14, width, height);
	drawButton("§cX", 0, height - 13, 20, height - 1);
	
	int wid = 20;
	for (Window w: windows) {
		if (w.closed) continue;
		Screen.fill(wid, height - 13, wid + 80 - 1, height - 1 - 1, 0xffb0b0b0);
		Screen.fill(wid + 1, height - 13 + 1, wid + 80, height - 1, 0xff000000);
		Screen.fill(wid + 1, height - 13 + 1, wid + 80 - 1, height - 1 - 1, (w.selected ? 0xffb0b0b0 : 0xff858585));
		font.draw(w.title, wid + 2, height - 11, 0x000000);
		wid += 80;
	}
	
	super.render(p_render_1_, p_render_2_, p_render_3_);
	
	particleMang.addParticle(p_render_1_, p_render_2_);
	particleMang.renderParticles();
	
}
 
Example #12
Source File: BleachMainMenu.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
public void render(MatrixStack matrix, int mouseX, int mouseY, float delta) {
	this.renderBackground(matrix);
	fill(matrix, 0, 0, width, height, 0xff008080);
	
	int copyWidth = this.textRenderer.getWidth("Copyright Mojang AB. Do not distribute!") + 2;
	
	textRenderer.drawWithShadow(matrix, "Copyright Mojang AB. Do not distribute!", width - copyWidth, height - 24, -1);
	textRenderer.drawWithShadow(matrix, "Fabric: " + FabricLoader.getInstance().getModContainer("fabricloader").get().getMetadata().getVersion().getFriendlyString(), 4, height - 44, -1);
	textRenderer.drawWithShadow(matrix, "Minecraft " + SharedConstants.getGameVersion().getName(), 4, height - 34, -1);
	textRenderer.drawWithShadow(matrix, "Logged in as: \u00a7a" + client.getSession().getUsername(), 4, height - 24, -1);
	
	try {
		if (Integer.parseInt(versions.get(1)) > BleachHack.INTVERSION) {
			drawCenteredString(matrix, this.textRenderer, "\u00a7cOutdated BleachHack Version!", width/2, 2, -1);
			drawCenteredString(matrix, this.textRenderer,"\u00a74[" + versions.get(0) + " > " + BleachHack.VERSION + "]", width/2, 11, -1);
		}
	} catch (Exception e) { }
	
	drawButton(matrix, "", 0, height - 14, width, height);
	drawButton(matrix, "\u00a7cX", 0, height - 13, 20, height - 1);
	
	int wid = 20;
	for (Window w: windows) {
		if (w.closed) continue;
		Screen.fill(matrix, wid, height - 13, wid + 80 - 1, height - 1 - 1, 0xffb0b0b0);
		Screen.fill(matrix, wid + 1, height - 13 + 1, wid + 80, height - 1, 0xff000000);
		Screen.fill(matrix, wid + 1, height - 13 + 1, wid + 80 - 1, height - 1 - 1, (w.selected ? 0xffb0b0b0 : 0xff858585));
		textRenderer.draw(matrix, w.title, wid + 2, height - 11, 0x000000);
		wid += 80;
	}
	
	super.render(matrix, mouseX, mouseY, delta);
	
	particleMang.addParticle(mouseX, mouseY);
	particleMang.renderParticles(matrix);
	
}
 
Example #13
Source File: BleachMainMenu.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
public void render(int p_render_1_, int p_render_2_, float p_render_3_) {
	//if (windows.get(0).x1 != width / 8 || windows.get(0).y1 != height / 8) minecraft.openScreen(new BleachMainMenu());
	
	this.renderBackground();
	fill(0, 0, width, height, 0xff008080);
	
	int copyWidth = this.font.getStringWidth("Copyright Mojang AB. Do not distribute!") + 2;
	
	font.drawWithShadow("Copyright Mojang AB. Do not distribute!", width - copyWidth, height - 24, -1);
	font.drawWithShadow("Fabric: " + FabricLoader.getInstance().getModContainer("fabricloader").get().getMetadata().getVersion().getFriendlyString(), 4, height - 44, -1);
	font.drawWithShadow("Minecraft " + SharedConstants.getGameVersion().getName(), 4, height - 34, -1);
	font.drawWithShadow("Logged in as: §a" + minecraft.getSession().getUsername(), 4, height - 24, -1);
	
	try {
		if (Integer.parseInt(versions.get(1)) > BleachHack.INTVERSION) {
			drawCenteredString(this.font, "§cOutdated BleachHack Version!", width/2, 2, -1);
			drawCenteredString(this.font,"§4[" + versions.get(0) + " > " + BleachHack.VERSION + "]", width/2, 11, -1);
		}
	} catch (Exception e) { }
	
	drawButton("", 0, height - 14, width, height);
	drawButton("§cX", 0, height - 13, 20, height - 1);
	
	int wid = 20;
	for (Window w: windows) {
		if (w.closed) continue;
		Screen.fill(wid, height - 13, wid + 80 - 1, height - 1 - 1, 0xffb0b0b0);
		Screen.fill(wid + 1, height - 13 + 1, wid + 80, height - 1, 0xff000000);
		Screen.fill(wid + 1, height - 13 + 1, wid + 80 - 1, height - 1 - 1, (w.selected ? 0xffb0b0b0 : 0xff858585));
		font.draw(w.title, wid + 2, height - 11, 0x000000);
		wid += 80;
	}
	
	super.render(p_render_1_, p_render_2_, p_render_3_);
	
	particleMang.addParticle(p_render_1_, p_render_2_);
	particleMang.renderParticles();
	
}
 
Example #14
Source File: VRPlatform.java    From ViaFabric with MIT License 5 votes vote down vote up
public VRPlatform() {
    Path configDir = FabricLoader.getInstance().getConfigDirectory().toPath().resolve("ViaFabric");
    config = new VRViaConfig(configDir.resolve("viaversion.yml").toFile());
    dataFolder = configDir.toFile();
    connectionManager = new VRConnectionManager();
    api = new VRViaAPI();
}
 
Example #15
Source File: LibGuiClient.java    From LibGui with MIT License 5 votes vote down vote up
public static void saveConfig(LibGuiConfig config) {
	try {
		File file = new File(FabricLoader.getInstance().getConfigDirectory(),"libgui.json5");
		
		JsonElement json = jankson.toJson(config);
		String result = json.toJson(true, true);
		try (FileOutputStream out = new FileOutputStream(file, false)) {
			out.write(result.getBytes(StandardCharsets.UTF_8));
		}
	} catch (Exception e) {
		logger.error("[LibGui] Error saving config: {}", e.getMessage());
	}
}
 
Example #16
Source File: TheHallow.java    From the-hallow with MIT License 5 votes vote down vote up
@Override
public void onInitialize() {
	HallowedConfig.sync();
	HallowedEntities.init();
	HallowedBlocks.init();
	HallowedItems.init();
	HallowedRecipes.init();
	HallowedBlockEntities.init();
	HallowedEnchantments.init();
	HallowedCommands.init();
	HallowedFeatures.init();
	HallowedBiomes.init();
	HallowedWorldGen.init();
	HallowedChunkGeneratorType.init();
	HallowedDimensions.init();
	HallowedEvents.init();
	HallowedSounds.init();
	HallowedFluids.init();
	HallowedTags.init();
	HallowedNetworking.init();
	HallowedEvents.init();
	
	MinecraftItems.init();

	if (FabricLoader.getInstance().isModLoaded("libcd")) {
		HallowTweaker.init();
	}
}
 
Example #17
Source File: OptifineSetup.java    From OptiFabric with Mozilla Public License 2.0 5 votes vote down vote up
private void remapOptifine(Path input, File remappedJar) throws Exception {
	String namespace = FabricLoader.getInstance().getMappingResolver().getCurrentRuntimeNamespace();
	System.out.println("Remapping optifine to :" + namespace);

	List<Path> mcLibs = getLibs();
	mcLibs.add(getMinecraftJar());

	RemapUtils.mapJar(remappedJar.toPath(), input, createMappings("official", namespace), mcLibs);
}
 
Example #18
Source File: OptifabricSetup.java    From OptiFabric with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void run() {
	if(!validateLoaderVersion()) return;
	if(!validateMods()) return;

	try {
		OptifineSetup optifineSetup = new OptifineSetup();
		Pair<File, ClassCache> runtime = optifineSetup.getRuntime();

		//Add the optifine jar to the classpath, as
		ClassTinkerers.addURL(runtime.getLeft().toURI().toURL());

		OptifineInjector injector = new OptifineInjector(runtime.getRight());
		injector.setup();

		optifineRuntimeJar = runtime.getLeft();
	} catch (Throwable e) {
		if(!OptifabricError.hasError()){
			OptifineVersion.jarType = OptifineVersion.JarType.INCOMPATIBE;
			OptifabricError.setError("Failed to load optifine, check the log for more info \n\n " + e.getMessage());
		}
		throw new RuntimeException("Failed to setup optifine", e);
	}

	if(FabricLoader.getInstance().isModLoaded("fabric-renderer-indigo")){
		validateIndigoVersion();
		Mixins.addConfiguration("optifabric.indigofix.mixins.json");
	}

	Mixins.addConfiguration("optifabric.optifine.mixins.json");
}
 
Example #19
Source File: OptifineVersion.java    From OptiFabric with Mozilla Public License 2.0 5 votes vote down vote up
public static File findOptifineJar() throws IOException {
	File modsDir = new File(FabricLoader.getInstance().getGameDirectory(), "mods");
	File[] mods = modsDir.listFiles();

	File optifineJar = null;

	if (mods != null) {
		for (File file : mods) {
			if (file.isDirectory()) {
				continue;
			}
			if (file.getName().endsWith(".jar")) {
				JarType type = getJarType(file);
				if (type.error) {
					throw new RuntimeException("An error occurred when trying to find the optifine jar: " + type.name());
				}
				if (type == JarType.OPIFINE_MOD || type == JarType.OPTFINE_INSTALLER) {
					if(optifineJar != null){
						OptifabricError.setError("Found 2 or more optifine jars, please ensure you only have 1 copy of optifine in the mods folder!");
						throw new FileNotFoundException("Multiple optifine jars");
					}
					jarType = type;
					optifineJar =  file;
				}
			}
		}
	}

	if(optifineJar != null){
		return optifineJar;
	}

	OptifabricError.setError("OptiFabric could not find the Optifine jar in the mods folder.");
	throw new FileNotFoundException("Could not find optifine jar");
}
 
Example #20
Source File: LibGuiTest.java    From LibGui with MIT License 5 votes vote down vote up
@Override
public void onInitialize() {
	Registry.register(Registry.ITEM, new Identifier(MODID, "client_gui"), new GuiItem());
	
	GUI_BLOCK = new GuiBlock();
	Registry.register(Registry.BLOCK, new Identifier(MODID, "gui"), GUI_BLOCK);
	GUI_BLOCK_ITEM = new BlockItem(GUI_BLOCK, new Item.Settings().group(ItemGroup.MISC));
	Registry.register(Registry.ITEM, new Identifier(MODID, "gui"), GUI_BLOCK_ITEM);
	GUI_BLOCKENTITY_TYPE = BlockEntityType.Builder.create(GuiBlockEntity::new, GUI_BLOCK).build(null);
	Registry.register(Registry.BLOCK_ENTITY_TYPE, new Identifier(MODID, "gui"), GUI_BLOCKENTITY_TYPE);
	
	GUI_SCREEN_HANDLER_TYPE = ScreenHandlerRegistry.registerSimple(new Identifier(MODID, "gui"), (int syncId, PlayerInventory inventory) -> {
		return new TestDescription(GUI_SCREEN_HANDLER_TYPE, syncId, inventory, ScreenHandlerContext.EMPTY);
	});

	Optional<ModContainer> containerOpt = FabricLoader.getInstance().getModContainer("jankson");
	if (containerOpt.isPresent()) {
		ModContainer jankson = containerOpt.get();
		System.out.println("Jankson root path: "+jankson.getRootPath());
		try {
			Files.list(jankson.getRootPath()).forEach((path)->{
				path.getFileSystem().getFileStores().forEach((store)->{
					System.out.println("        Filestore: "+store.name());
				});
				System.out.println("    "+path.toAbsolutePath());
			});
		} catch (IOException e) {
			e.printStackTrace();
		}
		Path modJson = jankson.getPath("/fabric.mod.json");
		System.out.println("Jankson fabric.mod.json path: "+modJson);
		System.out.println(Files.exists(modJson) ? "Exists" : "Does Not Exist");
	} else {
		System.out.println("Container isn't present!");
	}
}
 
Example #21
Source File: DistExecutor.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static <T> T runForDist(Supplier<Supplier<T>> clientTarget, Supplier<Supplier<T>> serverTarget) {
	switch (FabricLoader.getInstance().getEnvironmentType()) {
	case CLIENT:
		return clientTarget.get().get();
	case SERVER:
		return serverTarget.get().get();
	default:
		throw new IllegalArgumentException("UNSIDED?");
	}
}
 
Example #22
Source File: ModList.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
public ModFileInfo getModFileById(String modId) {
	ModContainer modContainer = FabricLoader.getInstance().getModContainer(modId).orElse(null);

	if (modContainer == null) {
		return null;
	}

	return getModFileByContainer(modContainer);
}
 
Example #23
Source File: PatchworkFML.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void onInitialize() {
	ServerStartCallback.EVENT.register(server -> LogicalSidedProvider.setServer(() -> server));
	ServerStopCallback.EVENT.register(server -> LogicalSidedProvider.setServer(null));

	Object instance = FabricLoader.getInstance().getGameInstance();

	DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> LogicalSidedProvider.setClient(() -> (MinecraftClient) instance));
	DistExecutor.runWhenOn(Dist.DEDICATED_SERVER, () -> () -> LogicalSidedProvider.setServer(() -> (MinecraftServer) instance));
}
 
Example #24
Source File: ViaFabric.java    From ViaFabric with MIT License 4 votes vote down vote up
public static String getVersion() {
    return FabricLoader.getInstance().getModContainer("viafabric")
            .get().getMetadata().getVersion().getFriendlyString();
}
 
Example #25
Source File: ModList.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
public boolean isLoaded(String modId) {
	// Patchwork: use Fabric Loader lookup instead of an internal one
	return FabricLoader.getInstance().isModLoaded(modId);
}
 
Example #26
Source File: PatchworkMappingService.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
private static boolean runtimeNamespaceIsIntermediary() {
	return FabricLoader.getInstance().getMappingResolver().getCurrentRuntimeNamespace().equals(INTERMEDIARY);
}
 
Example #27
Source File: VRPlatform.java    From ViaFabric with MIT License 4 votes vote down vote up
public static MinecraftServer getServer() {
    if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
        return getIntegratedServer();
    }
    return (MinecraftServer) FabricLoader.getInstance().getGameInstance();
}
 
Example #28
Source File: OptifabricSetup.java    From OptiFabric with Mozilla Public License 2.0 4 votes vote down vote up
private ModMetadata getModMetaData(String modId) {
	Optional<ModContainer> modContainer = FabricLoader.getInstance().getModContainer(modId);
	return modContainer.map(ModContainer::getMetadata).orElse(null);
}
 
Example #29
Source File: Sandbox.java    From Sandbox with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public Side getSide() {
    return FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT ? Side.CLIENT : Side.SERVER;
}
 
Example #30
Source File: FabricPlatformInfo.java    From spark with GNU General Public License v3.0 4 votes vote down vote up
private Optional<String> getModVersion(String mod) {
    return FabricLoader.getInstance().getModContainer(mod).map(container -> container.getMetadata().getVersion().getFriendlyString());
}