Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to OneConfig are documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added
- Mods that [Hotwire](https://modrinth.com/mod/irenehotwire) turns off, turns on, adds or updates while the game runs keep their settings, mod cards and HUDs, including when a profile was switched to, created or renamed while they were off
- API: `oneconfig:config` entrypoints of mods that Hotwire adds or updates while the game runs are run as the mod starts

## [1.9.1] - 2026-11-22

### Added
Expand Down
7 changes: 7 additions & 0 deletions buildSrc/src/main/kotlin/OneConfigSetupPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,13 @@ class OneConfigSetupPlugin : Plugin<Project> {
}
}

// Hotwire's API has no Minecraft types, so one of its builds serves every version. Its published jar keeps
// the API in a jar nested inside, which is the part to compile against
val hotwire = configurations.detachedConfiguration(
dependencies.create("maven.modrinth:irenehotwire:0.9.5.1-beta+mc26.1-26.3")
).apply { isTransitive = false }
"compileOnly"(zipTree(hotwire.elements.map { it.single() }).matching { include("META-INF/jars/hotwire-core.jar") })

"annotationProcessor"(versionedCatalog["mixin.squared"])

if (enableMoulRelocatorKsp) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.polyfrost.oneconfig.api.platform.v1.internal;

import com.google.common.collect.Iterables;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import net.fabricmc.loader.api.FabricLoader;
Expand Down Expand Up @@ -41,13 +43,17 @@ public void displayChatMessage(Component text) {
*///?}
}

// by its own id, the mod each copy stands in for that Hotwire runs in place of a mod it could not update in place
public static volatile Map<String, String> liveCopies = Collections.emptyMap();

