more metapack work

This commit is contained in:
Zoë Gidiere
2023-12-12 13:35:46 -07:00
parent c86faa44ec
commit db1e924246
5 changed files with 33 additions and 12 deletions

View File

@@ -3,9 +3,12 @@ package com.dfsek.terra.config.pack;
import ca.solostudios.strata.version.Version;
import java.awt.image.BufferedImage;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
@@ -73,14 +76,27 @@ public class MetaPackImpl implements MetaPack {
public MetaPackImpl(Path path, Platform platform, ConfigRegistry configRegistry) throws IOException {
long start = System.nanoTime();
this.rootPath = path;
this.platform = platform;
if(Files.notExists(path)) throw new FileNotFoundException("Could not load metapack, " + path + " does not exist");
if(Files.isDirectory(path)) {
this.rootPath = path;
} else if(Files.isRegularFile(path)) {
if(!path.getFileName().toString().endsWith(".zip")) {
throw new IOException("Could not load metapack, file " + path + " is not a zip");
}
FileSystem zipfs = FileSystems.newFileSystem(path);
this.rootPath = zipfs.getPath("/");
} else {
throw new IOException("Could not load metapack from " + path);
}
Path packManifestPath = rootPath.resolve("metapack.yml");
if(Files.notExists(packManifestPath)) throw new IOException("No metapack.yml found in " + path);
Configuration packManifest = new YamlConfiguration(Files.newInputStream(packManifestPath),
packManifestPath.getFileName().toString());
this.platform = platform;
register(selfLoader);
platform.register(selfLoader);
@@ -101,6 +117,8 @@ public class MetaPackImpl implements MetaPack {
this.key = RegistryKey.of(namespace, id);
logger.info("Loading metapack \"{}:{}\"", id, namespace);
template.getPacks().forEach((k, v) -> {
RegistryKey registryKey = RegistryKey.parse(v);
if (configRegistry.contains(registryKey)) {
@@ -126,7 +144,6 @@ public class MetaPackImpl implements MetaPack {
@Override
public String getAuthor() {
return author;
}

View File

@@ -8,6 +8,7 @@ import com.dfsek.tectonic.api.config.template.annotations.Value;
import java.util.Map;
@SuppressWarnings({ "unused", "FieldMayBeFinal" })
public class MetaPackTemplate implements ConfigTemplate {
@Value("id")
private String id;

View File

@@ -6,6 +6,7 @@ import com.dfsek.tectonic.api.exception.LoadException;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.SpawnGroup;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.server.MinecraftServer;
import net.minecraft.sound.BiomeAdditionsSound;
import net.minecraft.sound.BiomeMoodSound;
@@ -27,6 +28,7 @@ import net.minecraft.world.gen.WorldPreset;
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;
import org.jetbrains.annotations.NotNull;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.function.BiConsumer;
@@ -61,9 +63,17 @@ public abstract class ModPlatform extends AbstractPlatform {
public abstract MinecraftServer getServer();
public void registerWorldTypes(BiConsumer<Identifier, WorldPreset> registerFunction) {
HashSet<String> configPacksInMetaPack = new HashSet<>();
getRawMetaConfigRegistry().forEach(pack -> {
PresetUtil.createMetaPackPreset(pack, this).apply(registerFunction);
pack.packs().forEach((k, v) -> configPacksInMetaPack.add(v.getID()));
});
getRawConfigRegistry()
.forEach(pack -> PresetUtil.createDefault(pack, this).apply(registerFunction));
getRawMetaConfigRegistry().forEach(pack -> PresetUtil.createMetaPackPreset(pack, this).apply(registerFunction));
.forEach(pack -> {
if (!configPacksInMetaPack.contains(pack.getID())) {
PresetUtil.createDefault(pack, this).apply(registerFunction);
}
});
}
@Override

View File

@@ -10,7 +10,6 @@
"access.StructureAccessorAccessor",
"access.VillagerTypeAccessor",
"fix.BeeMoveGoalsUnsynchronizedRandomAccessFix",
"fix.NetherFossilOptimization",
"implementations.compat.GenerationSettingsFloraFeaturesMixin",
"implementations.terra.BiomeMixin",
"implementations.terra.HandleImplementationMixin",

View File

@@ -35,12 +35,6 @@ public final class BiomeUtil {
pack.getCheckedRegistry(Biome.class)
.forEach((id, biome) -> registerBiome(biome, pack, id, biomeRegistry));
});
CommonPlatform.get().getMetaConfigRegistry().forEach(metaPack -> { // Register all Terra biomes.
metaPack.packs().forEach((k, pack) -> {
pack.getCheckedRegistry(Biome.class)
.forEach((id, biome) -> registerBiome(biome, pack, id, biomeRegistry));
});
});
logger.info("Terra biomes registered.");
}