mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-04 00:45:57 +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);
|
map.put(properties.getClass(), properties);
|
||||||
return this;
|
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 ca.solostudios.strata.version.Version;
|
||||||
import com.dfsek.tectonic.api.exception.ConfigException;
|
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.api.registry.key.RegistryKey;
|
||||||
|
|
||||||
|
import com.dfsek.terra.fabric.config.BiomeColors;
|
||||||
|
|
||||||
import net.minecraft.util.registry.Registry;
|
import net.minecraft.util.registry.Registry;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -92,6 +95,16 @@ public final class FabricAddon implements BaseAddon {
|
|||||||
logger.info("Biomes registered.");
|
logger.info("Biomes registered.");
|
||||||
})
|
})
|
||||||
.global();
|
.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
|
@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")
|
@SuppressWarnings("FieldMayBeFinal")
|
||||||
public class PostLoadCompatibilityOptions implements ConfigTemplate, Properties {
|
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")
|
@SuppressWarnings("FieldMayBeFinal")
|
||||||
public class PreLoadCompatibilityOptions implements ConfigTemplate, Properties {
|
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;
|
package com.dfsek.terra.fabric.util;
|
||||||
|
|
||||||
|
import com.dfsek.terra.fabric.config.BiomeColors;
|
||||||
|
|
||||||
import com.mojang.serialization.Lifecycle;
|
import com.mojang.serialization.Lifecycle;
|
||||||
import net.minecraft.block.entity.LootableContainerBlockEntity;
|
import net.minecraft.block.entity.LootableContainerBlockEntity;
|
||||||
import net.minecraft.block.entity.MobSpawnerBlockEntity;
|
import net.minecraft.block.entity.MobSpawnerBlockEntity;
|
||||||
@ -68,68 +70,61 @@ public final class FabricUtil {
|
|||||||
*/
|
*/
|
||||||
public static void registerBiome(Biome biome, ConfigPack pack, DynamicRegistryManager registryManager,
|
public static void registerBiome(Biome biome, ConfigPack pack, DynamicRegistryManager registryManager,
|
||||||
com.dfsek.terra.api.registry.key.RegistryKey id) {
|
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);
|
Registry<net.minecraft.world.biome.Biome> biomeRegistry = registryManager.get(Registry.BIOME_KEY);
|
||||||
net.minecraft.world.biome.Biome vanilla = ((ProtoPlatformBiome) biome.getPlatformBiome()).get(biomeRegistry);
|
net.minecraft.world.biome.Biome vanilla = ((ProtoPlatformBiome) biome.getPlatformBiome()).get(biomeRegistry);
|
||||||
|
|
||||||
GenerationSettings.Builder generationSettings = new GenerationSettings.Builder();
|
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();
|
BiomeEffectsAccessor accessor = (BiomeEffectsAccessor) vanilla.getEffects();
|
||||||
BiomeEffects.Builder effects = new BiomeEffects.Builder()
|
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());
|
.grassColorModifier(accessor.getGrassColorModifier());
|
||||||
|
|
||||||
if(colors.containsKey("grass")) {
|
if(biome.getContext().has(BiomeColors.class)) {
|
||||||
effects.grassColor(colors.get("grass"));
|
BiomeColors biomeColors = biome.getContext().get(BiomeColors.class);
|
||||||
|
|
||||||
|
if(biomeColors.getWaterColor() == null) {
|
||||||
|
effects.waterColor(vanilla.getWaterColor());
|
||||||
} else {
|
} else {
|
||||||
accessor.getGrassColor().ifPresent(effects::grassColor);
|
effects.waterColor(biomeColors.getWaterColor());
|
||||||
}
|
}
|
||||||
if(colors.containsKey("foliage")) {
|
|
||||||
effects.foliageColor(colors.get("foliage"));
|
if(biomeColors.getWaterFogColor() == null) {
|
||||||
|
effects.waterFogColor(vanilla.getWaterFogColor());
|
||||||
} else {
|
} 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);
|
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()
|
net.minecraft.world.biome.Biome minecraftBiome = new net.minecraft.world.biome.Biome.Builder()
|
||||||
@ -141,6 +136,7 @@ public final class FabricUtil {
|
|||||||
.spawnSettings(vanilla.getSpawnSettings())
|
.spawnSettings(vanilla.getSpawnSettings())
|
||||||
.generationSettings(generationSettings.build())
|
.generationSettings(generationSettings.build())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
Identifier identifier = new Identifier("terra", FabricUtil.createBiomeID(pack, id));
|
Identifier identifier = new Identifier("terra", FabricUtil.createBiomeID(pack, id));
|
||||||
|
|
||||||
if(biomeRegistry.containsId(identifier)) {
|
if(biomeRegistry.containsId(identifier)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user