mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-03 16:35:50 +00:00
implement biome colors on fabric
This commit is contained in:
parent
3a626d9101
commit
039e45ef97
@ -27,4 +27,8 @@ public class Context {
|
||||
map.put(properties.getClass(), properties);
|
||||
return this;
|
||||
}
|
||||
|
||||
public <T extends Properties> boolean has(Class<T> test) {
|
||||
return map.containsKey(test);
|
||||
}
|
||||
}
|
||||
|
@ -21,8 +21,11 @@ import ca.solostudios.strata.Versions;
|
||||
import ca.solostudios.strata.version.Version;
|
||||
import com.dfsek.tectonic.api.exception.ConfigException;
|
||||
|
||||
import com.dfsek.terra.api.event.events.config.ConfigurationLoadEvent;
|
||||
import com.dfsek.terra.api.registry.key.RegistryKey;
|
||||
|
||||
import com.dfsek.terra.fabric.config.BiomeColors;
|
||||
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -92,6 +95,16 @@ public final class FabricAddon implements BaseAddon {
|
||||
logger.info("Biomes registered.");
|
||||
})
|
||||
.global();
|
||||
|
||||
terraFabricPlugin.getEventManager()
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(this, ConfigurationLoadEvent.class)
|
||||
.then(event -> {
|
||||
if(event.is(Biome.class)) {
|
||||
event.getLoadedObject(Biome.class).getContext().put(event.load(new BiomeColors()));
|
||||
}
|
||||
})
|
||||
.global();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,58 @@
|
||||
package com.dfsek.terra.fabric.config;
|
||||
|
||||
import com.dfsek.tectonic.api.config.template.ConfigTemplate;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Default;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||
|
||||
import com.dfsek.terra.api.properties.Properties;
|
||||
|
||||
|
||||
public class BiomeColors implements ConfigTemplate, Properties {
|
||||
@Value("colors.grass")
|
||||
@Default
|
||||
private Integer grassColor = null;
|
||||
|
||||
@Value("colors.fog")
|
||||
@Default
|
||||
private Integer fogColor = null;
|
||||
|
||||
@Value("colors.water")
|
||||
@Default
|
||||
private Integer waterColor = null;
|
||||
|
||||
@Value("colors.water-fog")
|
||||
@Default
|
||||
private Integer waterFogColor = null;
|
||||
|
||||
@Value("colors.foliage")
|
||||
@Default
|
||||
private Integer foliageColor = null;
|
||||
|
||||
@Value("colors.sky")
|
||||
@Default
|
||||
private Integer skyColor = null;
|
||||
|
||||
public Integer getFogColor() {
|
||||
return fogColor;
|
||||
}
|
||||
|
||||
public Integer getFoliageColor() {
|
||||
return foliageColor;
|
||||
}
|
||||
|
||||
public Integer getGrassColor() {
|
||||
return grassColor;
|
||||
}
|
||||
|
||||
public Integer getWaterColor() {
|
||||
return waterColor;
|
||||
}
|
||||
|
||||
public Integer getWaterFogColor() {
|
||||
return waterFogColor;
|
||||
}
|
||||
|
||||
public Integer getSkyColor() {
|
||||
return skyColor;
|
||||
}
|
||||
}
|
@ -34,19 +34,5 @@ import com.dfsek.terra.api.world.biome.Biome;
|
||||
|
||||
@SuppressWarnings("FieldMayBeFinal")
|
||||
public class PostLoadCompatibilityOptions implements ConfigTemplate, Properties {
|
||||
@Value("structures.inject-biome.exclude-biomes")
|
||||
@Default
|
||||
private Map<Biome, Set<Identifier>> excludedPerBiomeStructures = new HashMap<>();
|
||||
|
||||
@Value("features.inject-biome.exclude-biomes")
|
||||
@Default
|
||||
private Map<Biome, Set<Identifier>> excludedPerBiomeFeatures = new HashMap<>();
|
||||
|
||||
public Map<Biome, Set<Identifier>> getExcludedPerBiomeFeatures() {
|
||||
return excludedPerBiomeFeatures;
|
||||
}
|
||||
|
||||
public Map<Biome, Set<Identifier>> getExcludedPerBiomeStructures() {
|
||||
return excludedPerBiomeStructures;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -31,43 +31,5 @@ import java.util.Set;
|
||||
|
||||
@SuppressWarnings("FieldMayBeFinal")
|
||||
public class PreLoadCompatibilityOptions implements ConfigTemplate, Properties {
|
||||
@Value("features.inject-registry.enable")
|
||||
@Default
|
||||
private boolean doRegistryInjection = false;
|
||||
|
||||
@Value("features.inject-biome.enable")
|
||||
@Default
|
||||
private boolean doBiomeInjection = false;
|
||||
|
||||
@Value("features.inject-registry.excluded-features")
|
||||
@Default
|
||||
private Set<Identifier> excludedRegistryFeatures = new HashSet<>();
|
||||
|
||||
@Value("features.inject-biome.excluded-features")
|
||||
@Default
|
||||
private Set<Identifier> excludedBiomeFeatures = new HashSet<>();
|
||||
|
||||
@Value("structures.inject-biome.excluded-features")
|
||||
@Default
|
||||
private Set<Identifier> excludedBiomeStructures = new HashSet<>();
|
||||
|
||||
public boolean doBiomeInjection() {
|
||||
return doBiomeInjection;
|
||||
}
|
||||
|
||||
public boolean doRegistryInjection() {
|
||||
return doRegistryInjection;
|
||||
}
|
||||
|
||||
public Set<Identifier> getExcludedBiomeFeatures() {
|
||||
return excludedBiomeFeatures;
|
||||
}
|
||||
|
||||
public Set<Identifier> getExcludedRegistryFeatures() {
|
||||
return excludedRegistryFeatures;
|
||||
}
|
||||
|
||||
public Set<Identifier> getExcludedBiomeStructures() {
|
||||
return excludedBiomeStructures;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,6 +17,8 @@
|
||||
|
||||
package com.dfsek.terra.fabric.util;
|
||||
|
||||
import com.dfsek.terra.fabric.config.BiomeColors;
|
||||
|
||||
import com.mojang.serialization.Lifecycle;
|
||||
import net.minecraft.block.entity.LootableContainerBlockEntity;
|
||||
import net.minecraft.block.entity.MobSpawnerBlockEntity;
|
||||
@ -68,68 +70,61 @@ public final class FabricUtil {
|
||||
*/
|
||||
public static void registerBiome(Biome biome, ConfigPack pack, DynamicRegistryManager registryManager,
|
||||
com.dfsek.terra.api.registry.key.RegistryKey id) {
|
||||
// BiomeTemplate template = biome.getTemplate();
|
||||
Map<String, Integer> colors = new HashMap<>(); // template.getColors();
|
||||
|
||||
//TerraFabricPlugin.FabricAddon fabricAddon = TerraFabricPlugin.getInstance().getFabricAddon();
|
||||
|
||||
Registry<net.minecraft.world.biome.Biome> biomeRegistry = registryManager.get(Registry.BIOME_KEY);
|
||||
net.minecraft.world.biome.Biome vanilla = ((ProtoPlatformBiome) biome.getPlatformBiome()).get(biomeRegistry);
|
||||
|
||||
GenerationSettings.Builder generationSettings = new GenerationSettings.Builder();
|
||||
|
||||
/*
|
||||
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());
|
||||
|
||||
Registry<ConfiguredStructureFeature<?, ?>> configuredStructureFeatureRegistry = registryManager.get(Registry
|
||||
.CONFIGURED_STRUCTURE_FEATURE_KEY);
|
||||
for(Supplier<ConfiguredStructureFeature<?, ?>> structureFeature : vanilla.getGenerationSettings().getStructureFeatures()) {
|
||||
Identifier key = configuredStructureFeatureRegistry.getId(structureFeature.get());
|
||||
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()) {
|
||||
Registry<ConfiguredFeature<?, ?>> configuredFeatureRegistry = registryManager.get(Registry.CONFIGURED_FEATURE_KEY);
|
||||
for(int step = 0; step < vanilla.getGenerationSettings().getFeatures().size(); step++) {
|
||||
for(Supplier<ConfiguredFeature<?, ?>> featureSupplier : vanilla.getGenerationSettings().getFeatures().get(step)) {
|
||||
Identifier key = configuredFeatureRegistry.getId(featureSupplier.get());
|
||||
if(!compatibilityOptions.getExcludedBiomeFeatures().contains(key) && !postLoadCompatibilityOptions
|
||||
.getExcludedPerBiomeFeatures().getOrDefault(biome, Collections.emptySet()).contains(key)) {
|
||||
generationSettings.feature(step, featureSupplier);
|
||||
TerraFabricPlugin.getInstance().getDebugLogger().info("Injected feature " + key + " at stage " + step);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
BiomeEffectsAccessor accessor = (BiomeEffectsAccessor) vanilla.getEffects();
|
||||
BiomeEffects.Builder effects = new BiomeEffects.Builder()
|
||||
.waterColor(colors.getOrDefault("water", accessor.getWaterColor()))
|
||||
.waterFogColor(colors.getOrDefault("water-fog", accessor.getWaterFogColor()))
|
||||
.fogColor(colors.getOrDefault("fog", accessor.getFogColor()))
|
||||
.skyColor(colors.getOrDefault("sky", accessor.getSkyColor()))
|
||||
.grassColorModifier(accessor.getGrassColorModifier());
|
||||
|
||||
if(colors.containsKey("grass")) {
|
||||
effects.grassColor(colors.get("grass"));
|
||||
} else {
|
||||
accessor.getGrassColor().ifPresent(effects::grassColor);
|
||||
}
|
||||
if(colors.containsKey("foliage")) {
|
||||
effects.foliageColor(colors.get("foliage"));
|
||||
if(biome.getContext().has(BiomeColors.class)) {
|
||||
BiomeColors biomeColors = biome.getContext().get(BiomeColors.class);
|
||||
|
||||
if(biomeColors.getWaterColor() == null) {
|
||||
effects.waterColor(vanilla.getWaterColor());
|
||||
} else {
|
||||
effects.waterColor(biomeColors.getWaterColor());
|
||||
}
|
||||
|
||||
if(biomeColors.getWaterFogColor() == null) {
|
||||
effects.waterFogColor(vanilla.getWaterFogColor());
|
||||
} else {
|
||||
effects.waterFogColor(biomeColors.getWaterFogColor());
|
||||
}
|
||||
|
||||
if(biomeColors.getFogColor() == null) {
|
||||
effects.fogColor(vanilla.getFogColor());
|
||||
} else {
|
||||
effects.fogColor(biomeColors.getFogColor());
|
||||
}
|
||||
|
||||
if(biomeColors.getSkyColor() == null) {
|
||||
effects.skyColor(vanilla.getSkyColor());
|
||||
} else {
|
||||
effects.skyColor(biomeColors.getSkyColor());
|
||||
}
|
||||
|
||||
if(biomeColors.getGrassColor() == null) {
|
||||
accessor.getGrassColor().ifPresent(effects::grassColor);
|
||||
} else {
|
||||
effects.grassColor(biomeColors.getGrassColor());
|
||||
}
|
||||
|
||||
if(biomeColors.getFoliageColor() == null) {
|
||||
accessor.getFoliageColor().ifPresent(effects::foliageColor);
|
||||
} else {
|
||||
effects.foliageColor(biomeColors.getFoliageColor());
|
||||
}
|
||||
|
||||
} else {
|
||||
effects.waterColor(accessor.getWaterColor())
|
||||
.waterFogColor(accessor.getWaterFogColor())
|
||||
.fogColor(accessor.getFogColor())
|
||||
.skyColor(accessor.getSkyColor());
|
||||
accessor.getFoliageColor().ifPresent(effects::foliageColor);
|
||||
accessor.getGrassColor().ifPresent(effects::grassColor);
|
||||
}
|
||||
|
||||
net.minecraft.world.biome.Biome minecraftBiome = new net.minecraft.world.biome.Biome.Builder()
|
||||
@ -141,8 +136,9 @@ public final class FabricUtil {
|
||||
.spawnSettings(vanilla.getSpawnSettings())
|
||||
.generationSettings(generationSettings.build())
|
||||
.build();
|
||||
|
||||
Identifier identifier = new Identifier("terra", FabricUtil.createBiomeID(pack, id));
|
||||
|
||||
|
||||
if(biomeRegistry.containsId(identifier)) {
|
||||
((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(biomeRegistry.get(identifier));
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user