Hopefully fix WrappedPack

This commit is contained in:
JFronny 2021-07-13 13:33:27 +02:00
parent 672f8be302
commit 4966024847
No known key found for this signature in database
GPG Key ID: BEC5ACBBD4EE17E5
5 changed files with 34 additions and 14 deletions

View File

@ -22,9 +22,10 @@ dependencies {
modApi("me.shedaniel.cloth:cloth-config-fabric:5.0.34")
modCompileOnly "grondag:frex-mc117:+"
/*TODO re-enable after canvas works on 1.17.1
modRuntime("grondag:canvas-mc117-1.17:+") {
exclude(group: "me.shedaniel.cloth")
}
}*/
testImplementation('org.junit.jupiter:junit-jupiter:5.6.2')
}

View File

@ -21,23 +21,23 @@ public class ConfigBranch extends ConfigEntry<Map<String, ConfigEntry<?>>> {
public boolean getBoolean(String name) throws RpoError {
String[] sp = name.split("\\.");
if (!super.getValue().containsKey(sp[0]))
throw new RpoError("Invalid path to key");
throw new RpoError("Invalid path to key in " + getName());
ConfigEntry<?> e = super.getValue().get(sp[0]);
if (sp.length == 1) {
if (e instanceof ConfigBooleanEntry b)
return b.getValue();
throw new RpoError("Not a boolean");
throw new RpoError("Not a boolean in " + getName());
}
if (sp.length == 2 && e instanceof ConfigEnumEntry en) {
for (String entry : en.values) {
if (entry.equals(sp[1]))
return entry.equals(en.getValue());
}
throw new RpoError("Could not find enum entry");
throw new RpoError("Could not find enum entry in " + getName());
}
if (e instanceof ConfigBranch b)
return b.getBoolean(name.substring(name.indexOf('.') + 1));
throw new RpoError("Invalid path to key");
throw new RpoError("Invalid path to key in " + getName());
}
@Override
@ -52,7 +52,7 @@ public class ConfigBranch extends ConfigEntry<Map<String, ConfigEntry<?>>> {
syncSub(current, (ConfigEntry)e.getValue(), mode);
}
else {
Respackopts.LOGGER.warn("Type mismatch in config, ignoring");
Respackopts.LOGGER.warn("Type mismatch in config (" + getName() + "), ignoring");
}
}
}
@ -64,12 +64,21 @@ public class ConfigBranch extends ConfigEntry<Map<String, ConfigEntry<?>>> {
public <T> void add(String name, ConfigEntry<T> val) {
val.setVersion(version);
val.parent = this;
super.getValue().put(name, val);
}
public ConfigEntry<?> get(String key) {
return super.getValue().get(key);
}
public String getEntryName(ConfigEntry<?> entry) {
for (Map.Entry<String, ConfigEntry<?>> e : getValue().entrySet()) {
if (e.getValue() == entry)
return e.getKey();
}
throw new IndexOutOfBoundsException();
}
public boolean has(String key) {
return super.getValue().containsKey(key);

View File

@ -12,6 +12,16 @@ public abstract class ConfigEntry<T> {
private T defaultValue;
private T value;
protected int version;
protected ConfigBranch parent;
public String getName() {
if (parent == null)
return "";
String n = parent.getName() + "." + parent.getEntryName(this);
if (n.startsWith("."))
n = n.substring(0, 1);
return n;
}
public void setVersion(int version) {
this.version = version;
@ -23,7 +33,7 @@ public abstract class ConfigEntry<T> {
public T getValue() {
if (value == null) {
if (defaultValue == null) {
Respackopts.LOGGER.warn("No default value or current value set for entry, returning null");
Respackopts.LOGGER.warn("No default value or current value set for entry, returning null in " + getName());
return null;
}
value = getDefault();
@ -39,7 +49,7 @@ public abstract class ConfigEntry<T> {
public T getDefault() {
if (defaultValue == null) {
defaultValue = getValue();
Respackopts.LOGGER.warn("No default value set for entry, using current");
Respackopts.LOGGER.warn("No default value set for entry, using current in " + getName());
}
return defaultValue;
}

View File

@ -32,7 +32,7 @@ public class ConfigEnumEntry extends ConfigEntry<String> {
setValue(v);
}
else {
throw new NullPointerException("Could not get value");
throw new NullPointerException("Could not get value in " + getName());
}
}
return v;
@ -43,7 +43,7 @@ public class ConfigEnumEntry extends ConfigEntry<String> {
String v = super.getDefault();
if (v == null) {
if (values.size() == 0)
throw new NullPointerException("Could not get default entry as the entry array is empty");
throw new NullPointerException("Could not get default entry as the entry array is empty in " + getName());
else
v = values.get(0);
}
@ -63,7 +63,7 @@ public class ConfigEnumEntry extends ConfigEntry<String> {
setValue(values.get(n.nextValue));
}
else {
Respackopts.LOGGER.error("Could not load default value for enum");
Respackopts.LOGGER.error("Could not load default value for enum in " + getName());
}
}
}

View File

@ -36,11 +36,11 @@ public class WrappedPack implements ResourcePack {
};
FileContainedProvider contains = s -> {
Tuple<ResourceType, Identifier> p = pathGetter.split(s);
return this.pack.contains(p.left(), p.right());
return this.contains(p.left(), p.right());
};
FileOpenProvider open = s -> {
Tuple<ResourceType, Identifier> p = pathGetter.split(s);
return this.pack.open(p.left(), p.right());
return this.open(p.left(), p.right());
};
rpo = new ResourcePackFilter(contains, open);
fbt = new FallbackFilter(contains, open);
@ -59,7 +59,7 @@ public class WrappedPack implements ResourcePack {
@Override
public InputStream open(ResourceType type, Identifier id) throws IOException {
if (pack.contains(type, id) && containsFileWasFallback) {
if (contains(type, id) && containsFileWasFallback) {
return fbt.getReplacement(getFilename(type, id), new FileNotFoundException());
}
return pack.open(type, id);