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
@@ -3,9 +3,12 @@ package com.dfsek.terra.config.pack;
import ca.solostudios.strata.version.Version; import ca.solostudios.strata.version.Version;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.ParameterizedType; import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Arrays; import java.util.Arrays;
@@ -73,14 +76,27 @@ public class MetaPackImpl implements MetaPack {
public MetaPackImpl(Path path, Platform platform, ConfigRegistry configRegistry) throws IOException { public MetaPackImpl(Path path, Platform platform, ConfigRegistry configRegistry) throws IOException {
long start = System.nanoTime(); long start = System.nanoTime();
if(Files.notExists(path)) throw new FileNotFoundException("Could not load metapack, " + path + " does not exist");
if(Files.isDirectory(path)) {
this.rootPath = path; this.rootPath = path;
this.platform = platform; } 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"); Path packManifestPath = rootPath.resolve("metapack.yml");
if(Files.notExists(packManifestPath)) throw new IOException("No metapack.yml found in " + path); if(Files.notExists(packManifestPath)) throw new IOException("No metapack.yml found in " + path);
Configuration packManifest = new YamlConfiguration(Files.newInputStream(packManifestPath), Configuration packManifest = new YamlConfiguration(Files.newInputStream(packManifestPath),
packManifestPath.getFileName().toString()); packManifestPath.getFileName().toString());
this.platform = platform;
register(selfLoader); register(selfLoader);
platform.register(selfLoader); platform.register(selfLoader);
@@ -101,6 +117,8 @@ public class MetaPackImpl implements MetaPack {
this.key = RegistryKey.of(namespace, id); this.key = RegistryKey.of(namespace, id);
logger.info("Loading metapack \"{}:{}\"", id, namespace);
template.getPacks().forEach((k, v) -> { template.getPacks().forEach((k, v) -> {
RegistryKey registryKey = RegistryKey.parse(v); RegistryKey registryKey = RegistryKey.parse(v);
if (configRegistry.contains(registryKey)) { if (configRegistry.contains(registryKey)) {
@@ -126,7 +144,6 @@ public class MetaPackImpl implements MetaPack {
@Override @Override
public String getAuthor() { public String getAuthor() {
return author; return author;
} }
@@ -8,6 +8,7 @@ import com.dfsek.tectonic.api.config.template.annotations.Value;
import java.util.Map; import java.util.Map;
@SuppressWarnings({ "unused", "FieldMayBeFinal" })
public class MetaPackTemplate implements ConfigTemplate { public class MetaPackTemplate implements ConfigTemplate {
@Value("id") @Value("id")
private String id; private String id;
@@ -6,6 +6,7 @@ import com.dfsek.tectonic.api.exception.LoadException;
import net.minecraft.entity.EntityType; import net.minecraft.entity.EntityType;
import net.minecraft.entity.SpawnGroup; import net.minecraft.entity.SpawnGroup;
import net.minecraft.registry.Registry; import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.sound.BiomeAdditionsSound; import net.minecraft.sound.BiomeAdditionsSound;
import net.minecraft.sound.BiomeMoodSound; import net.minecraft.sound.BiomeMoodSound;
@@ -27,6 +28,7 @@ import net.minecraft.world.gen.WorldPreset;
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings; import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
@@ -61,9 +63,17 @@ public abstract class ModPlatform extends AbstractPlatform {
public abstract MinecraftServer getServer(); public abstract MinecraftServer getServer();
public void registerWorldTypes(BiConsumer<Identifier, WorldPreset> registerFunction) { 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() getRawConfigRegistry()
.forEach(pack -> PresetUtil.createDefault(pack, this).apply(registerFunction)); .forEach(pack -> {
getRawMetaConfigRegistry().forEach(pack -> PresetUtil.createMetaPackPreset(pack, this).apply(registerFunction)); if (!configPacksInMetaPack.contains(pack.getID())) {
PresetUtil.createDefault(pack, this).apply(registerFunction);
}
});
} }
@Override @Override
@@ -10,7 +10,6 @@
"access.StructureAccessorAccessor", "access.StructureAccessorAccessor",
"access.VillagerTypeAccessor", "access.VillagerTypeAccessor",
"fix.BeeMoveGoalsUnsynchronizedRandomAccessFix", "fix.BeeMoveGoalsUnsynchronizedRandomAccessFix",
"fix.NetherFossilOptimization",
"implementations.compat.GenerationSettingsFloraFeaturesMixin", "implementations.compat.GenerationSettingsFloraFeaturesMixin",
"implementations.terra.BiomeMixin", "implementations.terra.BiomeMixin",
"implementations.terra.HandleImplementationMixin", "implementations.terra.HandleImplementationMixin",
@@ -35,12 +35,6 @@ public final class BiomeUtil {
pack.getCheckedRegistry(Biome.class) pack.getCheckedRegistry(Biome.class)
.forEach((id, biome) -> registerBiome(biome, pack, id, biomeRegistry)); .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."); logger.info("Terra biomes registered.");
} }