mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-10-26 11:27:38 +00:00
Merge branch 'mc-1.20.x' into mc-1.21.x
This commit is contained in:
@@ -7,7 +7,7 @@ import net.neoforged.gradle.dsl.common.runs.run.Run
|
||||
|
||||
plugins {
|
||||
id("cc-tweaked.forge")
|
||||
id("cc-tweaked.gametest")
|
||||
id("cc-tweaked.mod")
|
||||
id("cc-tweaked.mod-publishing")
|
||||
}
|
||||
|
||||
@@ -65,6 +65,8 @@ runs {
|
||||
"--existing", project(":common").file("src/main/resources/").absolutePath,
|
||||
"--existing", file("src/main/resources/").absolutePath,
|
||||
)
|
||||
|
||||
modSources.add("computercraft", sourceSets.datagen.get())
|
||||
}
|
||||
|
||||
fun Run.configureForGameTest() {
|
||||
|
||||
@@ -32,7 +32,7 @@ import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@EventBusSubscriber(bus = EventBusSubscriber.Bus.MOD)
|
||||
public class Generators {
|
||||
public class ForgeDataProviders {
|
||||
@SubscribeEvent
|
||||
public static void gather(GatherDataEvent event) {
|
||||
var generator = event.getGenerator();
|
||||
@@ -5,50 +5,33 @@
|
||||
package dan200.computercraft.shared.platform;
|
||||
|
||||
import dan200.computercraft.shared.config.ConfigFile;
|
||||
import dan200.computercraft.shared.util.Trie;
|
||||
import net.neoforged.neoforge.common.ModConfigSpec;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Map;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* A {@link ConfigFile} which wraps Forge's config implementation.
|
||||
*/
|
||||
public final class ForgeConfigFile implements ConfigFile {
|
||||
public final class ForgeConfigFile extends ConfigFile {
|
||||
private final ModConfigSpec spec;
|
||||
private final Trie<String, ConfigFile.Entry> entries;
|
||||
|
||||
public ForgeConfigFile(ModConfigSpec spec, Trie<String, Entry> entries) {
|
||||
private ForgeConfigFile(ModConfigSpec spec, Map<String, Entry> entries) {
|
||||
super(entries);
|
||||
this.spec = spec;
|
||||
this.entries = entries;
|
||||
}
|
||||
|
||||
public ModConfigSpec spec() {
|
||||
return spec;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<Entry> entries() {
|
||||
return entries.stream();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Entry getEntry(String path) {
|
||||
return entries.getValue(SPLITTER.split(path));
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps {@link ModConfigSpec.Builder} into our own config builder abstraction.
|
||||
*/
|
||||
static class Builder extends ConfigFile.Builder {
|
||||
private final ModConfigSpec.Builder builder = new ModConfigSpec.Builder();
|
||||
private final Trie<String, ConfigFile.Entry> entries = new Trie<>();
|
||||
|
||||
private void translation(String name) {
|
||||
builder.translation(getTranslation(name));
|
||||
@@ -56,24 +39,23 @@ public final class ForgeConfigFile implements ConfigFile {
|
||||
|
||||
@Override
|
||||
public ConfigFile.Builder comment(String comment) {
|
||||
super.comment(comment);
|
||||
builder.comment(comment);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void push(String name) {
|
||||
super.push(name);
|
||||
|
||||
translation(name);
|
||||
builder.push(name);
|
||||
super.push(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pop() {
|
||||
var path = new ArrayList<>(groupStack);
|
||||
entries.setValue(path, new GroupImpl(path));
|
||||
|
||||
builder.pop();
|
||||
super.pop();
|
||||
builder.pop();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -82,100 +64,63 @@ public final class ForgeConfigFile implements ConfigFile {
|
||||
return this;
|
||||
}
|
||||
|
||||
private <T> ConfigFile.Value<T> defineValue(ModConfigSpec.ConfigValue<T> value) {
|
||||
var wrapped = new ValueImpl<>(value);
|
||||
entries.setValue(value.getPath(), wrapped);
|
||||
private <T> ConfigFile.Value<T> defineValue(String name, ModConfigSpec.ConfigValue<T> value) {
|
||||
var wrapped = new ValueImpl<>(getPath(name), takeComment(), value);
|
||||
groupStack.getLast().children().put(name, wrapped);
|
||||
return wrapped;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> ConfigFile.Value<T> define(String path, T defaultValue) {
|
||||
translation(path);
|
||||
return defineValue(builder.define(path, defaultValue));
|
||||
public <T> ConfigFile.Value<T> define(String name, T defaultValue) {
|
||||
translation(name);
|
||||
return defineValue(name, builder.define(name, defaultValue));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigFile.Value<Boolean> define(String path, boolean defaultValue) {
|
||||
translation(path);
|
||||
return defineValue(builder.define(path, defaultValue));
|
||||
public ConfigFile.Value<Boolean> define(String name, boolean defaultValue) {
|
||||
translation(name);
|
||||
return defineValue(name, builder.define(name, defaultValue));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigFile.Value<Integer> defineInRange(String path, int defaultValue, int min, int max) {
|
||||
translation(path);
|
||||
return defineValue(builder.defineInRange(path, defaultValue, min, max));
|
||||
public ConfigFile.Value<Integer> defineInRange(String name, int defaultValue, int min, int max) {
|
||||
translation(name);
|
||||
return defineValue(name, builder.defineInRange(name, defaultValue, min, max));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> ConfigFile.Value<List<? extends T>> defineList(String path, List<? extends T> defaultValue, Supplier<T> newValue, Predicate<Object> elementValidator) {
|
||||
translation(path);
|
||||
return defineValue(builder.defineList(path, defaultValue, newValue, elementValidator));
|
||||
public <T> ConfigFile.Value<List<? extends T>> defineList(String name, List<? extends T> defaultValue, Supplier<T> newValue, Predicate<Object> elementValidator) {
|
||||
translation(name);
|
||||
return defineValue(name, builder.defineList(name, defaultValue, newValue, elementValidator));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <V extends Enum<V>> ConfigFile.Value<V> defineEnum(String path, V defaultValue) {
|
||||
translation(path);
|
||||
return defineValue(builder.defineEnum(path, defaultValue));
|
||||
public <V extends Enum<V>> ConfigFile.Value<V> defineEnum(String name, V defaultValue) {
|
||||
translation(name);
|
||||
return defineValue(name, builder.defineEnum(name, defaultValue));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigFile build(ConfigListener onChange) {
|
||||
var children = groupStack.removeLast().children();
|
||||
if (!groupStack.isEmpty()) throw new IllegalStateException("Mismatched config push/pop");
|
||||
|
||||
var spec = builder.build();
|
||||
entries.stream().forEach(x -> {
|
||||
if (x instanceof ValueImpl<?> value) value.owner = spec;
|
||||
if (x instanceof GroupImpl value) value.owner = spec;
|
||||
});
|
||||
return new ForgeConfigFile(spec, entries);
|
||||
return new ForgeConfigFile(spec, children);
|
||||
}
|
||||
}
|
||||
|
||||
private static final class GroupImpl implements ConfigFile.Group {
|
||||
private final List<String> path;
|
||||
private @Nullable ModConfigSpec owner;
|
||||
|
||||
private GroupImpl(List<String> path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String translationKey() {
|
||||
if (owner == null) throw new IllegalStateException("Config has not been built yet");
|
||||
return owner.getLevelTranslationKey(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String comment() {
|
||||
if (owner == null) throw new IllegalStateException("Config has not been built yet");
|
||||
return owner.getLevelComment(path);
|
||||
}
|
||||
}
|
||||
|
||||
private static final class ValueImpl<T> implements ConfigFile.Value<T> {
|
||||
private static final class ValueImpl<T> extends Value<T> {
|
||||
private final ModConfigSpec.ConfigValue<T> value;
|
||||
private @Nullable ModConfigSpec owner;
|
||||
|
||||
private ValueImpl(ModConfigSpec.ConfigValue<T> value) {
|
||||
private ValueImpl(String path, String comment, ModConfigSpec.ConfigValue<T> value) {
|
||||
super(path, comment);
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
private ModConfigSpec.ValueSpec spec() {
|
||||
if (owner == null) throw new IllegalStateException("Config has not been built yet");
|
||||
return owner.getSpec().get(value.getPath());
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get() {
|
||||
return value.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String translationKey() {
|
||||
return Objects.requireNonNull(spec().getTranslationKey(), "No comment for value");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String comment() {
|
||||
return Objects.requireNonNull(spec().getComment(), "No comment for value");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user