@Override
public Set<ModInfo> getMods() {
return FabricLoader.getInstance().getAllMods().stream()
.map(mod -> {
var metadata = mod.getMetadata();
return new ModInfo(
metadata.getId(),
// so the copy's settings, snapshots and cards stay those of the mod it stands in for
liveCopies.getOrDefault(metadata.getId(), metadata.getId()),
metadata.getName(),
metadata.getVersion().getFriendlyString(),
Iterables.getFirst(mod.getRootPaths(), null),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import com.mojang.brigadier.Command;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -56,6 +57,7 @@
import org.polyfrost.oneconfig.api.platform.v1.Platform;
import org.polyfrost.oneconfig.internal.compat.CompatLoader;
import org.polyfrost.oneconfig.internal.compat.ConfigEntrypoints;
import org.polyfrost.oneconfig.internal.compat.HotwireLifecycle;
import org.polyfrost.oneconfig.internal.compat.KaleidoCompat;
import org.polyfrost.oneconfig.internal.compat.toggle.ModGates;
import org.polyfrost.oneconfig.internal.ui.api.ConfigRegistry;
Expand Down Expand Up @@ -343,6 +345,8 @@ private static void registerEventHandlers() {
//? if wwaypoints_compat
WWaypointsCompat.register();
ThemeRegistry.INSTANCE.loadFromConfig();
// names Hotwire's types, so it cannot be loaded without Hotwire
if (FabricLoader.getInstance().isModLoaded("hotwire")) HotwireLifecycle.register();
});
EventManager.register(WorldEvent.Load.class, e -> {
showFirstLaunchNotification();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.polyfrost.oneconfig.api.config.v1.ConfigEntrypoint;
import org.polyfrost.oneconfig.api.config.v1.ConfigManager;
import org.polyfrost.oneconfig.api.config.v1.Tree;
import org.polyfrost.oneconfig.api.platform.v1.internal.CompatibilityPlatformImpl;
import org.polyfrost.oneconfig.api.platform.v1.ModInfo;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer;
Expand Down Expand Up @@ -76,6 +77,7 @@ private record Skipped(String modId, Runnable extraction) {
// keyed so a hook that fires more than once before the mod is decided is only retried once
private static final Map<String, Map<Object, Skipped>> skippedExtractions = new HashMap<>();
private static final AtomicBoolean registered = new AtomicBoolean();
private static final AtomicBoolean listening = new AtomicBoolean();
private static final Map<String, String> treeOwners = new ConcurrentHashMap<>();
// configs claimed only because they existed before the entrypoint ran, which do not count when it threw
private static final Set<String> earlierConfigs = ConcurrentHashMap.newKeySet();
Expand Down Expand Up @@ -152,21 +154,84 @@ public static List<Tree> ownedTrees(String modId) {
public static void registerAll() {
if (!registered.compareAndSet(false, true)) return;
if (providers().isEmpty()) return;
ConfigManager.addTreeRegistrationListener(ConfigEntrypoints::onTreeRegistered);
ConfigManager.addConfigSubmissionListener(ConfigEntrypoints::onConfigSubmitted);
listen();
claimEarlierConfigs();
// a mod may name more than one entrypoint, which only decide together whether its original is extracted
Map<String, List<Provider>> byMod = new LinkedHashMap<>();
for (Provider provider : providers()) byMod.computeIfAbsent(provider.modId, k -> new ArrayList<>()).add(provider);
byMod.forEach((modId, entrypoints) -> undecided.put(modId, register(modId, entrypoints)));
}

private static void listen() {
if (!listening.compareAndSet(false, true)) return;
ConfigManager.addTreeRegistrationListener(ConfigEntrypoints::onTreeRegistered);
ConfigManager.addConfigSubmissionListener(ConfigEntrypoints::onConfigSubmitted);
}

/**
* Runs the entrypoints of mods that Hotwire started after the game did, to be decided by the next
* {@link #finishStarted()}. A mod that was already decided is left alone, as it only gained other entrypoints,
* unless it is a copy, which starts over what it stands in for.
* <br>
* shortcut: a second config entrypoint that an update adds to a decided mod only runs at the next launch, track
* which definitions ran if a mod ever does that
*/
public static void registerStarted(Collection<String> modIds) {
// registerAll has not run yet and will find them itself
if (!registered.get()) return;
Set<String> started = new HashSet<>();
for (String id : modIds) {
String original = CompatibilityPlatformImpl.liveCopies.get(id);
if (original != null) forgetDecision(original);
started.add(original == null ? id : original);
}
Map<String, List<Provider>> byMod = new LinkedHashMap<>();
for (Provider provider : providers()) {
if (started.contains(provider.modId) && !isDecided(provider.modId)) byMod.computeIfAbsent(provider.modId, k -> new ArrayList<>()).add(provider);
}
if (byMod.isEmpty()) return;
listen();
claimEarlierConfigs();
byMod.forEach((modId, entrypoints) -> {
// as CompatLoader did for the providers it saw when it initialized
CompatLoader.INSTANCE.getNativeLoadedConfigs().add(modId);
undecided.put(modId, register(modId, entrypoints));
});
}

private static synchronized void forgetDecision(String modId) {
succeeded.remove(modId);
failed.remove(modId);
}

/**
* Looks the entrypoints up again at their next use, for when the mods that provide them changed
*/
static void forgetProviders() {
synchronized (DISCOVERY_LOCK) {
providers = null;
}
defaultOpeners.clear();
}

/**
* Decides for each mod that ran an entrypoint whether to keep its configs or extract its original. Called after
* {@link ConfigManager#initialize()}, as a config only counts once its tree was built and registered.
*/
// compat waits for this, so it always ends by releasing it even if deciding a mod threw
public static void finishRegistration() {
finishRegistration(true);
}

/**
* As {@link #finishRegistration()} for {@link #registerStarted}, where a provider that has not run is left alone,
* as it may be of a mod that Hotwire is yet to start
*/
public static void finishStarted() {
finishRegistration(false);
}

// compat waits for this, so it always ends by releasing it even if deciding a mod threw
private static void finishRegistration(boolean all) {
try {
Map<String, Boolean> pending = new LinkedHashMap<>(undecided);
undecided.clear();
Expand All @@ -185,7 +250,7 @@ public static void finishRegistration() {
});
// providers registerAll never reached, such as when it threw partway, would otherwise stay skipped forever
for (String modId : providerIds()) {
if (pending.containsKey(modId) || isDecided(modId)) continue;
if (!all || pending.containsKey(modId) || isDecided(modId)) continue;
LOGGER.warn("The OneConfig config entrypoint of {} never ran, extracting its original config instead", modId);
try {
fallBackToOriginal(modId);
Expand Down Expand Up @@ -497,8 +562,9 @@ private static List<Provider> providers() {
List<Provider> found = new ArrayList<>();
try {
for (EntrypointContainer<ConfigEntrypoint> container : FabricLoader.getInstance().getEntrypointContainers(ConfigEntrypoint.ENTRYPOINT, ConfigEntrypoint.class)) {
String id = container.getProvider().getMetadata().getId();
found.add(new Provider(
container.getProvider().getMetadata().getId(),
CompatibilityPlatformImpl.liveCopies.getOrDefault(id, id),
container.getDefinition(),
container::getEntrypoint
));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*
* This file is part of OneConfig.
* OneConfig - Next Generation Config Library for Minecraft: Java Edition
* Copyright (C) 2021~2024 Polyfrost.
* <https://polyfrost.org> <https://github.com/Polyfrost/>
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* OneConfig is licensed under the terms of version 3 of the GNU Lesser
* General Public License as published by the Free Software Foundation, AND
* under the Additional Terms Applicable to OneConfig, as published by Polyfrost,
* either version 1.0 of the Additional Terms, 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. If not, see <https://www.gnu.org/licenses/>. You should
* have also received a copy of the Additional Terms Applicable
* to OneConfig, as published by Polyfrost. If not, see
* <https://polyfrost.org/legal/oneconfig/additional-terms>
*/

package org.polyfrost.oneconfig.internal.compat;

import dev.moon.hotwire.api.HotwireApi;
import dev.moon.hotwire.api.ModLifecycleListener;
import dev.moon.hotwire.api.ModState;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.polyfrost.oneconfig.api.config.v1.CompatSnapshots;
import org.polyfrost.oneconfig.api.config.v1.ConfigManager;
import org.polyfrost.oneconfig.api.hud.v1.HudManager;
import org.polyfrost.oneconfig.api.platform.v1.internal.CompatibilityPlatformImpl;
import org.polyfrost.oneconfig.internal.ui.api.ConfigRegistry;
import org.polyfrost.oneconfig.internal.ui.api.ConfigSource;

/**
* OneConfig's part in Hotwire turning mods off and on, adding and updating them while the game runs. Hotwire takes a
* mod's objects out of OneConfig's collections and puts the same ones back itself, so what is left is what needs to
* know about profiles and about when new configs are initialized. Every call comes on the game thread.
* <br>
* This is the only class that names Hotwire's types, so it must only be loaded when Hotwire is installed.
*/
public final class HotwireLifecycle implements ModLifecycleListener {
private static final Logger LOGGER = LogManager.getLogger("OneConfig/Hotwire");

private HotwireLifecycle() {
}

public static void register() {
HotwireApi.getInstance().addLifecycleListener(new HotwireLifecycle());
}

// the whole profile rather than what these mods own, which Hotwire decides in ways OneConfig cannot mirror
@Override
public void prepareOff(List<String> ids) {
try {
ConfigManager.active().saveAll();
CompatSnapshots.INSTANCE.onProfileSaving(ConfigManager.activeProfile());
} catch (Throwable t) {
LOGGER.error("Failed to save the settings of {} before Hotwire turns them off", ids, t);
}
}

// by what is out of place rather than by which mods came back, as their objects only are if the profile changed
@Override
public void finishOn(List<String> ids) {
try {
refreshMods();
ConfigManager.rebindDetached();
HudManager.INSTANCE.reloadForNewProviders();
ConfigRegistry.INSTANCE.loadFrom(ConfigManager.active(), ConfigSource.OC);
} catch (Throwable t) {
LOGGER.error("Failed to bind {} to the active profile after Hotwire turned them on", ids, t);
}
}

// the mods are in the loader's list by now, which compat goes by to tell whose config an initializer builds
@Override
public void prepareStart(List<String> ids) {
try {
refreshMods();
} catch (Throwable t) {
LOGGER.error("Failed to read the mods again before Hotwire starts {}", ids, t);
}
ConfigManager.reopenInitialization();
}

@Override
public void finishStart(List<String> ids, boolean ok) {
try {
if (ok) {
ConfigEntrypoints.registerStarted(ids);
} else {
ConfigManager.pendingConfigs().forEach(ConfigManager::cancelInitialization);
}
} catch (Throwable t) {
LOGGER.error("Failed to set up the configs of {}, which Hotwire started", ids, t);
} finally {
// also what closes the window prepareStart opened
try {
ConfigManager.initialize();
} finally {
if (ok) ConfigEntrypoints.finishStarted();
}
}
}

@Override
public void finishUpdate(List<String> ids) {
try {
refreshMods();
} catch (Throwable t) {
LOGGER.error("Failed to read the mods again after Hotwire updated {}", ids, t);
}
}

private static void refreshMods() {
Map<String, String> copies = new HashMap<>();
for (ModState mod : HotwireApi.getInstance().getMods()) {
if (mod.copyOf() != null) copies.put(mod.id(), mod.copyOf());
}
CompatibilityPlatformImpl.liveCopies = copies;
CompatLoader.INSTANCE.refreshMods();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ object CompatLoader {
var queuedCompatsRan = false
private set

private val pathFactory: MutableMap<ModInfo, (String) -> String> = mutableMapOf()
@Volatile
private var pathFactory: Map<ModInfo, (String) -> String> = emptyMap()

// concurrent as compat hooks may fire on other threads while ConfigEntrypoints un-marks a failed mod
val nativeLoadedConfigs: MutableSet<String> = ConcurrentHashMap.newKeySet()
Expand Down Expand Up @@ -174,14 +175,30 @@ object CompatLoader {
private var entrypointsDecided = false

init {
indexMods()

// filtered so a mod whose entrypoint already failed is never marked again
nativeLoadedConfigs.addAll(ConfigEntrypoints.providerModIds().filter(ConfigEntrypoints::provides))
}

/**
* Reads the loader's mod list again into everything built from it, for when mods changed while the game runs
*/
fun refreshMods() {
ModInfo.forgetLoadedMods()
indexMods()
ConfigEntrypoints.forgetProviders()
}

private fun indexMods() {
val paths = HashMap<ModInfo, (String) -> String>()
ModInfo.loadedMods.forEach { mod ->
mod.file?.let {
pathFactory[mod] = it.toUri().toString()::plus
paths[mod] = it.toUri().toString()::plus
}
}

// filtered so a mod whose entrypoint already failed is never marked again
nativeLoadedConfigs.addAll(ConfigEntrypoints.providerModIds().filter(ConfigEntrypoints::provides))
pathFactory = paths
ownerByClassName.clear()
}

/**
Expand Down Expand Up @@ -230,4 +247,4 @@ object CompatLoader {
}
if (!queued) init()
}
}
}
1 change: 1 addition & 0 deletions minecraft/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"chattweaks": "<1.2.3",
"crashpatch": "<2.3.0",
"evergreenhud": "<3.10.0",
"hotwire": "<0.9.2-beta",
"hybedwars": "<1.2.1",
"legacyskyblock": "<2.10.1",
"noteable": "<3.1.0",
Expand Down
Loading