fix: perform reload when changing setting in combined screen
This commit is contained in:
parent
796bbe40e6
commit
30b508513f
|
@ -1,9 +1,10 @@
|
|||
import io.gitlab.jfronny.scripts.*
|
||||
|
||||
plugins {
|
||||
id("jfmod") version "1.4-SNAPSHOT"
|
||||
id("jfmod") version "1.5-SNAPSHOT"
|
||||
}
|
||||
|
||||
allprojects { group = "io.gitlab.jfronny" }
|
||||
base.archivesName = "respackopts"
|
||||
|
||||
repositories {
|
||||
maven("https://maven.vram.io/") {
|
||||
name = "FREX/Canvas"
|
||||
|
@ -20,19 +21,39 @@ repositories {
|
|||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
modImplementation("net.fabricmc.fabric-api:fabric-api:${prop("fabric_version")}")
|
||||
include(modImplementation("io.gitlab.jfronny:muscript:${prop("muscript_version")}")!!)
|
||||
modImplementation("io.gitlab.jfronny.libjf:libjf-data-manipulation-v0:${prop("libjf_version")}")
|
||||
modImplementation("io.gitlab.jfronny.libjf:libjf-config-core-v1:${prop("libjf_version")}")
|
||||
modImplementation("io.gitlab.jfronny.libjf:libjf-config-ui-tiny-v1:${prop("libjf_version")}")
|
||||
val fabricVersion = "0.87.0+1.20.1"
|
||||
val muscriptVersion = "1.3-SNAPSHOT"
|
||||
jfMod {
|
||||
minecraftVersion = "1.20.1"
|
||||
yarn("build.10")
|
||||
loaderVersion = "0.14.22"
|
||||
libJfVersion = "3.12.0"
|
||||
|
||||
modLocalRuntime("io.gitlab.jfronny.libjf:libjf-devutil:${prop("libjf_version")}") {
|
||||
exclude("net.fabricmc") // required to work around duplicate fabric loaders
|
||||
}
|
||||
modLocalRuntime("com.terraformersmc:modmenu:7.0.1") {
|
||||
modrinth {
|
||||
projectId = "respackopts"
|
||||
requiredDependencies.addAll("fabric-api", "libjf")
|
||||
optionalDependencies.add("modmenu")
|
||||
}
|
||||
curseforge {
|
||||
projectId = "430090"
|
||||
requiredDependencies.addAll("fabric-api", "libjf")
|
||||
optionalDependencies.add("modmenu")
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
modImplementation("net.fabricmc.fabric-api:fabric-api:$fabricVersion")
|
||||
include(modImplementation("io.gitlab.jfronny:muscript:$muscriptVersion")!!)
|
||||
modImplementation("io.gitlab.jfronny.libjf:libjf-data-manipulation-v0:${jfMod.libJfVersion.get()}")
|
||||
modImplementation("io.gitlab.jfronny.libjf:libjf-config-core-v1:${jfMod.libJfVersion.get()}")
|
||||
modImplementation("io.gitlab.jfronny.libjf:libjf-config-ui-tiny-v1:${jfMod.libJfVersion.get()}")
|
||||
|
||||
val nofabric: Action<ExternalModuleDependency> = Action {
|
||||
exclude("net.fabricmc") // required to work around duplicate fabric loaders
|
||||
}
|
||||
modLocalRuntime("io.gitlab.jfronny.libjf:libjf-devutil:${jfMod.libJfVersion.get()}", nofabric)
|
||||
modLocalRuntime("com.terraformersmc:modmenu:7.2.1", nofabric)
|
||||
modClientCompileOnly("com.terraformersmc:modmenu:7.2.1", nofabric)
|
||||
|
||||
modClientCompileOnly("io.vram:frex-fabric:20.0.+")
|
||||
modClientCompileOnly("dev.notalpha:dashloader:5.0.0-beta.1+1.20.0")
|
||||
|
|
|
@ -22,6 +22,11 @@ The content imported to your shader by the integrations will equal the dumped co
|
|||
If your conditions aren't working as expected, you can use `/rpoc dump scope` to output muScript code representing the scope passed to your conditions.
|
||||
Comparing this with your condition should help you figure out most issues.
|
||||
|
||||
## Dump asset
|
||||
You can dump individual files with `/rpoc dump asset <identifier>`.
|
||||
This allows you to see the actual file minecraft will use for a given identifier.
|
||||
This is especially useful when using file expansion.
|
||||
|
||||
## Verify that the option you are using exists
|
||||
One common issue is that you removed an option but still use it somewhere.
|
||||
The log will usually reference that option and the source.
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
# https://fabricmc.net/develop/
|
||||
minecraft_version=1.20.1
|
||||
yarn_mappings=build.8
|
||||
loader_version=0.14.21
|
||||
|
||||
maven_group=io.gitlab.jfronny
|
||||
archives_base_name=respackopts
|
||||
|
||||
modrinth_id=respackopts
|
||||
modrinth_required_dependencies=fabric-api, libjf
|
||||
modrinth_optional_dependencies=modmenu
|
||||
curseforge_id=430090
|
||||
curseforge_required_dependencies=fabric-api, libjf
|
||||
curseforge_optional_dependencies=modmenu
|
||||
|
||||
fabric_version=0.84.0+1.20.1
|
||||
libjf_version=3.8.0
|
||||
muscript_version=1.3-SNAPSHOT
|
|
@ -1,21 +1,28 @@
|
|||
package io.gitlab.jfronny.respackopts;
|
||||
|
||||
import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import io.gitlab.jfronny.commons.throwable.ThrowingConsumer;
|
||||
import io.gitlab.jfronny.commons.throwable.ThrowingSupplier;
|
||||
import io.gitlab.jfronny.respackopts.util.MetaCache;
|
||||
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
|
||||
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.fabricmc.loader.api.Version;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.command.argument.IdentifierArgumentType;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.*;
|
||||
import java.nio.file.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal;
|
||||
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.*;
|
||||
|
||||
public class RpoClientCommand {
|
||||
private static final Version VERSION = FabricLoader.getInstance().getModContainer(Respackopts.ID).get().getMetadata().getVersion();
|
||||
private static final Version VERSION = FabricLoader.getInstance().getModContainer(Respackopts.ID).orElseThrow().getMetadata().getVersion();
|
||||
public static void register() {
|
||||
ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> {
|
||||
Command<FabricClientCommandSource> getVersion = ctx -> {
|
||||
|
@ -35,6 +42,11 @@ public class RpoClientCommand {
|
|||
MetaCache.forEach((id, branch) -> ctx.getSource().sendFeedback(dump(branch.executionScope().getOverrides().toExpr().toString(), branch.packId() + ".mu")));
|
||||
return 1;
|
||||
};
|
||||
Command<FabricClientCommandSource> dumpAsset = ctx -> {
|
||||
Identifier id = ctx.getArgument("asset", Identifier.class);
|
||||
ctx.getSource().sendFeedback(dump(() -> MinecraftClient.getInstance().getResourceManager().open(id), id.getNamespace() + "/" + id.getPath()));
|
||||
return 1;
|
||||
};
|
||||
Command<FabricClientCommandSource> reload = ctx -> {
|
||||
MetaCache.clear();
|
||||
CompletableFuture.allOf(RespackoptsClient.forceReloadResources(), RespackoptsClient.reloadIntegratedServerData())
|
||||
|
@ -51,20 +63,33 @@ public class RpoClientCommand {
|
|||
.then(literal("dump").executes(dumpConfig)
|
||||
.then(literal("config").executes(dumpConfig))
|
||||
.then(literal("scope").executes(dumpScope))
|
||||
.then(literal("glsl").executes(dumpGlsl)))
|
||||
.then(literal("glsl").executes(dumpGlsl))
|
||||
.then(literal("asset").then(argument("asset", IdentifierArgumentType.identifier()).executes(dumpAsset))))
|
||||
.then(literal("version").executes(getVersion))
|
||||
.then(literal("reload").executes(reload)));
|
||||
});
|
||||
}
|
||||
|
||||
private static final Path dumpPath = FabricLoader.getInstance().getGameDir().resolve("respackopts");
|
||||
private static final Path dumpPath = FabricLoader.getInstance().getGameDir().resolve("respackopts").toAbsolutePath();
|
||||
private static Text dump(String text, String fileName) {
|
||||
try {
|
||||
if (!Files.exists(dumpPath)) Files.createDirectories(dumpPath);
|
||||
Path filePath = dumpPath.resolve(fileName);
|
||||
try (BufferedWriter bw = Files.newBufferedWriter(filePath, StandardOpenOption.CREATE)) {
|
||||
bw.write(text);
|
||||
return dump(path -> Files.writeString(path, text, StandardOpenOption.CREATE), fileName);
|
||||
}
|
||||
|
||||
private static Text dump(ThrowingSupplier<InputStream, IOException> content, String fileName) {
|
||||
return dump(path -> {
|
||||
try (InputStream is = content.get();
|
||||
OutputStream os = Files.newOutputStream(path, StandardOpenOption.CREATE)) {
|
||||
IOUtils.copy(is, os);
|
||||
}
|
||||
}, fileName);
|
||||
}
|
||||
|
||||
private static Text dump(ThrowingConsumer<Path, IOException> content, String fileName) {
|
||||
try {
|
||||
Path filePath = dumpPath.resolve(fileName).normalize();
|
||||
if (!filePath.startsWith(dumpPath)) throw new IOException("Illegal path");
|
||||
Files.createDirectories(filePath.getParent());
|
||||
content.accept(filePath);
|
||||
return Text.translatable("respackopts.dumpSucceeded", filePath.toAbsolutePath());
|
||||
}
|
||||
catch (Throwable e) {
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
package io.gitlab.jfronny.respackopts.integration;
|
||||
|
||||
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
|
||||
import com.terraformersmc.modmenu.api.ModMenuApi;
|
||||
import io.gitlab.jfronny.respackopts.Respackopts;
|
||||
import io.gitlab.jfronny.respackopts.RespackoptsClient;
|
||||
|
||||
public class ModMenuIntegration implements ModMenuApi {
|
||||
@Override
|
||||
public ConfigScreenFactory<?> getModConfigScreenFactory() {
|
||||
Respackopts.LOGGER.info("JOEBIDEN");
|
||||
return parent -> {
|
||||
io.gitlab.jfronny.libjf.config.api.v2.ui.ConfigScreenFactory.Built<?> built = io.gitlab.jfronny.libjf.config.api.v2.ui.ConfigScreenFactory.getInstance().create(Respackopts.CONFIG, parent);
|
||||
built.onSave(() -> {
|
||||
if (RespackoptsClient.forcePackReload) {
|
||||
RespackoptsClient.forceReloadResources();
|
||||
}
|
||||
});
|
||||
return built.get();
|
||||
};
|
||||
}
|
||||
}
|
|
@ -31,17 +31,21 @@ public class MetaCache {
|
|||
CacheKey k;
|
||||
// Remove the key and ones that share a property
|
||||
// Example: if an old pack has the same data location but a different name, it should still be removed
|
||||
if ((k = KEYS_BY_DATA_LOCATION.remove(key.dataLocation())) != null) remove(k);
|
||||
if ((k = KEYS_BY_PACK_NAME.remove(key.packName())) != null) remove(k);
|
||||
if ((k = KEYS_BY_DISPLAY_NAME.remove(key.displayName())) != null) remove(k);
|
||||
PACK_STATES.remove(key);
|
||||
synchronized (PACK_STATES) {
|
||||
if ((k = KEYS_BY_DATA_LOCATION.remove(key.dataLocation())) != null) remove(k);
|
||||
if ((k = KEYS_BY_PACK_NAME.remove(key.packName())) != null) remove(k);
|
||||
if ((k = KEYS_BY_DISPLAY_NAME.remove(key.displayName())) != null) remove(k);
|
||||
PACK_STATES.remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
public static void clear() {
|
||||
PACK_STATES.clear();
|
||||
KEYS_BY_DISPLAY_NAME.clear();
|
||||
KEYS_BY_PACK_NAME.clear();
|
||||
KEYS_BY_DATA_LOCATION.clear();
|
||||
synchronized (PACK_STATES) {
|
||||
PACK_STATES.clear();
|
||||
KEYS_BY_DISPLAY_NAME.clear();
|
||||
KEYS_BY_PACK_NAME.clear();
|
||||
KEYS_BY_DATA_LOCATION.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public static void addFromScan(String displayName, String packName, PackMeta meta, Path dataLocation) {
|
||||
|
@ -62,10 +66,12 @@ public class MetaCache {
|
|||
CacheKey key = new CacheKey(displayName, packName, dataLocation);
|
||||
CachedPackState state = new CachedPackState(key, meta, branch);
|
||||
remove(key);
|
||||
PACK_STATES.put(key, state);
|
||||
KEYS_BY_DISPLAY_NAME.put(key.displayName(), key);
|
||||
KEYS_BY_PACK_NAME.put(key.packName(), key);
|
||||
KEYS_BY_DATA_LOCATION.put(key.dataLocation(), key);
|
||||
synchronized (PACK_STATES) {
|
||||
PACK_STATES.put(key, state);
|
||||
KEYS_BY_DISPLAY_NAME.put(key.displayName(), key);
|
||||
KEYS_BY_PACK_NAME.put(key.packName(), key);
|
||||
KEYS_BY_DATA_LOCATION.put(key.dataLocation(), key);
|
||||
}
|
||||
// Move old configs to the new location
|
||||
if (!dataLocation.startsWith(Respackopts.FALLBACK_CONF_DIR)) {
|
||||
Path legacyLocation = Respackopts.FALLBACK_CONF_DIR.resolve(meta.id + ".json");
|
||||
|
@ -84,8 +90,10 @@ public class MetaCache {
|
|||
public static CompletableFuture<Void> save(SaveHook.Arguments args) {
|
||||
if (RespackoptsConfig.debugLogs)
|
||||
Respackopts.LOGGER.info("Saving configs");
|
||||
for (Map.Entry<CacheKey, CachedPackState> e : PACK_STATES.entrySet()) {
|
||||
save(e.getKey().dataLocation(), e.getValue().configBranch());
|
||||
synchronized (PACK_STATES) {
|
||||
for (Map.Entry<CacheKey, CachedPackState> e : PACK_STATES.entrySet()) {
|
||||
save(e.getKey().dataLocation(), e.getValue().configBranch());
|
||||
}
|
||||
}
|
||||
List<CompletableFuture<Void>> futures = new ArrayList<>();
|
||||
for (SaveHook hook : FabricLoader.getInstance().getEntrypoints(Respackopts.ID + ":save_hook", SaveHook.class)) {
|
||||
|
@ -168,8 +176,10 @@ public class MetaCache {
|
|||
StringBuilder sb = new StringBuilder("Could not get pack with \"");
|
||||
sb.append(key);
|
||||
sb.append("\" (available: ");
|
||||
for (CacheKey path : PACK_STATES.keySet()) {
|
||||
sb.append(path).append(", ");
|
||||
synchronized (PACK_STATES) {
|
||||
for (CacheKey path : PACK_STATES.keySet()) {
|
||||
sb.append(path).append(", ");
|
||||
}
|
||||
}
|
||||
throw new NullPointerException(sb.substring(0, sb.length() - 2) + ')');
|
||||
}
|
||||
|
@ -177,8 +187,10 @@ public class MetaCache {
|
|||
}
|
||||
|
||||
public static <TEx extends Exception> void forEach(ThrowingBiConsumer<CacheKey, CachedPackState, TEx> idAndBranchConsumer) throws TEx {
|
||||
for (Map.Entry<CacheKey, CachedPackState> entry : PACK_STATES.entrySet()) {
|
||||
idAndBranchConsumer.accept(entry.getKey(), entry.getValue());
|
||||
synchronized (PACK_STATES) {
|
||||
for (Map.Entry<CacheKey, CachedPackState> entry : PACK_STATES.entrySet().stream().toList()) {
|
||||
idAndBranchConsumer.accept(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,5 +11,6 @@
|
|||
"respackopts.dumpFailed": "Could not dump the requested resource, look at your log for details",
|
||||
"respackopts.reloadSucceeded": "Successfully reloaded resources and data",
|
||||
"respackopts.reloadFailed": "Could not reload all resources, look at your log for details",
|
||||
"respackopts.versionText": "Version %s using the respackotps meta version %s"
|
||||
"respackopts.versionText": "Version %s using the respackotps meta version %s",
|
||||
"respackopts.invalidId": "Invalid Identifier"
|
||||
}
|
|
@ -20,7 +20,8 @@
|
|||
"frex": ["io.gitlab.jfronny.respackopts.integration.FrexCompat"],
|
||||
"respackopts:save_hook": ["io.gitlab.jfronny.respackopts.Respackopts"],
|
||||
"respackopts:client_save_hook": ["io.gitlab.jfronny.respackopts.RespackoptsClient"],
|
||||
"libjf:config": ["io.gitlab.jfronny.respackopts.RespackoptsConfig"]
|
||||
"libjf:config": ["io.gitlab.jfronny.respackopts.RespackoptsConfig"],
|
||||
"modmenu": ["io.gitlab.jfronny.respackopts.integration.ModMenuIntegration"]
|
||||
},
|
||||
"mixins": [
|
||||
"respackopts.mixins.json",
|
||||
|
|
Loading…
Reference in New Issue