mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-10 17:56:03 +00:00
fix biome specific exclusions
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package com.dfsek.terra.api.event.events.config;
|
||||
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
import com.dfsek.tectonic.exception.ConfigException;
|
||||
import com.dfsek.terra.api.event.events.PackEvent;
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
|
||||
@@ -8,13 +10,28 @@ import com.dfsek.terra.config.pack.ConfigPack;
|
||||
*/
|
||||
public abstract class ConfigPackLoadEvent implements PackEvent {
|
||||
private final ConfigPack pack;
|
||||
private final ExceptionalConsumer<ConfigTemplate> configLoader;
|
||||
|
||||
public ConfigPackLoadEvent(ConfigPack pack) {
|
||||
public ConfigPackLoadEvent(ConfigPack pack, ExceptionalConsumer<ConfigTemplate> configLoader) {
|
||||
this.pack = pack;
|
||||
this.configLoader = configLoader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigPack getPack() {
|
||||
return pack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a custom {@link ConfigTemplate} using the pack manifest.
|
||||
*
|
||||
* @param template Template to register.
|
||||
*/
|
||||
public void loadTemplate(ConfigTemplate template) throws ConfigException {
|
||||
configLoader.accept(template);
|
||||
}
|
||||
|
||||
public interface ExceptionalConsumer<T extends ConfigTemplate> {
|
||||
void accept(T value) throws ConfigException;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package com.dfsek.terra.api.event.events.config;
|
||||
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
|
||||
/**
|
||||
* Called when a config pack has finished loading.
|
||||
*/
|
||||
public class ConfigPackPostLoadEvent extends ConfigPackLoadEvent {
|
||||
public ConfigPackPostLoadEvent(ConfigPack pack) {
|
||||
super(pack);
|
||||
public ConfigPackPostLoadEvent(ConfigPack pack, ExceptionalConsumer<ConfigTemplate> loader) {
|
||||
super(pack, loader);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,23 +8,7 @@ import com.dfsek.terra.config.pack.ConfigPack;
|
||||
* Called before a config pack's registries are filled. At this point, the pack manifest has been loaded, and all registries are empty.
|
||||
*/
|
||||
public class ConfigPackPreLoadEvent extends ConfigPackLoadEvent {
|
||||
private final ExceptionalConsumer<ConfigTemplate> configLoader;
|
||||
|
||||
public ConfigPackPreLoadEvent(ConfigPack pack, ExceptionalConsumer<ConfigTemplate> configLoader) {
|
||||
super(pack);
|
||||
this.configLoader = configLoader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a custom {@link ConfigTemplate} using the pack manifest.
|
||||
*
|
||||
* @param template Template to register.
|
||||
*/
|
||||
public void loadTemplate(ConfigTemplate template) throws ConfigException {
|
||||
configLoader.accept(template);
|
||||
}
|
||||
|
||||
public interface ExceptionalConsumer<T extends ConfigTemplate> {
|
||||
void accept(T value) throws ConfigException;
|
||||
super(pack, configLoader);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,6 +111,8 @@ public class ConfigPack implements LoaderRegistrar {
|
||||
private final TerraPlugin main;
|
||||
private final Loader loader;
|
||||
|
||||
private final Configuration configuration;
|
||||
|
||||
private final BiomeProvider.BiomeProviderBuilder biomeProviderBuilder;
|
||||
|
||||
|
||||
@@ -131,7 +133,7 @@ public class ConfigPack implements LoaderRegistrar {
|
||||
File pack = new File(folder, "pack.yml");
|
||||
|
||||
try {
|
||||
Configuration configuration = new Configuration(new FileInputStream(pack));
|
||||
configuration = new Configuration(new FileInputStream(pack));
|
||||
selfLoader.load(template, configuration);
|
||||
|
||||
main.logger().info("Loading config pack \"" + template.getID() + "\"");
|
||||
@@ -179,7 +181,7 @@ public class ConfigPack implements LoaderRegistrar {
|
||||
|
||||
if(pack == null) throw new LoadException("No pack.yml file found in " + file.getName());
|
||||
|
||||
Configuration configuration = new Configuration(file.getInputStream(pack));
|
||||
configuration = new Configuration(file.getInputStream(pack));
|
||||
selfLoader.load(template, configuration);
|
||||
main.logger().info("Loading config pack \"" + template.getID() + "\"");
|
||||
|
||||
@@ -251,7 +253,7 @@ public class ConfigPack implements LoaderRegistrar {
|
||||
.open("flora", ".yml").then(configs -> buildAll(new FloraFactory(), floraRegistry, abstractConfigLoader.loadConfigs(configs, FloraTemplate::new), main)).close()
|
||||
.open("biomes", ".yml").then(configs -> buildAll(new BiomeFactory(this), biomeRegistry, abstractConfigLoader.loadConfigs(configs, () -> new BiomeTemplate(this, main)), main)).close();
|
||||
|
||||
main.getEventManager().callEvent(new ConfigPackPostLoadEvent(this));
|
||||
main.getEventManager().callEvent(new ConfigPackPostLoadEvent(this, template -> selfLoader.load(template, configuration)));
|
||||
main.logger().info("Loaded config pack \"" + template.getID() + "\" v" + template.getVersion() + " by " + template.getAuthor() + " in " + (System.nanoTime() - start) / 1000000D + "ms.");
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ import com.dfsek.terra.api.event.EventManager;
|
||||
import com.dfsek.terra.api.event.TerraEventManager;
|
||||
import com.dfsek.terra.api.event.annotations.Global;
|
||||
import com.dfsek.terra.api.event.annotations.Priority;
|
||||
import com.dfsek.terra.api.event.events.config.ConfigPackPostLoadEvent;
|
||||
import com.dfsek.terra.api.event.events.config.ConfigPackPreLoadEvent;
|
||||
import com.dfsek.terra.api.platform.block.BlockData;
|
||||
import com.dfsek.terra.api.platform.handle.ItemHandle;
|
||||
@@ -35,7 +36,8 @@ import com.dfsek.terra.config.PluginConfig;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.config.lang.Language;
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
import com.dfsek.terra.fabric.config.PackCompatibilityOptions;
|
||||
import com.dfsek.terra.fabric.config.PostLoadCompatibilityOptions;
|
||||
import com.dfsek.terra.fabric.config.PreLoadCompatibilityOptions;
|
||||
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.fabric.generation.PopulatorFeature;
|
||||
import com.dfsek.terra.fabric.generation.TerraBiomeSource;
|
||||
@@ -295,7 +297,7 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
|
||||
private final TerraPlugin main;
|
||||
|
||||
private final Map<ConfigPack, PackCompatibilityOptions> templates = new HashMap<>();
|
||||
private final Map<ConfigPack, Pair<PreLoadCompatibilityOptions, PostLoadCompatibilityOptions>> templates = new HashMap<>();
|
||||
|
||||
private FabricAddon(TerraPlugin main) {
|
||||
this.main = main;
|
||||
@@ -330,7 +332,7 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
injectTree(treeRegistry, "CRIMSON_FUNGUS", ConfiguredFeatures.CRIMSON_FUNGI);
|
||||
injectTree(treeRegistry, "WARPED_FUNGUS", ConfiguredFeatures.WARPED_FUNGI);
|
||||
|
||||
PackCompatibilityOptions template = new PackCompatibilityOptions();
|
||||
PreLoadCompatibilityOptions template = new PreLoadCompatibilityOptions();
|
||||
try {
|
||||
event.loadTemplate(template);
|
||||
} catch(ConfigException e) {
|
||||
@@ -348,7 +350,21 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
}
|
||||
});
|
||||
}
|
||||
templates.put(event.getPack(), template);
|
||||
templates.put(event.getPack(), Pair.of(template, null));
|
||||
}
|
||||
|
||||
@Priority(Priority.HIGHEST)
|
||||
@Global
|
||||
public void createInjectionOptions(ConfigPackPostLoadEvent event) {
|
||||
PostLoadCompatibilityOptions template = new PostLoadCompatibilityOptions();
|
||||
|
||||
try {
|
||||
event.loadTemplate(template);
|
||||
} catch(ConfigException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
templates.get(event.getPack()).setRight(template);
|
||||
}
|
||||
|
||||
|
||||
@@ -359,7 +375,7 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
}
|
||||
}
|
||||
|
||||
public Map<ConfigPack, PackCompatibilityOptions> getTemplates() {
|
||||
public Map<ConfigPack, Pair<PreLoadCompatibilityOptions, PostLoadCompatibilityOptions>> getTemplates() {
|
||||
return templates;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.dfsek.terra.fabric.config;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
import com.dfsek.terra.config.builder.BiomeBuilder;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@SuppressWarnings("FieldMayBeFinal")
|
||||
public class PostLoadCompatibilityOptions implements ConfigTemplate {
|
||||
@Value("structures.inject-biome.exclude-biomes")
|
||||
@Default
|
||||
private Map<BiomeBuilder, Set<Identifier>> excludedPerBiomeStructures = new HashMap<>();
|
||||
|
||||
@Value("features.inject-biome.exclude-biomes")
|
||||
@Default
|
||||
private Map<BiomeBuilder, Set<Identifier>> excludedPerBiomeFeatures = new HashMap<>();
|
||||
|
||||
public Map<BiomeBuilder, Set<Identifier>> getExcludedPerBiomeFeatures() {
|
||||
return excludedPerBiomeFeatures;
|
||||
}
|
||||
|
||||
public Map<BiomeBuilder, Set<Identifier>> getExcludedPerBiomeStructures() {
|
||||
return excludedPerBiomeStructures;
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@SuppressWarnings("FieldMayBeFinal")
|
||||
public class PackCompatibilityOptions implements ConfigTemplate {
|
||||
public class PreLoadCompatibilityOptions implements ConfigTemplate {
|
||||
@Value("features.inject-registry.enable")
|
||||
@Default
|
||||
private boolean doRegistryInjection = false;
|
||||
@@ -29,18 +29,10 @@ public class PackCompatibilityOptions implements ConfigTemplate {
|
||||
@Default
|
||||
private Set<Identifier> excludedBiomeFeatures = new HashSet<>();
|
||||
|
||||
@Value("features.inject-biome.exclude-biomes")
|
||||
@Default
|
||||
private Map<BiomeBuilder, Set<Identifier>> excludedPerBiomeFeatures = new HashMap<>();
|
||||
|
||||
@Value("structures.inject-biome.excluded-features")
|
||||
@Default
|
||||
private Set<Identifier> excludedBiomeStructures = new HashSet<>();
|
||||
|
||||
@Value("structures.inject-biome.exclude-biomes")
|
||||
@Default
|
||||
private Map<BiomeBuilder, Set<Identifier>> excludedPerBiomeStructures = new HashMap<>();
|
||||
|
||||
public boolean doBiomeInjection() {
|
||||
return doBiomeInjection;
|
||||
}
|
||||
@@ -57,14 +49,6 @@ public class PackCompatibilityOptions implements ConfigTemplate {
|
||||
return excludedRegistryFeatures;
|
||||
}
|
||||
|
||||
public Map<BiomeBuilder, Set<Identifier>> getExcludedPerBiomeFeatures() {
|
||||
return excludedPerBiomeFeatures;
|
||||
}
|
||||
|
||||
public Map<BiomeBuilder, Set<Identifier>> getExcludedPerBiomeStructures() {
|
||||
return excludedPerBiomeStructures;
|
||||
}
|
||||
|
||||
public Set<Identifier> getExcludedBiomeStructures() {
|
||||
return excludedBiomeStructures;
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
package com.dfsek.terra.fabric.util;
|
||||
|
||||
import com.dfsek.terra.api.util.generic.pair.Pair;
|
||||
import com.dfsek.terra.config.builder.BiomeBuilder;
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
import com.dfsek.terra.config.templates.BiomeTemplate;
|
||||
import com.dfsek.terra.fabric.TerraFabricPlugin;
|
||||
import com.dfsek.terra.fabric.config.PackCompatibilityOptions;
|
||||
import com.dfsek.terra.fabric.config.PostLoadCompatibilityOptions;
|
||||
import com.dfsek.terra.fabric.config.PreLoadCompatibilityOptions;
|
||||
import com.dfsek.terra.fabric.mixin.access.BiomeEffectsAccessor;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.BuiltinRegistries;
|
||||
@@ -53,23 +55,27 @@ public final class FabricUtil {
|
||||
}
|
||||
}
|
||||
|
||||
PackCompatibilityOptions compatibilityOptions = fabricAddon.getTemplates().get(pack);
|
||||
Pair<PreLoadCompatibilityOptions, PostLoadCompatibilityOptions> pair = fabricAddon.getTemplates().get(pack);
|
||||
PreLoadCompatibilityOptions compatibilityOptions = pair.getLeft();
|
||||
PostLoadCompatibilityOptions postLoadCompatibilityOptions = pair.getRight();
|
||||
|
||||
TerraFabricPlugin.getInstance().getDebugLogger().info("Injecting Vanilla structures and features into Terra biome " + biome.getTemplate().getID());
|
||||
|
||||
for(Supplier<ConfiguredStructureFeature<?, ?>> structureFeature : vanilla.getGenerationSettings().getStructureFeatures()) {
|
||||
Identifier key = BuiltinRegistries.CONFIGURED_STRUCTURE_FEATURE.getId(structureFeature.get());
|
||||
if(!compatibilityOptions.getExcludedBiomeStructures().contains(key) && !compatibilityOptions.getExcludedPerBiomeStructures().getOrDefault(biome, Collections.emptySet()).contains(key)) {
|
||||
if(!compatibilityOptions.getExcludedBiomeStructures().contains(key) && !postLoadCompatibilityOptions.getExcludedPerBiomeStructures().getOrDefault(biome, Collections.emptySet()).contains(key)) {
|
||||
generationSettings.structureFeature(structureFeature.get());
|
||||
TerraFabricPlugin.getInstance().getDebugLogger().info("Injected structure " + key);
|
||||
}
|
||||
}
|
||||
|
||||
if(compatibilityOptions.doBiomeInjection()) {
|
||||
TerraFabricPlugin.getInstance().getDebugLogger().info("Injecting features into " + biome.getTemplate().getID());
|
||||
for(int step = 0; step < vanilla.getGenerationSettings().getFeatures().size(); step++) {
|
||||
for(Supplier<ConfiguredFeature<?, ?>> featureSupplier : vanilla.getGenerationSettings().getFeatures().get(step)) {
|
||||
Identifier key = BuiltinRegistries.CONFIGURED_FEATURE.getId(featureSupplier.get());
|
||||
if(!compatibilityOptions.getExcludedBiomeFeatures().contains(key) && !compatibilityOptions.getExcludedPerBiomeFeatures().getOrDefault(biome, Collections.emptySet()).contains(key)) {
|
||||
if(!compatibilityOptions.getExcludedBiomeFeatures().contains(key) && !postLoadCompatibilityOptions.getExcludedPerBiomeFeatures().getOrDefault(biome, Collections.emptySet()).contains(key)) {
|
||||
generationSettings.feature(step, featureSupplier);
|
||||
TerraFabricPlugin.getInstance().getDebugLogger().info("Injected " + key + " at stage " + step);
|
||||
TerraFabricPlugin.getInstance().getDebugLogger().info("Injected feature " + key + " at stage " + step);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user