mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-17 14:21:08 +00:00
fix biome specific exclusions
This commit is contained in:
+18
-1
@@ -1,5 +1,7 @@
|
|||||||
package com.dfsek.terra.api.event.events.config;
|
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.api.event.events.PackEvent;
|
||||||
import com.dfsek.terra.config.pack.ConfigPack;
|
import com.dfsek.terra.config.pack.ConfigPack;
|
||||||
|
|
||||||
@@ -8,13 +10,28 @@ import com.dfsek.terra.config.pack.ConfigPack;
|
|||||||
*/
|
*/
|
||||||
public abstract class ConfigPackLoadEvent implements PackEvent {
|
public abstract class ConfigPackLoadEvent implements PackEvent {
|
||||||
private final ConfigPack pack;
|
private final ConfigPack pack;
|
||||||
|
private final ExceptionalConsumer<ConfigTemplate> configLoader;
|
||||||
|
|
||||||
public ConfigPackLoadEvent(ConfigPack pack) {
|
public ConfigPackLoadEvent(ConfigPack pack, ExceptionalConsumer<ConfigTemplate> configLoader) {
|
||||||
this.pack = pack;
|
this.pack = pack;
|
||||||
|
this.configLoader = configLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ConfigPack getPack() {
|
public ConfigPack getPack() {
|
||||||
return pack;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-2
@@ -1,12 +1,13 @@
|
|||||||
package com.dfsek.terra.api.event.events.config;
|
package com.dfsek.terra.api.event.events.config;
|
||||||
|
|
||||||
|
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||||
import com.dfsek.terra.config.pack.ConfigPack;
|
import com.dfsek.terra.config.pack.ConfigPack;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a config pack has finished loading.
|
* Called when a config pack has finished loading.
|
||||||
*/
|
*/
|
||||||
public class ConfigPackPostLoadEvent extends ConfigPackLoadEvent {
|
public class ConfigPackPostLoadEvent extends ConfigPackLoadEvent {
|
||||||
public ConfigPackPostLoadEvent(ConfigPack pack) {
|
public ConfigPackPostLoadEvent(ConfigPack pack, ExceptionalConsumer<ConfigTemplate> loader) {
|
||||||
super(pack);
|
super(pack, loader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-17
@@ -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.
|
* 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 {
|
public class ConfigPackPreLoadEvent extends ConfigPackLoadEvent {
|
||||||
private final ExceptionalConsumer<ConfigTemplate> configLoader;
|
|
||||||
|
|
||||||
public ConfigPackPreLoadEvent(ConfigPack pack, ExceptionalConsumer<ConfigTemplate> configLoader) {
|
public ConfigPackPreLoadEvent(ConfigPack pack, ExceptionalConsumer<ConfigTemplate> configLoader) {
|
||||||
super(pack);
|
super(pack, configLoader);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,6 +111,8 @@ public class ConfigPack implements LoaderRegistrar {
|
|||||||
private final TerraPlugin main;
|
private final TerraPlugin main;
|
||||||
private final Loader loader;
|
private final Loader loader;
|
||||||
|
|
||||||
|
private final Configuration configuration;
|
||||||
|
|
||||||
private final BiomeProvider.BiomeProviderBuilder biomeProviderBuilder;
|
private final BiomeProvider.BiomeProviderBuilder biomeProviderBuilder;
|
||||||
|
|
||||||
|
|
||||||
@@ -131,7 +133,7 @@ public class ConfigPack implements LoaderRegistrar {
|
|||||||
File pack = new File(folder, "pack.yml");
|
File pack = new File(folder, "pack.yml");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Configuration configuration = new Configuration(new FileInputStream(pack));
|
configuration = new Configuration(new FileInputStream(pack));
|
||||||
selfLoader.load(template, configuration);
|
selfLoader.load(template, configuration);
|
||||||
|
|
||||||
main.logger().info("Loading config pack \"" + template.getID() + "\"");
|
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());
|
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);
|
selfLoader.load(template, configuration);
|
||||||
main.logger().info("Loading config pack \"" + template.getID() + "\"");
|
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("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();
|
.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.");
|
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.TerraEventManager;
|
||||||
import com.dfsek.terra.api.event.annotations.Global;
|
import com.dfsek.terra.api.event.annotations.Global;
|
||||||
import com.dfsek.terra.api.event.annotations.Priority;
|
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.event.events.config.ConfigPackPreLoadEvent;
|
||||||
import com.dfsek.terra.api.platform.block.BlockData;
|
import com.dfsek.terra.api.platform.block.BlockData;
|
||||||
import com.dfsek.terra.api.platform.handle.ItemHandle;
|
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.LangUtil;
|
||||||
import com.dfsek.terra.config.lang.Language;
|
import com.dfsek.terra.config.lang.Language;
|
||||||
import com.dfsek.terra.config.pack.ConfigPack;
|
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.FabricChunkGeneratorWrapper;
|
||||||
import com.dfsek.terra.fabric.generation.PopulatorFeature;
|
import com.dfsek.terra.fabric.generation.PopulatorFeature;
|
||||||
import com.dfsek.terra.fabric.generation.TerraBiomeSource;
|
import com.dfsek.terra.fabric.generation.TerraBiomeSource;
|
||||||
@@ -295,7 +297,7 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
|||||||
|
|
||||||
private final TerraPlugin main;
|
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) {
|
private FabricAddon(TerraPlugin main) {
|
||||||
this.main = main;
|
this.main = main;
|
||||||
@@ -330,7 +332,7 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
|||||||
injectTree(treeRegistry, "CRIMSON_FUNGUS", ConfiguredFeatures.CRIMSON_FUNGI);
|
injectTree(treeRegistry, "CRIMSON_FUNGUS", ConfiguredFeatures.CRIMSON_FUNGI);
|
||||||
injectTree(treeRegistry, "WARPED_FUNGUS", ConfiguredFeatures.WARPED_FUNGI);
|
injectTree(treeRegistry, "WARPED_FUNGUS", ConfiguredFeatures.WARPED_FUNGI);
|
||||||
|
|
||||||
PackCompatibilityOptions template = new PackCompatibilityOptions();
|
PreLoadCompatibilityOptions template = new PreLoadCompatibilityOptions();
|
||||||
try {
|
try {
|
||||||
event.loadTemplate(template);
|
event.loadTemplate(template);
|
||||||
} catch(ConfigException e) {
|
} 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;
|
return templates;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+30
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-17
@@ -12,7 +12,7 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@SuppressWarnings("FieldMayBeFinal")
|
@SuppressWarnings("FieldMayBeFinal")
|
||||||
public class PackCompatibilityOptions implements ConfigTemplate {
|
public class PreLoadCompatibilityOptions implements ConfigTemplate {
|
||||||
@Value("features.inject-registry.enable")
|
@Value("features.inject-registry.enable")
|
||||||
@Default
|
@Default
|
||||||
private boolean doRegistryInjection = false;
|
private boolean doRegistryInjection = false;
|
||||||
@@ -29,18 +29,10 @@ public class PackCompatibilityOptions implements ConfigTemplate {
|
|||||||
@Default
|
@Default
|
||||||
private Set<Identifier> excludedBiomeFeatures = new HashSet<>();
|
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")
|
@Value("structures.inject-biome.excluded-features")
|
||||||
@Default
|
@Default
|
||||||
private Set<Identifier> excludedBiomeStructures = new HashSet<>();
|
private Set<Identifier> excludedBiomeStructures = new HashSet<>();
|
||||||
|
|
||||||
@Value("structures.inject-biome.exclude-biomes")
|
|
||||||
@Default
|
|
||||||
private Map<BiomeBuilder, Set<Identifier>> excludedPerBiomeStructures = new HashMap<>();
|
|
||||||
|
|
||||||
public boolean doBiomeInjection() {
|
public boolean doBiomeInjection() {
|
||||||
return doBiomeInjection;
|
return doBiomeInjection;
|
||||||
}
|
}
|
||||||
@@ -57,14 +49,6 @@ public class PackCompatibilityOptions implements ConfigTemplate {
|
|||||||
return excludedRegistryFeatures;
|
return excludedRegistryFeatures;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<BiomeBuilder, Set<Identifier>> getExcludedPerBiomeFeatures() {
|
|
||||||
return excludedPerBiomeFeatures;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<BiomeBuilder, Set<Identifier>> getExcludedPerBiomeStructures() {
|
|
||||||
return excludedPerBiomeStructures;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<Identifier> getExcludedBiomeStructures() {
|
public Set<Identifier> getExcludedBiomeStructures() {
|
||||||
return excludedBiomeStructures;
|
return excludedBiomeStructures;
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,12 @@
|
|||||||
package com.dfsek.terra.fabric.util;
|
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.builder.BiomeBuilder;
|
||||||
import com.dfsek.terra.config.pack.ConfigPack;
|
import com.dfsek.terra.config.pack.ConfigPack;
|
||||||
import com.dfsek.terra.config.templates.BiomeTemplate;
|
import com.dfsek.terra.config.templates.BiomeTemplate;
|
||||||
import com.dfsek.terra.fabric.TerraFabricPlugin;
|
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 com.dfsek.terra.fabric.mixin.access.BiomeEffectsAccessor;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.registry.BuiltinRegistries;
|
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()) {
|
for(Supplier<ConfiguredStructureFeature<?, ?>> structureFeature : vanilla.getGenerationSettings().getStructureFeatures()) {
|
||||||
Identifier key = BuiltinRegistries.CONFIGURED_STRUCTURE_FEATURE.getId(structureFeature.get());
|
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());
|
generationSettings.structureFeature(structureFeature.get());
|
||||||
|
TerraFabricPlugin.getInstance().getDebugLogger().info("Injected structure " + key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(compatibilityOptions.doBiomeInjection()) {
|
if(compatibilityOptions.doBiomeInjection()) {
|
||||||
TerraFabricPlugin.getInstance().getDebugLogger().info("Injecting features into " + biome.getTemplate().getID());
|
|
||||||
for(int step = 0; step < vanilla.getGenerationSettings().getFeatures().size(); step++) {
|
for(int step = 0; step < vanilla.getGenerationSettings().getFeatures().size(); step++) {
|
||||||
for(Supplier<ConfiguredFeature<?, ?>> featureSupplier : vanilla.getGenerationSettings().getFeatures().get(step)) {
|
for(Supplier<ConfiguredFeature<?, ?>> featureSupplier : vanilla.getGenerationSettings().getFeatures().get(step)) {
|
||||||
Identifier key = BuiltinRegistries.CONFIGURED_FEATURE.getId(featureSupplier.get());
|
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);
|
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