Fix an issue from the previous commit and support built-in conditions
This commit is contained in:
parent
e24405b611
commit
61306eef50
|
@ -27,4 +27,11 @@ You will need to navigate to the file you would like to toggle inside your resou
|
|||
}
|
||||
```
|
||||
|
||||
### Built-in conditions
|
||||
Respackopts provides some conditions by default, you can use them in any pack.
|
||||
|
||||
| Condition | Explaination |
|
||||
| --- | --- |
|
||||
| `modversion:<mod>:<predicate>` | True if the specified mod is loaded (use the mod ID) and the version fits the predicate. Example: `modversion:minecraft:>=1.7.10`, `modversion:continuity:*` |
|
||||
|
||||
See [Switch between two files](./ToggleFilesWithFallback.md) to see how to swap textures out with each other (alternate Options)
|
||||
|
|
|
@ -2,16 +2,16 @@
|
|||
org.gradle.jvmargs=-Xmx1G
|
||||
# Fabric Properties
|
||||
# check these on https://fabricmc.net/versions.html
|
||||
minecraft_version=1.18-pre2
|
||||
yarn_mappings=build.2
|
||||
minecraft_version=1.18-pre4
|
||||
yarn_mappings=build.9
|
||||
loader_version=0.12.5
|
||||
# Mod Properties
|
||||
mod_version=2.8.3
|
||||
maven_group=io.gitlab.jfronny
|
||||
archives_base_name=respackopts
|
||||
# Dependencies
|
||||
fabric_version=0.42.5+1.18
|
||||
jfapi_version=2.1.4-410670846
|
||||
fabric_version=0.42.7+1.18
|
||||
jfapi_version=2.1.4-412595557
|
||||
|
||||
modrinth_id=TiF5QWZY
|
||||
modrinth_required_dependencies=3CD6YUw1
|
||||
|
|
|
@ -98,9 +98,7 @@ public class Respackopts implements ClientModInitializer {
|
|||
}
|
||||
if (CONFIG.debugLogs)
|
||||
SAVE_ACTIONS.add(() -> LOGGER.info("Save"));
|
||||
SAVE_ACTIONS.add(() -> {
|
||||
MetaCache.forEach((id, branch) -> STAR_SCRIPT.set(sanitizeString(id), branch::buildStarscript));
|
||||
});
|
||||
SAVE_ACTIONS.add(() -> MetaCache.forEach((id, branch) -> STAR_SCRIPT.set(sanitizeString(id), branch::buildStarScript)));
|
||||
SAVE_ACTIONS.add(() -> {
|
||||
if (CONFIG.debugLogs)
|
||||
LOGGER.info("Generating shader code");
|
||||
|
|
|
@ -1,12 +1,18 @@
|
|||
package io.gitlab.jfronny.respackopts.model.condition;
|
||||
|
||||
import com.google.gson.JsonParseException;
|
||||
import io.gitlab.jfronny.respackopts.Respackopts;
|
||||
import io.gitlab.jfronny.respackopts.util.MetaCache;
|
||||
import io.gitlab.jfronny.respackopts.model.ThrowingBiConsumer;
|
||||
import io.gitlab.jfronny.respackopts.model.tree.ConfigBranch;
|
||||
import io.gitlab.jfronny.respackopts.util.RpoFormatException;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.fabricmc.loader.api.ModContainer;
|
||||
import net.fabricmc.loader.api.VersionParsingException;
|
||||
import net.fabricmc.loader.api.metadata.version.VersionPredicate;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
public record RpoBooleanCondition(String name) implements Condition {
|
||||
|
@ -21,9 +27,23 @@ public record RpoBooleanCondition(String name) implements Condition {
|
|||
if (!condition.contains(":")) {
|
||||
condition = packId + ":" + condition;
|
||||
}
|
||||
String sourcePack = condition.split(":")[0];
|
||||
String sourcePack = condition.substring(0, condition.indexOf(':'));
|
||||
condition = condition.substring(condition.indexOf(':') + 1);
|
||||
final String finalCondition = condition;
|
||||
if (sourcePack.equals("modversion")) {
|
||||
// builtin conditions
|
||||
String modName = condition.substring(0, condition.indexOf(':'));
|
||||
Optional<ModContainer> container = FabricLoader.getInstance().getModContainer(modName);
|
||||
if (container.isEmpty()) {
|
||||
if (Respackopts.CONFIG.debugLogs) Respackopts.LOGGER.info("Mod not found: " + modName);
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
return VersionPredicate.parse(condition.substring(condition.indexOf(':') + 1)).test(container.get().getMetadata().getVersion());
|
||||
} catch (VersionParsingException e) {
|
||||
throw new RpoFormatException("Could not parse version predicate", e);
|
||||
}
|
||||
}
|
||||
AtomicReference<Boolean> result = new AtomicReference<>(null);
|
||||
MetaCache.forEach((ThrowingBiConsumer<String, ConfigBranch, ? extends RpoFormatException>) (id, branch) -> {
|
||||
if (Objects.equals(id, sourcePack)) {
|
||||
|
@ -35,7 +55,7 @@ public record RpoBooleanCondition(String name) implements Condition {
|
|||
}
|
||||
});
|
||||
if (result.get() == null)
|
||||
throw new RpoFormatException("Could not find pack with specified ID: " + packId);
|
||||
throw new RpoFormatException("Could not find pack with specified ID: " + sourcePack);
|
||||
return result.get();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ public class ConfigBooleanEntry extends ConfigEntry<Boolean> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Value buildStarscript() {
|
||||
public Value buildStarScript() {
|
||||
return Value.bool(getValue());
|
||||
}
|
||||
|
||||
|
|
|
@ -107,10 +107,10 @@ public class ConfigBranch extends ConfigEntry<Map<String, ConfigEntry<?>>> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Value buildStarscript() {
|
||||
public Value buildStarScript() {
|
||||
ValueMap vm = new ValueMap();
|
||||
for (Map.Entry<String, ConfigEntry<?>> e : super.getValue().entrySet()) {
|
||||
vm.set(Respackopts.sanitizeString(e.getKey()), () -> e.getValue().buildStarscript());
|
||||
vm.set(Respackopts.sanitizeString(e.getKey()), () -> e.getValue().buildStarScript());
|
||||
}
|
||||
return Value.map(vm);
|
||||
}
|
||||
|
@ -144,6 +144,7 @@ public class ConfigBranch extends ConfigEntry<Map<String, ConfigEntry<?>>> {
|
|||
for (Map.Entry<String, ConfigEntry<?>> e : getValue().entrySet()) {
|
||||
branch.add(e.getKey(), e.getValue().clone());
|
||||
}
|
||||
branch.setVersion(getVersion());
|
||||
return branch;
|
||||
}
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ public abstract class ConfigEntry<T> {
|
|||
|
||||
public abstract void buildShader(StringBuilder sb, String valueName);
|
||||
|
||||
public abstract Value buildStarscript();
|
||||
public abstract Value buildStarScript();
|
||||
|
||||
public abstract AbstractConfigListEntry<?> buildEntry(GuiEntryBuilderParam guiEntryBuilderParam);
|
||||
|
||||
|
|
|
@ -113,7 +113,7 @@ public class ConfigEnumEntry extends ConfigEntry<String> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Value buildStarscript() {
|
||||
public Value buildStarScript() {
|
||||
return Value.string(getValue());
|
||||
}
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ public class ConfigNumericEntry extends ConfigEntry<Double> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Value buildStarscript() {
|
||||
public Value buildStarScript() {
|
||||
return Value.number(getValue());
|
||||
}
|
||||
|
||||
|
|
|
@ -97,7 +97,7 @@ public class MetaCache {
|
|||
ConfigBranch b = Respackopts.GSON.fromJson(reader, ConfigBranch.class);
|
||||
if (CONFIG_BRANCH.containsKey(id))
|
||||
CONFIG_BRANCH.get(id).sync(b, ConfigSyncMode.CONF_LOAD);
|
||||
Respackopts.STAR_SCRIPT.set(Respackopts.sanitizeString(id), b::buildStarscript);
|
||||
Respackopts.STAR_SCRIPT.set(Respackopts.sanitizeString(id), b::buildStarScript);
|
||||
} catch (IOException e) {
|
||||
Respackopts.LOGGER.error("Failed to load " + id, e);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue