Work on more config systems, refactored config, include cloth-config in mod via jij

This commit is contained in:
mcrcortex
2024-02-22 11:00:13 +10:00
parent af9d4065a0
commit 17240e9288
11 changed files with 97 additions and 18 deletions

View File

@@ -3,7 +3,7 @@ package me.cortex.voxy.client;
import me.cortex.voxy.client.core.VoxelCore;
import me.cortex.voxy.client.saver.ContextSelectionSystem;
import me.cortex.voxy.client.terrain.WorldImportCommand;
import me.cortex.voxy.common.storage.config.Serialization;
import me.cortex.voxy.common.config.Serialization;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.loader.api.FabricLoader;

View File

@@ -0,0 +1,28 @@
package me.cortex.voxy.client.config;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
public class BlockConfig {
public Block block = Blocks.AIR;
public boolean ignoreBlock = false;
public final Face[] faces = new Face[6];
public float colourMultiplier = 1.0f;
public BlockConfig() {
for (int i = 0; i < this.faces.length; i++) {
this.faces[i] = new Face();
}
}
public static class Face {
public BooleanChoice occludes = BooleanChoice.DEFAULT;
public BooleanChoice canBeOccluded = BooleanChoice.DEFAULT;
}
public enum BooleanChoice {
DEFAULT,
TRUE,
FALSE
}
}

View File

@@ -39,7 +39,7 @@ public class VoxyConfigScreenFactory implements ModMenuApi {
VoxyConfig.CONFIG.save();
});
return builder.build();//ClothConfigDemo.getConfigBuilderWithDemo().build();
return builder.build();//
}
private static void addGeneralCategory(ConfigBuilder builder, VoxyConfig config) {

View File

@@ -0,0 +1,17 @@
package me.cortex.voxy.client.config.screens;
import me.cortex.voxy.client.config.BlockConfig;
import me.shedaniel.clothconfig2.api.AbstractConfigEntry;
import me.shedaniel.clothconfig2.api.AbstractConfigListEntry;
import me.shedaniel.clothconfig2.api.ConfigEntryBuilder;
import net.minecraft.block.Blocks;
import net.minecraft.text.Text;
public class BlockConfigScreen {
private static final ConfigEntryBuilder ENTRY_BUILDER = ConfigEntryBuilder.create();
public static AbstractConfigListEntry<BlockConfig> makeScreen(BlockConfig config) {
var entry = ENTRY_BUILDER.startSubCategory(config.block.getName());
entry.add(UtilityScreens.makeBlockSelectionScreen(Text.literal("a"), Blocks.AIR, null));
return null;
}
}

View File

@@ -0,0 +1,29 @@
package me.cortex.voxy.client.config.screens;
import me.cortex.voxy.client.config.BlockConfig;
import me.shedaniel.clothconfig2.api.AbstractConfigEntry;
import me.shedaniel.clothconfig2.api.AbstractConfigListEntry;
import me.shedaniel.clothconfig2.api.ConfigEntryBuilder;
import me.shedaniel.clothconfig2.impl.builders.DropdownMenuBuilder;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.registry.Registries;
import net.minecraft.text.Text;
import java.util.function.Consumer;
public class UtilityScreens {
private static final ConfigEntryBuilder ENTRY_BUILDER = ConfigEntryBuilder.create();
public static AbstractConfigListEntry<Block> makeBlockSelectionScreen(Text name, Block selectedBlock, Consumer<Block> onSave) {
return makeBlockSelectionScreen(name, Blocks.AIR, selectedBlock, onSave);
}
public static AbstractConfigListEntry<Block> makeBlockSelectionScreen(Text name, Block defaultBlock, Block selectedBlock, Consumer<Block> onSave) {
return ENTRY_BUILDER.startDropdownMenu(name,
DropdownMenuBuilder.TopCellElementBuilder.ofBlockObject(selectedBlock),
DropdownMenuBuilder.CellCreatorBuilder.ofBlockObject())
.setDefaultValue(defaultBlock)
.setSelections(Registries.BLOCK.stream().toList())
.setSaveConsumer(onSave)
.build();
}
}

View File

@@ -4,17 +4,15 @@ import me.cortex.voxy.client.config.VoxyConfig;
import me.cortex.voxy.common.storage.StorageBackend;
import me.cortex.voxy.common.storage.compressors.ZSTDCompressor;
import me.cortex.voxy.common.storage.config.ConfigBuildCtx;
import me.cortex.voxy.common.storage.config.Serialization;
import me.cortex.voxy.common.config.Serialization;
import me.cortex.voxy.common.storage.config.StorageConfig;
import me.cortex.voxy.common.storage.other.CompressionStorageAdaptor;
import me.cortex.voxy.common.storage.other.TranslocatingStorageAdaptor;
import me.cortex.voxy.common.storage.rocksdb.RocksDBStorageBackend;
import me.cortex.voxy.common.world.WorldEngine;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.util.WorldSavePath;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

View File

@@ -1,10 +1,8 @@
package me.cortex.voxy.common.storage.config;
package me.cortex.voxy.common.config;
import com.google.gson.*;
import com.google.gson.internal.bind.JsonTreeWriter;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;
import net.fabricmc.loader.api.FabricLoader;
@@ -13,14 +11,12 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.lang.reflect.Modifier;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.jar.JarFile;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.zip.ZipEntry;
public class Serialization {
public static final Set<Class<?>> CONFIG_TYPES = new HashSet<>();
@@ -93,21 +89,34 @@ public class Serialization {
}
static {
String BASE_SEARCH_PACKAGE = "me.cortex.voxy";
Map<Class<?>, GsonConfigSerialization<?>> serializers = new HashMap<>();
Set<String> clazzs = new LinkedHashSet<>();
var path = FabricLoader.getInstance().getModContainer("voxy").get().getRootPaths().get(0);
clazzs.addAll(collectAllClasses(path, "me.cortex.voxy.common.storage"));
clazzs.addAll(collectAllClasses("me.cortex.voxy.common.storage"));
clazzs.addAll(collectAllClasses(path, BASE_SEARCH_PACKAGE));
clazzs.addAll(collectAllClasses(BASE_SEARCH_PACKAGE));
outer:
for (var clzName : clazzs) {
if (!clzName.toLowerCase().contains("config")) {
continue;//Only load classes that contain the word config
}
if (clzName.contains("mixin")) {
continue;//Dont want to load mixins
}
if (clzName.equals(Serialization.class.getName())) {
continue;//Dont want to load ourselves
}
try {
var clz = Class.forName(clzName);
if (Modifier.isAbstract(clz.getModifiers())) {
//Dont want to register abstract classes
continue;
}
var original = clz;
while ((clz = clz.getSuperclass()) != null) {
if (CONFIG_TYPES.contains(clz)) {

View File

@@ -1,5 +1,6 @@
package me.cortex.voxy.common.storage.config;
import me.cortex.voxy.common.config.Serialization;
import me.cortex.voxy.common.storage.StorageCompressor;
public abstract class CompressorConfig {

View File

@@ -1,5 +1,6 @@
package me.cortex.voxy.common.storage.config;
import me.cortex.voxy.common.config.Serialization;
import me.cortex.voxy.common.storage.StorageBackend;
import java.util.ArrayList;

View File

@@ -2,13 +2,9 @@ package me.cortex.voxy.common.storage.other;
import me.cortex.voxy.common.storage.StorageBackend;
import me.cortex.voxy.common.storage.config.ConfigBuildCtx;
import me.cortex.voxy.common.storage.config.Serialization;
import me.cortex.voxy.common.storage.config.StorageConfig;
import org.apache.commons.lang3.NotImplementedException;
import java.util.ArrayList;
import java.util.List;
//A conditional storage backend depending on build time config, this enables conditional backends depending on the
// dimension as an example
public class ConditionalStorageBackendConfig extends StorageConfig {