Remove Vanilla Key

This commit is contained in:
Zoë
2022-07-11 13:49:55 -07:00
parent b1b91726ef
commit f26cedd613
19 changed files with 226 additions and 343 deletions

View File

@@ -22,6 +22,6 @@ public class BiomeFactory implements ConfigFactory<BiomeTemplate, Biome> {
@Override
public Biome build(BiomeTemplate template, Platform platform) {
return new UserDefinedBiome(template.getVanilla(), template);
return new UserDefinedBiome(template);
}
}

View File

@@ -21,7 +21,6 @@ import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.config.AbstractableTemplate;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.api.config.meta.Meta;
import com.dfsek.terra.api.world.biome.PlatformBiome;
@SuppressWarnings({ "FieldMayBeFinal", "unused" })
@@ -37,13 +36,11 @@ public class BiomeTemplate implements AbstractableTemplate, ValidatedConfigTempl
@Default
private List<String> extended = Collections.emptyList();
@Value("vanilla")
private @Meta PlatformBiome vanilla;
@Value("color")
@Final
@Default
private @Meta int color = 0;
@Value("tags")
@Default
private @Meta Set<@Meta String> tags = new HashSet<>();
@@ -77,8 +74,4 @@ public class BiomeTemplate implements AbstractableTemplate, ValidatedConfigTempl
public String getID() {
return id;
}
public PlatformBiome getVanilla() {
return vanilla;
}
}

View File

