Start migration

This commit is contained in:
Aleksey 2021-04-08 21:55:07 +03:00
parent 6630ce0cab
commit 47ed597358
491 changed files with 12045 additions and 11953 deletions

View file

@ -1,20 +1,20 @@
package ru.betterend.config;
import net.minecraft.util.Identifier;
import net.minecraft.resources.ResourceLocation;
public class ConfigKey {
private final String path[];
private final String entry;
private final boolean root;
public ConfigKey(String entry, String... path) {
this.validate(entry);
this.path = path;
this.entry = entry;
this.root = path.length == 0 || (path.length == 1 && path[0].isEmpty());
}
public ConfigKey(String entry, Identifier path) {
public ConfigKey(String entry, ResourceLocation path) {
this(entry, path.getNamespace(), path.getPath());
}
@ -25,7 +25,7 @@ public class ConfigKey {
public String getEntry() {
return entry;
}
public boolean isRoot() {
return root;
}
@ -61,7 +61,7 @@ public class ConfigKey {
}
return true;
}
@Override
public String toString() {
if (root) {
@ -73,7 +73,7 @@ public class ConfigKey {
}
return String.format("%s:%s", p, entry);
}
private void validate(String entry) {
if (entry == null) {
throw new NullPointerException("Config key must be not null!");

View file

@ -4,90 +4,91 @@ import java.util.function.BiFunction;
import org.jetbrains.annotations.Nullable;
import net.minecraft.util.Identifier;
import net.minecraft.resources.ResourceLocation;
import ru.betterend.config.ConfigKeeper.Entry;
import ru.betterend.config.ConfigKeeper.FloatRange;
import ru.betterend.config.ConfigKeeper.IntegerRange;
public class IdConfig extends Config {
protected final BiFunction<Identifier, String, ConfigKey> keyFactory;
public IdConfig(String group, BiFunction<Identifier, String, ConfigKey> keyFactory) {
protected final BiFunction<ResourceLocation, String, ConfigKey> keyFactory;
public IdConfig(String group, BiFunction<ResourceLocation, String, ConfigKey> keyFactory) {
super(group);
this.keyFactory = keyFactory;
}
@Override
protected void registerEntries() {}
protected void registerEntries() {
}
protected ConfigKey createKey(Identifier id, String key) {
protected ConfigKey createKey(ResourceLocation id, String key) {
return this.keyFactory.apply(id, key);
}
@Nullable
public <T, E extends Entry<T>> E getEntry(Identifier id, String key, Class<E> type) {
public <T, E extends Entry<T>> E getEntry(ResourceLocation id, String key, Class<E> type) {
return this.getEntry(createKey(id, key), type);
}
@Nullable
public <T, E extends Entry<T>> T getDefault(Identifier id, String key, Class<E> type) {
public <T, E extends Entry<T>> T getDefault(ResourceLocation id, String key, Class<E> type) {
return this.getDefault(createKey(id, key), type);
}
public String getString(Identifier id, String key, String defaultValue) {
public String getString(ResourceLocation id, String key, String defaultValue) {
return this.getString(createKey(id, key), defaultValue);
}
public String getString(Identifier id, String key) {
public String getString(ResourceLocation id, String key) {
return this.getString(createKey(id, key));
}
public boolean setString(Identifier id, String key, String value) {
public boolean setString(ResourceLocation id, String key, String value) {
return this.setString(createKey(id, key), value);
}
public int getInt(Identifier id, String key, int defaultValue) {
public int getInt(ResourceLocation id, String key, int defaultValue) {
return this.getInt(createKey(id, key), defaultValue);
}
public int getInt(Identifier id, String key) {
public int getInt(ResourceLocation id, String key) {
return this.getInt(createKey(id, key));
}
public boolean setInt(Identifier id, String key, int value) {
public boolean setInt(ResourceLocation id, String key, int value) {
return this.setInt(createKey(id, key), value);
}
public boolean setRangedInt(Identifier id, String key, int value) {
public boolean setRangedInt(ResourceLocation id, String key, int value) {
return this.setRanged(createKey(id, key), value, IntegerRange.class);
}
public boolean setRangedFloat(Identifier id, String key, float value) {
public boolean setRangedFloat(ResourceLocation id, String key, float value) {
return this.setRanged(createKey(id, key), value, FloatRange.class);
}
public float getFloat(Identifier id, String key, float defaultValue) {
public float getFloat(ResourceLocation id, String key, float defaultValue) {
return this.getFloat(createKey(id, key), defaultValue);
}
public float getFloat(Identifier id, String key) {
public float getFloat(ResourceLocation id, String key) {
return this.getFloat(createKey(id, key));
}
public boolean setFloat(Identifier id, String key, float value) {
public boolean setFloat(ResourceLocation id, String key, float value) {
return this.setFloat(createKey(id, key), value);
}
public boolean getBoolean(Identifier id, String key, boolean defaultValue) {
public boolean getBoolean(ResourceLocation id, String key, boolean defaultValue) {
return this.getBoolean(createKey(id, key), defaultValue);
}
public boolean getBoolean(Identifier id, String key) {
public boolean getBoolean(ResourceLocation id, String key) {
return this.getBoolean(createKey(id, key));
}
public boolean setBoolean(Identifier id, String key, boolean value) {
public boolean setBoolean(ResourceLocation id, String key, boolean value) {
return this.setBoolean(createKey(id, key), value);
}
}