apply vanilla biome flower feature supplier to terra biomes

This commit is contained in:
dfsek
2022-05-28 16:39:10 -07:00
parent 278ab648dd
commit 0b6b66b7e6
5 changed files with 76 additions and 28 deletions

View File

@@ -0,0 +1,21 @@
package com.dfsek.terra.fabric.mixin.access;
import net.minecraft.world.biome.GenerationSettings;
import net.minecraft.world.gen.feature.ConfiguredFeature;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.gen.Accessor;
import java.util.List;
import java.util.function.Supplier;
@Mixin(GenerationSettings.class)
public interface GenerationSettingsAccessor {
@Mutable
@Accessor("flowerFeatures")
void setFlowerFeatures(Supplier<List<ConfiguredFeature<?, ?>>> flowerFeatures);
@Accessor("flowerFeatures")
Supplier<List<ConfiguredFeature<?, ?>>> getFlowerFeaturesSupplier();
}

View File

@@ -1,9 +1,11 @@
package com.dfsek.terra.fabric.mixin.lifecycle;
import com.dfsek.terra.fabric.util.BiomeUtil;
import com.dfsek.terra.fabric.util.TagUtil;
import net.minecraft.server.DataPackContents;
import net.minecraft.util.registry.DynamicRegistryManager;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.biome.Biome;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
@@ -17,6 +19,7 @@ public class DataPackContentsMixin {
*/
@Inject(method = "refresh(Lnet/minecraft/util/registry/DynamicRegistryManager;)V", at = @At("RETURN"))
private void injectReload(DynamicRegistryManager dynamicRegistryManager, CallbackInfo ci) {
TagUtil.registerTags(dynamicRegistryManager.get(Registry.BIOME_KEY));
Registry<Biome> biomeRegistry = dynamicRegistryManager.get(Registry.BIOME_KEY);
TagUtil.registerTags(biomeRegistry);
}
}

View File

@@ -5,6 +5,7 @@ import com.dfsek.terra.api.world.biome.Biome;
import com.dfsek.terra.fabric.FabricEntryPoint;
import com.dfsek.terra.fabric.config.PreLoadCompatibilityOptions;
import com.dfsek.terra.fabric.config.VanillaBiomeProperties;
import com.dfsek.terra.fabric.mixin.access.GenerationSettingsAccessor;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.BuiltinRegistries;
@@ -16,12 +17,7 @@ import net.minecraft.world.biome.GenerationSettings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.*;
public final class BiomeUtil {
@@ -136,13 +132,19 @@ public final class BiomeUtil {
builder.precipitation(vanilla.getPrecipitation())
.category(vanilla.getCategory());
}
GenerationSettings settings = generationSettings.build();
((GenerationSettingsAccessor) settings)
.setFlowerFeatures(((GenerationSettingsAccessor) vanilla.getGenerationSettings())
.getFlowerFeaturesSupplier());
return builder
.temperature(vanilla.getTemperature())
.downfall(vanilla.getDownfall())
.effects(effects.build())
.spawnSettings(vanilla.getSpawnSettings())
.generationSettings(generationSettings.build())
.generationSettings(settings)
.build();
}
}

View File

@@ -16,6 +16,7 @@ import java.util.Map;
public final class TagUtil {
private static final Logger logger = LoggerFactory.getLogger(TagUtil.class);
private TagUtil() {
}
@@ -29,26 +30,46 @@ public final class TagUtil {
map.put(pair.getFirst(), new ArrayList<>(pair.getSecond().stream().toList())),
HashMap::putAll);
BiomeUtil.getTerraBiomeMap().forEach((vb, terraBiomes) -> FabricUtil.getEntry(registry, vb)
.ifPresentOrElse(vanilla -> terraBiomes.forEach(tb -> FabricUtil.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(FabricUtil.getEntry(registry,
terra.getKey()
.orElseThrow()
.getValue()).orElseThrow()));
},
() -> logger.error("No such biome: {}", tb))),
() -> logger.error("No vanilla biome: {}", vb)));
BiomeUtil
.getTerraBiomeMap()
.forEach((vb, terraBiomes) ->
FabricUtil.getEntry(registry, vb)
.ifPresentOrElse(vanilla -> terraBiomes
.forEach(tb -> FabricUtil
.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(FabricUtil
.getEntry(
registry,
terra.getKey()
.orElseThrow()
.getValue())
.orElseThrow()));
},
() -> logger.error(
"No such biome: {}",
tb))),
() -> logger.error("No vanilla biome: {}", vb)));
registry.clearTags();
registry.populateTags(ImmutableMap.copyOf(collect));

View File

@@ -4,6 +4,7 @@
"package": "com.dfsek.terra.fabric.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [
"access.GenerationSettingsAccessor",
"access.MobSpawnerLogicAccessor",
"access.StateAccessor",
"access.StructureAccessorAccessor",