fix: partial reapply

This commit is contained in:
Johannes Frohnmeyer 2023-06-29 14:49:43 +02:00
parent ec895217b0
commit e61d3a19e8
Signed by: Johannes
GPG Key ID: E76429612C2929F4
7 changed files with 45 additions and 34 deletions

View File

@ -1,12 +1,16 @@
import io.gitlab.jfronny.scripts.*
plugins {
id("jfmod") version "1.3-SNAPSHOT"
id("jfmod") version "1.4-SNAPSHOT"
}
repositories {
maven("https://maven.shedaniel.me/") { name = "Cloth Config" }
maven("https://maven.vram.io/") { name = "FREX/Canvas" }
maven("https://maven.vram.io/") {
name = "FREX/Canvas"
content {
includeGroup("io.vram")
}
}
maven("https://notalpha.dev/maven/releases") {
name = "DashLoader"
content {

View File

@ -1,6 +1,6 @@
# https://fabricmc.net/develop/
minecraft_version=1.20
yarn_mappings=build.1
minecraft_version=1.20.1
yarn_mappings=build.8
loader_version=0.14.21
maven_group=io.gitlab.jfronny
@ -13,6 +13,6 @@ curseforge_id=430090
curseforge_required_dependencies=fabric-api, libjf
curseforge_optional_dependencies=modmenu
fabric_version=0.83.0+1.20
fabric_version=0.84.0+1.20.1
libjf_version=3.8.0
muscript_version=1.3-SNAPSHOT

View File

@ -3,7 +3,7 @@ package io.gitlab.jfronny.respackopts;
import io.gitlab.jfronny.commons.log.Logger;
import io.gitlab.jfronny.gson.Gson;
import io.gitlab.jfronny.gson.GsonBuilder;
import io.gitlab.jfronny.libjf.config.api.v1.ConfigHolder;
import io.gitlab.jfronny.libjf.config.api.v1.ConfigInstance;
import io.gitlab.jfronny.muscript.StandardLib;
import io.gitlab.jfronny.muscript.ast.*;
import io.gitlab.jfronny.muscript.data.Scope;
@ -80,9 +80,11 @@ public class Respackopts implements ModInitializer, SaveHook {
ServerInstanceHolder.init();
}
public static ConfigInstance CONFIG;
@Override
public CompletableFuture<Void> onSave(Arguments args) {
ConfigHolder.getInstance().get(ID).write();
CONFIG.write();
if (args.reloadData() && FabricLoader.getInstance().getEnvironmentType() == EnvType.SERVER) {
ServerInstanceHolder.reloadResources();

View File

@ -15,7 +15,8 @@ public class RespackoptsConfig implements JfCustomConfig {
@Override
public void register(DSL.Defaulted dsl) {
dsl.register(builder -> builder
if (Respackopts.CONFIG != null) return;
Respackopts.CONFIG = dsl.register(builder -> builder
.value("debugCommands", debugCommands, () -> debugCommands, v -> debugCommands = v)
.value("debugLogs", debugLogs, () -> debugLogs, v -> debugLogs = v)
.value("dashloaderCompat", dashloaderCompat, () -> dashloaderCompat, v -> dashloaderCompat = v)

View File

@ -77,7 +77,7 @@ public enum DirFilterEvents implements UserResourceEvents.Open, UserResourceEven
try {
return !rpo.condition.get(MetaCache.getScope(key));
} catch (Condition.ConditionException e) {
String res = "Could not evaluate condition " + file + " (pack: " + key.packName() + ")";
String res = "Could not evaluate condition for " + file + " (pack: " + key.packName() + ")";
try {
Respackopts.LOGGER.error(res + " with condition:\n" + ObjectGraphPrinter.printGraph(rpo.condition) + ")", e);
} catch (Throwable ex) {

View File

@ -9,7 +9,6 @@ import io.gitlab.jfronny.respackopts.util.FallbackI18n;
import io.gitlab.jfronny.respackopts.util.MetaCache;
import net.minecraft.resource.*;
import net.minecraft.util.Identifier;
import net.minecraft.util.Language;
import org.spongepowered.asm.mixin.*;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
@ -27,14 +26,17 @@ public class ResourcePackManagerMixin {
@Inject(at = @At("TAIL"), method = "scanPacks()V")
private void scanPacks(CallbackInfo info) {
FallbackI18n.clear();
Set<Path> newDataLocations = new HashSet<>();
Set<Path> toRemove = new HashSet<>(dataLocations);
dataLocations.clear();
profiles.forEach((s, v) -> {
try (ResourcePack rpi = v.createResourcePack()) {
String id = rpo$checkProfile(s, v.getDisplayName().getString(), rpi, toRemove);
if (id != null) rpo$loadTranslations(rpi, id);
String id = rpo$checkProfile(s, v.getDisplayName().getString(), rpi, newDataLocations, toRemove);
if (id != null) FallbackI18n.loadFrom(rpi, id);
}
});
dataLocations.clear();
dataLocations.addAll(newDataLocations);
for (Path s : toRemove) {
CacheKey k = MetaCache.getKeyByDataLocation(s);
if (k != null) MetaCache.remove(k);
@ -42,7 +44,7 @@ public class ResourcePackManagerMixin {
MetaCache.save(SaveHook.Arguments.DO_NOTHING);
}
private String rpo$checkProfile(String profileName, String displayName, ResourcePack rpi, Set<Path> toRemove) {
private static String rpo$checkProfile(String profileName, String displayName, ResourcePack rpi, Set<Path> dataLocations, Set<Path> toRemove) {
Path dataLocation = null;
if (rpi instanceof DirectoryResourcePack drp) {
Path pack = ((DirectoryResourcePackAccessor) drp).getRoot();
@ -57,7 +59,7 @@ public class ResourcePackManagerMixin {
var conf = rpi.openRoot(Respackopts.ID + ".json5");
if (conf != null) {
try (InputStream is = conf.get()) {
return rpo$readConfiguration(is, dataLocation, rpi.getName(), displayName, toRemove);
return rpo$readConfiguration(is, dataLocation, rpi.getName(), displayName, dataLocations, toRemove);
} catch (Throwable e) {
String message = "Could not read respackopts config in root for " + profileName;
if (RespackoptsConfig.debugLogs) Respackopts.LOGGER.error(message, e);
@ -70,7 +72,7 @@ public class ResourcePackManagerMixin {
conf = rpi.open(type, confId);
if (conf != null) {
try (InputStream is = conf.get()) {
return rpo$readConfiguration(is, dataLocation, rpi.getName(), displayName, toRemove);
return rpo$readConfiguration(is, dataLocation, rpi.getName(), displayName, dataLocations, toRemove);
} catch (Throwable e) {
Respackopts.LOGGER.error("Could not initialize pack meta for " + profileName, e);
}
@ -80,7 +82,7 @@ public class ResourcePackManagerMixin {
return null;
}
private String rpo$readConfiguration(InputStream is, Path dataLocation, String packName, String displayName, Set<Path> toRemove) throws IOException {
private static String rpo$readConfiguration(InputStream is, Path dataLocation, String packName, String displayName, Set<Path> dataLocations, Set<Path> toRemove) throws IOException {
try (InputStreamReader isr = new InputStreamReader(is)) {
PackMeta conf = Respackopts.GSON.fromJson(isr, PackMeta.class);
if (RespackoptsConfig.debugLogs) Respackopts.LOGGER.info("Discovered pack: " + conf.id);
@ -95,19 +97,4 @@ public class ResourcePackManagerMixin {
return conf.id;
}
}
private void rpo$loadTranslations(ResourcePack rpi, String id) {
for (String namespace : rpi.getNamespaces(ResourceType.CLIENT_RESOURCES)) {
var translation = rpi.open(ResourceType.CLIENT_RESOURCES, new Identifier(namespace, "lang/en_us.json"));
if (translation == null) continue;
try (InputStream is = translation.get()) {
Language.load(is, (key, value) -> {
if (key.startsWith("rpo." + id + ".")) {
FallbackI18n.put(key, value);
}
});
} catch (Throwable ignored) {
}
}
}
}

View File

@ -1,5 +1,11 @@
package io.gitlab.jfronny.respackopts.util;
import net.minecraft.resource.ResourcePack;
import net.minecraft.resource.ResourceType;
import net.minecraft.util.Identifier;
import net.minecraft.util.Language;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
@ -10,8 +16,19 @@ public class FallbackI18n {
translations.clear();
}
public static void put(String key, String value) {
translations.put(key, value);
public static void loadFrom(ResourcePack pack, String packId) {
for (String namespace : pack.getNamespaces(ResourceType.CLIENT_RESOURCES)) {
var translation = pack.open(ResourceType.CLIENT_RESOURCES, new Identifier(namespace, "lang/en_us.json"));
if (translation == null) continue;
try (InputStream is = translation.get()) {
Language.load(is, (key, value) -> {
if (key.startsWith("rpo." + packId + ".")) {
translations.put(key, value);
}
});
} catch (Throwable ignored) {
}
}
}
public static void insertInto(Map<String, String> target) {