@@ -7,6 +7,8 @@
package com.dfsek.terra.addons.biome;
import org.jetbrains.annotations.Nullable;
import java.util.Set;
import com.dfsek.terra.api.properties.Context;
@@ -18,7 +20,8 @@ import com.dfsek.terra.api.world.biome.PlatformBiome;
* Class representing a config-defined biome
*/
public class UserDefinedBiome implements Biome {
private final PlatformBiome vanilla;
private PlatformBiome platformBiome;
private final String id;
private final BiomeTemplate config;
private final int color;
@@ -26,8 +29,7 @@ public class UserDefinedBiome implements Biome {
private final Context context = new Context();
public UserDefinedBiome(PlatformBiome vanilla, BiomeTemplate config) {
this.vanilla = vanilla;
public UserDefinedBiome(BiomeTemplate config) {
this.id = config.getID();
this.config = config;
this.color = config.getColor();
@@ -41,14 +43,9 @@ public class UserDefinedBiome implements Biome {
return "{BIOME:" + getID() + "}";
}
/**
* Gets the Vanilla biomes to represent the custom biome.
*
* @return Collection of biomes to represent the custom biome.
*/
@Override
public PlatformBiome getPlatformBiome() {
return vanilla;
public @Nullable PlatformBiome getPlatformBiome() {
return platformBiome;
}
@Override
@@ -56,6 +53,15 @@ public class UserDefinedBiome implements Biome {
return color;
}
@Override
public void setPlatformBiome(PlatformBiome biome) {
if(platformBiome != null) {
throw new IllegalStateException("Platform biome already set");
}
this.platformBiome = biome;
}
@Override
public Set<String> getTags() {
return tags;

View File

@@ -8,6 +8,8 @@
package com.dfsek.terra.api.world.biome;
import org.jetbrains.annotations.Nullable;
import java.util.Set;
import com.dfsek.terra.api.properties.PropertyHolder;
@@ -24,7 +26,7 @@ public interface Biome extends PropertyHolder, StringIdentifiable {
*
* @return The platform biome.
*/
PlatformBiome getPlatformBiome();
@Nullable PlatformBiome getPlatformBiome();
/**
* Get the color of this biome.
@@ -39,4 +41,9 @@ public interface Biome extends PropertyHolder, StringIdentifiable {
* @return A {@link Set} of String tags this biome holds.
*/
Set<String> getTags();
/**
* Sets the platform biome this custom biome delegates to.
*/
void setPlatformBiome(PlatformBiome biome);
}

View File

@@ -36,7 +36,7 @@ import org.slf4j.LoggerFactory;
import com.dfsek.terra.api.event.events.platform.PlatformInitializationEvent;
import com.dfsek.terra.forge.AwfulForgeHacks.RegistrySanityCheck;
import com.dfsek.terra.forge.AwfulForgeHacks.RegistryStep;
import com.dfsek.terra.forge.util.BiomeUtil;
import com.dfsek.terra.forge.util.ForgeBiomeUtil;
import com.dfsek.terra.mod.data.Codecs;
@@ -64,7 +64,7 @@ public class ForgeEntryPoint {
public static void initialize(RegisterHelper<Biome> helper) {
getPlatform().getEventManager().callEvent(
new PlatformInitializationEvent());
BiomeUtil.registerBiomes(helper);
ForgeBiomeUtil.registerBiomes(helper);
}
@SubscribeEvent(priority = EventPriority.LOWEST)

View File

@@ -22,6 +22,9 @@ import ca.solostudios.strata.parser.tokenizer.ParseException;
import ca.solostudios.strata.version.Version;
import net.minecraft.MinecraftVersion;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.biome.Biome;
import net.minecraftforge.fml.loading.FMLLoader;
import net.minecraftforge.server.ServerLifecycleHooks;
import org.jetbrains.annotations.NotNull;
@@ -35,6 +38,7 @@ import java.util.List;
import com.dfsek.terra.addon.EphemeralAddon;
import com.dfsek.terra.api.addon.BaseAddon;
import com.dfsek.terra.api.util.generic.Lazy;
import com.dfsek.terra.forge.util.ForgeBiomeUtil;
import com.dfsek.terra.mod.CommonPlatform;
import com.dfsek.terra.mod.ModPlatform;
import com.dfsek.terra.mod.generation.MinecraftChunkGeneratorWrapper;
@@ -49,6 +53,11 @@ public class ForgePlatform extends ModPlatform {
load();
}
@Override
public RegistryKey<Biome> getBiomeKey(Identifier identifier) {
return ForgeBiomeUtil.getBiomeKey(identifier);
}
@Override
public MinecraftServer getServer() {
return ServerLifecycleHooks.getCurrentServer();

View File

@@ -1,92 +0,0 @@
package com.dfsek.terra.forge.util;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.BuiltinRegistries;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.village.VillagerType;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegisterEvent.RegisterHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Map;
import java.util.Objects;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.api.world.biome.Biome;
import com.dfsek.terra.forge.ForgeEntryPoint;
import com.dfsek.terra.mod.config.PreLoadCompatibilityOptions;
import com.dfsek.terra.mod.config.ProtoPlatformBiome;
import com.dfsek.terra.mod.config.VanillaBiomeProperties;
import com.dfsek.terra.mod.mixin.access.VillagerTypeAccessor;
import com.dfsek.terra.mod.util.MinecraftUtil;
public final class BiomeUtil {
private static final Logger logger = LoggerFactory.getLogger(BiomeUtil.class);
private BiomeUtil() {
}
public static void registerBiomes(RegisterHelper<net.minecraft.world.biome.Biome> helper) {
logger.info("Registering biomes...");
ForgeEntryPoint.getPlatform().getConfigRegistry().forEach(pack -> { // Register all Terra biomes.
pack.getCheckedRegistry(Biome.class)
.forEach((id, biome) -> registerBiome(biome, pack, id, helper));
});
MinecraftUtil.registerFlora(BuiltinRegistries.BIOME);
logger.info("Terra biomes registered.");
}
/**
* Clones a Vanilla biome and injects Terra data to create a Terra-vanilla biome delegate.
*
* @param biome The Terra BiomeBuilder.
* @param pack The ConfigPack this biome belongs to.
*/
private static void registerBiome(Biome biome, ConfigPack pack,
com.dfsek.terra.api.registry.key.RegistryKey id,
RegisterHelper<net.minecraft.world.biome.Biome> helper) {
RegistryKey<net.minecraft.world.biome.Biome> vanilla = ((ProtoPlatformBiome) biome.getPlatformBiome()).get(BuiltinRegistries.BIOME);
if(pack.getContext().get(PreLoadCompatibilityOptions.class).useVanillaBiomes()) {
((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(vanilla);
} else {
VanillaBiomeProperties vanillaBiomeProperties = biome.getContext().get(VanillaBiomeProperties.class);
net.minecraft.world.biome.Biome minecraftBiome = MinecraftUtil.createBiome(biome,
ForgeRegistries.BIOMES.getDelegateOrThrow(vanilla)
.value(),
vanillaBiomeProperties);
Identifier identifier = new Identifier("terra", MinecraftUtil.createBiomeID(pack, id));
if(ForgeRegistries.BIOMES.containsKey(identifier)) {
((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(ForgeRegistries.BIOMES.getHolder(identifier)
.orElseThrow()
.getKey()
.orElseThrow());
} else {
helper.register(MinecraftUtil.registerKey(identifier).getValue(), minecraftBiome);
((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(ForgeRegistries.BIOMES.getHolder(identifier)
.orElseThrow()
.getKey()
.orElseThrow());
}
Map villagerMap = VillagerTypeAccessor.getBiomeTypeToIdMap();
villagerMap.put(RegistryKey.of(Registry.BIOME_KEY, identifier),
Objects.requireNonNullElse(vanillaBiomeProperties.getVillagerType(),
villagerMap.getOrDefault(vanilla, VillagerType.PLAINS)));
MinecraftUtil.TERRA_BIOME_MAP.computeIfAbsent(vanilla.getValue(), i -> new ArrayList<>()).add(identifier);
}
}
}

View File

@@ -0,0 +1,29 @@
package com.dfsek.terra.forge.util;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.biome.Biome;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegisterEvent.RegisterHelper;
import com.dfsek.terra.mod.util.BiomeUtil;
import com.dfsek.terra.mod.util.MinecraftUtil;
public final class ForgeBiomeUtil extends BiomeUtil {
static RegisterHelper<Biome> helper;
public static void registerBiomes(RegisterHelper<Biome> helper) {
ForgeBiomeUtil.helper = helper;
registerBiomes();
}
protected static RegistryKey<net.minecraft.world.biome.Biome> registerBiome(Identifier identifier,
net.minecraft.world.biome.Biome biome) {
helper.register(MinecraftUtil.registerKey(identifier).getValue(), biome);
return ForgeRegistries.BIOMES.getHolder(identifier)
.orElseThrow()
.getKey()
.orElseThrow();
}
}

View File

@@ -12,7 +12,9 @@ import net.minecraft.sound.MusicSound;
import net.minecraft.sound.SoundEvent;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.BuiltinRegistries;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.village.VillagerType;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.Biome.Precipitation;
import net.minecraft.world.biome.Biome.TemperatureModifier;
import net.minecraft.world.biome.BiomeEffects.GrassColorModifier;
@@ -45,13 +47,14 @@ import com.dfsek.terra.mod.config.SpawnTypeConfig;
import com.dfsek.terra.mod.config.VillagerTypeTemplate;
import com.dfsek.terra.mod.handle.MinecraftItemHandle;
import com.dfsek.terra.mod.handle.MinecraftWorldHandle;
import com.dfsek.terra.mod.util.BiomeUtil;
import com.dfsek.terra.mod.util.PresetUtil;
public abstract class ModPlatform extends AbstractPlatform {
private final ItemHandle itemHandle = new MinecraftItemHandle();
private final WorldHandle worldHandle = new MinecraftWorldHandle();
public abstract MinecraftServer getServer();
public void registerWorldTypes(BiConsumer<Identifier, WorldPreset> registerFunction) {
@@ -59,6 +62,10 @@ public abstract class ModPlatform extends AbstractPlatform {
.forEach(pack -> PresetUtil.createDefault(pack).apply(registerFunction));
}
public RegistryKey<Biome> getBiomeKey(Identifier identifier) {
return BiomeUtil.getBiomeKey(identifier);
}
@Override
public void register(TypeRegistry registry) {
super.register(registry);
@@ -94,7 +101,7 @@ public abstract class ModPlatform extends AbstractPlatform {
private ProtoPlatformBiome parseBiome(String id, DepthTracker tracker) throws LoadException {
Identifier identifier = Identifier.tryParse(id);
if(BuiltinRegistries.BIOME.get(identifier) == null) throw new LoadException("Invalid Biome ID: " + identifier, tracker); // failure.
return new ProtoPlatformBiome(identifier);
return new ProtoPlatformBiome(identifier, getBiomeKey(identifier));
}
@Override

View File

@@ -22,8 +22,6 @@ import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.biome.Biome;
import java.util.Objects;
import com.dfsek.terra.api.world.biome.PlatformBiome;
import com.dfsek.terra.mod.util.MinecraftUtil;
@@ -31,10 +29,11 @@ import com.dfsek.terra.mod.util.MinecraftUtil;
public class ProtoPlatformBiome implements PlatformBiome {
private final Identifier identifier;
private RegistryKey<Biome> delegate;
private final RegistryKey<Biome> biome;
public ProtoPlatformBiome(Identifier identifier) {
public ProtoPlatformBiome(Identifier identifier, RegistryKey<Biome> biome) {
this.identifier = identifier;
this.biome = biome;
}
public RegistryKey<Biome> get(Registry<net.minecraft.world.biome.Biome> registry) {
@@ -46,11 +45,7 @@ public class ProtoPlatformBiome implements PlatformBiome {
return identifier;
}
public RegistryKey<Biome> getDelegate() {
return delegate;
}
public void setDelegate(RegistryKey<Biome> delegate) {
this.delegate = Objects.requireNonNull(delegate);
public RegistryKey<Biome> getBiome() {
return biome;
}
}

View File

@@ -7,6 +7,7 @@ import net.minecraft.sound.BiomeAdditionsSound;
import net.minecraft.sound.BiomeMoodSound;
import net.minecraft.sound.MusicSound;
import net.minecraft.sound.SoundEvent;
import net.minecraft.util.Identifier;
import net.minecraft.village.VillagerType;
import net.minecraft.world.biome.Biome.Precipitation;
import net.minecraft.world.biome.Biome.TemperatureModifier;
@@ -14,82 +15,93 @@ import net.minecraft.world.biome.BiomeEffects.GrassColorModifier;
import net.minecraft.world.biome.BiomeParticleConfig;
import net.minecraft.world.biome.SpawnSettings;
import java.util.List;
import com.dfsek.terra.api.properties.Properties;
public class VanillaBiomeProperties implements ConfigTemplate, Properties {
@Value("colors.grass")
@Value("minecraft.tags")
@Default
private List<Identifier> tags = null;
@Value("minecraft.colors.grass")
@Default
private Integer grassColor = null;
@Value("colors.fog")
@Value("minecraft.colors.fog")
@Default
private Integer fogColor = null;
@Value("colors.water")
@Value("minecraft.colors.water")
@Default
private Integer waterColor = null;
@Value("colors.water-fog")
@Value("minecraft.colors.water-fog")
@Default
private Integer waterFogColor = null;
@Value("colors.foliage")
@Value("minecraft.colors.foliage")
@Default
private Integer foliageColor = null;
@Value("colors.sky")
@Value("minecraft.colors.sky")
@Default
private Integer skyColor = null;
@Value("colors.modifier")
@Value("minecraft.colors.modifier")
@Default
private GrassColorModifier grassColorModifier = null;
@Value("particles")
@Value("minecraft.particles")
@Default
private BiomeParticleConfig particleConfig = null;
@Value("climate.precipitation")
@Value("minecraft.climate.precipitation")
@Default
private Precipitation precipitation = null;
@Value("climate.temperature")
@Value("minecraft.climate.temperature")
@Default
private Float temperature = null;
@Value("climate.temperature-modifier")
@Value("minecraft.climate.temperature-modifier")
@Default
private TemperatureModifier temperatureModifier = null;
@Value("climate.downfall")
@Value("minecraft.climate.downfall")
@Default
private Float downfall = null;
@Value("sound.loop-sound.sound")
@Value("minecraft.sound.loop-sound.sound")
@Default
private SoundEvent loopSound = null;
@Value("sound.mood-sound")
@Value("minecraft.sound.mood-sound")
@Default
private BiomeMoodSound moodSound = null;
@Value("sound.additions-sound")
@Value("minecraft.sound.additions-sound")
@Default
private BiomeAdditionsSound additionsSound = null;
@Value("sound.music")
@Value("minecraft.sound.music")
@Default
private MusicSound music = null;
@Value("spawning")
@Value("minecraft.spawning")
@Default
private SpawnSettings spawnSettings = null;
@Value("villager-type")
@Value("minecraft.villager-type")
@Default
private VillagerType villagerType = null;
public List<Identifier> getTags() {
return tags;
}
public Integer getGrassColor() {
return grassColor;
}

View File

@@ -45,7 +45,7 @@ public class TerraBiomeSource extends BiomeSource {
.stream(pack.getBiomeProvider()
.getBiomes()
.spliterator(), false)
.map(b -> biomes.getOrCreateEntry(((ProtoPlatformBiome) b.getPlatformBiome()).getDelegate())));
.map(b -> biomes.getOrCreateEntry(((ProtoPlatformBiome) b.getPlatformBiome()).getBiome())));
this.biomeRegistry = biomes;
this.pack = pack;
@@ -63,7 +63,7 @@ public class TerraBiomeSource extends BiomeSource {
.entryOf(((ProtoPlatformBiome) pack
.getBiomeProvider()
.getBiome(biomeX << 2, biomeY << 2, biomeZ << 2, SeedHack.getSeed(noiseSampler))
.getPlatformBiome()).getDelegate()
.getPlatformBiome()).getBiome()
);
}

View File

@@ -9,7 +9,6 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.dfsek.terra.mod.util.MinecraftUtil;
import com.dfsek.terra.mod.util.TagUtil;
@@ -24,6 +23,5 @@ public class DataPackContentsMixin {
Registry<Biome> biomeRegistry = dynamicRegistryManager.get(Registry.BIOME_KEY);
TagUtil.registerBiomeTags(biomeRegistry);
MinecraftUtil.registerFlora(biomeRegistry);
}
}

View File

@@ -0,0 +1,74 @@
package com.dfsek.terra.mod.util;
import net.minecraft.tag.TagKey;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.BuiltinRegistries;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.village.VillagerType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Map;
import java.util.Objects;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.api.world.biome.Biome;
import com.dfsek.terra.mod.CommonPlatform;
import com.dfsek.terra.mod.config.ProtoPlatformBiome;
import com.dfsek.terra.mod.config.VanillaBiomeProperties;
import com.dfsek.terra.mod.mixin.access.VillagerTypeAccessor;
public class BiomeUtil {
private static final Logger logger = LoggerFactory.getLogger(BiomeUtil.class);
public static void registerBiomes() {
logger.info("Registering biomes...");
CommonPlatform.get().getConfigRegistry().forEach(pack -> { // Register all Terra biomes.
pack.getCheckedRegistry(Biome.class)
.forEach((id, biome) -> registerBiome(biome, pack, id));
});
logger.info("Terra biomes registered.");
}
protected static RegistryKey<net.minecraft.world.biome.Biome> registerBiome(Identifier identifier,
net.minecraft.world.biome.Biome biome) {
BuiltinRegistries.add(BuiltinRegistries.BIOME,
MinecraftUtil.registerKey(identifier)
.getValue(),
biome);
return getBiomeKey(identifier);
}
public static RegistryKey<net.minecraft.world.biome.Biome> getBiomeKey(Identifier identifier) {
return BuiltinRegistries.BIOME.getKey(BuiltinRegistries.BIOME.get(identifier)).orElseThrow();
}
/**
* Clones a Vanilla biome and injects Terra data to create a Terra-vanilla biome delegate.
*
* @param biome The Terra BiomeBuilder.
* @param pack The ConfigPack this biome belongs to.
*/
protected static void registerBiome(Biome biome, ConfigPack pack,
com.dfsek.terra.api.registry.key.RegistryKey id) {
VanillaBiomeProperties vanillaBiomeProperties = biome.getContext().get(VanillaBiomeProperties.class);
net.minecraft.world.biome.Biome minecraftBiome = MinecraftUtil.createBiome(vanillaBiomeProperties);
Identifier identifier = new Identifier("terra", MinecraftUtil.createBiomeID(pack, id));
biome.setPlatformBiome(new ProtoPlatformBiome(identifier, registerBiome(identifier, minecraftBiome)));
Map villagerMap = VillagerTypeAccessor.getBiomeTypeToIdMap();
villagerMap.put(RegistryKey.of(Registry.BIOME_KEY, identifier),
Objects.requireNonNullElse(vanillaBiomeProperties.getVillagerType(), VillagerType.PLAINS));
for(Identifier tag : vanillaBiomeProperties.getTags()) {
MinecraftUtil.TERRA_BIOME_TAG_MAP.getOrDefault(TagKey.of(Registry.BIOME_KEY, tag), new ArrayList<>()).add(identifier);
}
}
}

View File

@@ -3,6 +3,7 @@ package com.dfsek.terra.mod.util;
import net.minecraft.block.entity.LootableContainerBlockEntity;
import net.minecraft.block.entity.MobSpawnerBlockEntity;
import net.minecraft.block.entity.SignBlockEntity;
import net.minecraft.tag.TagKey;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.Registry;
@@ -13,7 +14,6 @@ import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.Biome.Builder;
import net.minecraft.world.biome.BiomeEffects;
import net.minecraft.world.biome.GenerationSettings;
import net.minecraft.world.gen.feature.ConfiguredFeature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -30,14 +30,13 @@ import com.dfsek.terra.api.block.entity.MobSpawner;
import com.dfsek.terra.api.block.entity.Sign;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.mod.config.VanillaBiomeProperties;
import com.dfsek.terra.mod.mixin.access.BiomeAccessor;
import com.dfsek.terra.mod.mixin_ifaces.FloraFeatureHolder;
public final class MinecraftUtil {
public static final Logger logger = LoggerFactory.getLogger(MinecraftUtil.class);
public static final Map<Identifier, List<Identifier>>
TERRA_BIOME_MAP = new HashMap<>();
public static final Map<TagKey<Biome>, List<Identifier>>
TERRA_BIOME_TAG_MAP = new HashMap<>();
private MinecraftUtil() {
@@ -61,107 +60,62 @@ public final class MinecraftUtil {
return null;
}
public static void registerFlora(Registry<net.minecraft.world.biome.Biome> biomes) {
logger.info("Injecting flora into Terra biomes...");
TERRA_BIOME_MAP
.forEach((vb, terraBiomes) ->
biomes.getOrEmpty(vb)
.ifPresentOrElse(vanilla -> terraBiomes
.forEach(tb -> biomes.getOrEmpty(tb)
.ifPresentOrElse(
terra -> {
List<ConfiguredFeature<?, ?>> flowerFeatures = List.copyOf(
vanilla.getGenerationSettings()
.getFlowerFeatures());
logger.debug("Injecting flora into biome" +
" {} : {}", tb,
flowerFeatures);
((FloraFeatureHolder) terra.getGenerationSettings()).setFloraFeatures(
flowerFeatures);
},
() -> logger.error(
"No such biome: {}",
tb))),
() -> logger.error("No vanilla biome: {}", vb)));
}
public static Map<Identifier, List<Identifier>> getTerraBiomeMap() {
return Map.copyOf(TERRA_BIOME_MAP);
}
public static RegistryKey<Biome> registerKey(Identifier identifier) {
return RegistryKey.of(Registry.BIOME_KEY, identifier);
}
public static Biome createBiome(com.dfsek.terra.api.world.biome.Biome biome, Biome vanilla,
VanillaBiomeProperties vanillaBiomeProperties) {
public static Biome createBiome(VanillaBiomeProperties vanillaBiomeProperties) {
GenerationSettings.Builder generationSettings = new GenerationSettings.Builder();
BiomeEffects.Builder effects = new BiomeEffects.Builder();
net.minecraft.world.biome.Biome.Builder builder = new Builder();
effects.waterColor(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterColor(), vanilla.getWaterColor()))
.waterFogColor(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterFogColor(), vanilla.getWaterFogColor()))
.fogColor(Objects.requireNonNullElse(vanillaBiomeProperties.getFogColor(), vanilla.getFogColor()))
.skyColor(Objects.requireNonNullElse(vanillaBiomeProperties.getSkyColor(), vanilla.getSkyColor()))
effects.waterColor(Objects.requireNonNull(vanillaBiomeProperties.getWaterColor()))
.waterFogColor(Objects.requireNonNull(vanillaBiomeProperties.getWaterFogColor()))
.fogColor(Objects.requireNonNull(vanillaBiomeProperties.getFogColor()))
.skyColor(Objects.requireNonNull(vanillaBiomeProperties.getSkyColor()))
.grassColorModifier(
Objects.requireNonNullElse(vanillaBiomeProperties.getGrassColorModifier(),
vanilla.getEffects().getGrassColorModifier()));
Objects.requireNonNull(vanillaBiomeProperties.getGrassColorModifier()));
if(vanillaBiomeProperties.getFoliageColor() == null) {
vanilla.getEffects().getFoliageColor().ifPresent(effects::foliageColor);
} else {
if(vanillaBiomeProperties.getFoliageColor() != null) {
effects.foliageColor(vanillaBiomeProperties.getFoliageColor());
}
if(vanillaBiomeProperties.getGrassColor() == null) {
vanilla.getEffects().getGrassColor().ifPresent(effects::grassColor);
} else {
if(vanillaBiomeProperties.getGrassColor() != null) {
effects.grassColor(vanillaBiomeProperties.getGrassColor());
}
if(vanillaBiomeProperties.getParticleConfig() == null) {
vanilla.getEffects().getParticleConfig().ifPresent(effects::particleConfig);
} else {
if(vanillaBiomeProperties.getParticleConfig() != null) {
effects.particleConfig(vanillaBiomeProperties.getParticleConfig());
}
if(vanillaBiomeProperties.getLoopSound() == null) {
vanilla.getEffects().getLoopSound().ifPresent(effects::loopSound);
} else {
if(vanillaBiomeProperties.getLoopSound() != null) {
effects.loopSound(vanillaBiomeProperties.getLoopSound());
}
if(vanillaBiomeProperties.getMoodSound() == null) {
vanilla.getEffects().getMoodSound().ifPresent(effects::moodSound);
} else {
if(vanillaBiomeProperties.getMoodSound() != null) {
effects.moodSound(vanillaBiomeProperties.getMoodSound());
}
if(vanillaBiomeProperties.getAdditionsSound() == null) {
vanilla.getEffects().getAdditionsSound().ifPresent(effects::additionsSound);
} else {
if(vanillaBiomeProperties.getAdditionsSound() != null) {
effects.additionsSound(vanillaBiomeProperties.getAdditionsSound());
}
if(vanillaBiomeProperties.getMusic() == null) {
vanilla.getEffects().getMusic().ifPresent(effects::music);
} else {
if(vanillaBiomeProperties.getMusic() != null) {
effects.music(vanillaBiomeProperties.getMusic());
}
builder.precipitation(Objects.requireNonNullElse(vanillaBiomeProperties.getPrecipitation(), vanilla.getPrecipitation()));
builder.precipitation(Objects.requireNonNull(vanillaBiomeProperties.getPrecipitation()));
builder.temperature(Objects.requireNonNullElse(vanillaBiomeProperties.getTemperature(), vanilla.getTemperature()));
builder.temperature(Objects.requireNonNull(vanillaBiomeProperties.getTemperature()));
builder.downfall(Objects.requireNonNullElse(vanillaBiomeProperties.getDownfall(), vanilla.getDownfall()));
builder.downfall(Objects.requireNonNull(vanillaBiomeProperties.getDownfall()));
builder.temperatureModifier(Objects.requireNonNullElse(vanillaBiomeProperties.getTemperatureModifier(),
((BiomeAccessor) ((Object) vanilla)).getWeather().temperatureModifier()));
builder.temperatureModifier(Objects.requireNonNull(vanillaBiomeProperties.getTemperatureModifier()));
builder.spawnSettings(Objects.requireNonNullElse(vanillaBiomeProperties.getSpawnSettings(), vanilla.getSpawnSettings()));
builder.spawnSettings(Objects.requireNonNull(vanillaBiomeProperties.getSpawnSettings()));
return builder
.effects(effects.build())

View File

@@ -14,6 +14,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public final class TagUtil {
@@ -51,48 +52,23 @@ public final class TagUtil {
}
public static void registerBiomeTags(Registry<Biome> registry) {
logger.info("Doing biome tag garbage....");
logger.info("Doing data-driven biome tag garbage....");
logger.info("who let this data drive?");
Map<TagKey<Biome>, List<RegistryEntry<Biome>>> collect = tagsToMutableMap(registry);
MinecraftUtil
.getTerraBiomeMap()
.forEach((vb, terraBiomes) ->
MinecraftUtil
.getEntry(registry, vb)
.ifPresentOrElse(
vanilla -> terraBiomes
.forEach(tb -> MinecraftUtil
.getEntry(registry, tb)
.ifPresentOrElse(
terra -> {
logger.debug(
vanilla.getKey()
.orElseThrow()
.getValue() +
" (vanilla for " +
terra.getKey()
.orElseThrow()
.getValue() +
": " +
vanilla.streamTags()
.toList());
vanilla.streamTags()
.forEach(
tag -> collect
.computeIfAbsent(
tag,
t -> new ArrayList<>())
.add(terra));
},
() -> logger.error(
"No such biome: {}",
tb))),
() -> logger.error("No vanilla biome: {}", vb)));
MinecraftUtil.TERRA_BIOME_TAG_MAP.forEach((tag, biomeList) -> {
collect.getOrDefault(tag, new ArrayList<>())
.addAll(biomeList.stream()
.map(registry::getOrEmpty)
.filter(Optional::isPresent)
.map(Optional::get)
.map(RegistryEntry::of)
.toList());
});
registry.clearTags();
registry.populateTags(ImmutableMap.copyOf(collect));
if(logger.isDebugEnabled()) {
registry.streamEntries()
.map(e -> e.registryKey().getValue() + ": " +

View File

@@ -15,10 +15,10 @@ import java.util.stream.Stream;
import com.dfsek.terra.addon.EphemeralAddon;
import com.dfsek.terra.api.addon.BaseAddon;
import com.dfsek.terra.lifecycle.util.BiomeUtil;
import com.dfsek.terra.mod.CommonPlatform;
import com.dfsek.terra.mod.ModPlatform;
import com.dfsek.terra.mod.generation.MinecraftChunkGeneratorWrapper;
import com.dfsek.terra.mod.util.BiomeUtil;
public abstract class LifecyclePlatform extends ModPlatform {

View File

@@ -1,86 +0,0 @@
package com.dfsek.terra.lifecycle.util;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.BuiltinRegistries;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.village.VillagerType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Map;
import java.util.Objects;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.api.world.biome.Biome;
import com.dfsek.terra.mod.CommonPlatform;
import com.dfsek.terra.mod.config.PreLoadCompatibilityOptions;
import com.dfsek.terra.mod.config.ProtoPlatformBiome;
import com.dfsek.terra.mod.config.VanillaBiomeProperties;
import com.dfsek.terra.mod.mixin.access.VillagerTypeAccessor;
import com.dfsek.terra.mod.util.MinecraftUtil;
public final class BiomeUtil {
private static final Logger logger = LoggerFactory.getLogger(BiomeUtil.class);
private BiomeUtil() {
}
public static void registerBiomes() {
logger.info("Registering biomes...");
CommonPlatform.get().getConfigRegistry().forEach(pack -> { // Register all Terra biomes.
pack.getCheckedRegistry(Biome.class)
.forEach((id, biome) -> registerBiome(biome, pack, id));
});
MinecraftUtil.registerFlora(BuiltinRegistries.BIOME);
logger.info("Terra biomes registered.");
}
/**
* Clones a Vanilla biome and injects Terra data to create a Terra-vanilla biome delegate.
*
* @param biome The Terra BiomeBuilder.
* @param pack The ConfigPack this biome belongs to.
*/
private static void registerBiome(Biome biome, ConfigPack pack,
com.dfsek.terra.api.registry.key.RegistryKey id) {
Registry<net.minecraft.world.biome.Biome> registry = BuiltinRegistries.BIOME;
RegistryKey<net.minecraft.world.biome.Biome> vanilla = ((ProtoPlatformBiome) biome.getPlatformBiome()).get(registry);
if(pack.getContext().get(PreLoadCompatibilityOptions.class).useVanillaBiomes()) {
((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(vanilla);
} else {
VanillaBiomeProperties vanillaBiomeProperties = biome.getContext().get(VanillaBiomeProperties.class);
net.minecraft.world.biome.Biome minecraftBiome = MinecraftUtil.createBiome(biome, registry.get(vanilla),
vanillaBiomeProperties);
Identifier identifier = new Identifier("terra", MinecraftUtil.createBiomeID(pack, id));
if(registry.containsId(identifier)) {
((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(MinecraftUtil.getEntry(registry, identifier)
.orElseThrow()
.getKey()
.orElseThrow());
} else {
((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(BuiltinRegistries.add(registry,
MinecraftUtil.registerKey(identifier)
.getValue(),
minecraftBiome).getKey().orElseThrow());
}
Map villagerMap = VillagerTypeAccessor.getBiomeTypeToIdMap();
villagerMap.put(RegistryKey.of(Registry.BIOME_KEY, identifier),
Objects.requireNonNullElse(vanillaBiomeProperties.getVillagerType(),
villagerMap.getOrDefault(vanilla, VillagerType.PLAINS)));
MinecraftUtil.TERRA_BIOME_MAP.computeIfAbsent(vanilla.getValue(), i -> new ArrayList<>()).add(identifier);
}
}
}

View File

@@ -4,6 +4,7 @@ import net.minecraft.util.registry.BuiltinRegistries;
import com.dfsek.terra.api.event.events.platform.PlatformInitializationEvent;
import com.dfsek.terra.mod.CommonPlatform;
import com.dfsek.terra.mod.util.BiomeUtil;
public final class LifecycleUtil {