mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 10:30:42 +00:00
register normal tag to Terra world presets
This commit is contained in:
@@ -19,6 +19,8 @@ public class DataPackContentsMixin {
|
||||
*/
|
||||
@Inject(method = "refresh(Lnet/minecraft/util/registry/DynamicRegistryManager;)V", at = @At("RETURN"))
|
||||
private void injectReload(DynamicRegistryManager dynamicRegistryManager, CallbackInfo ci) {
|
||||
TagUtil.registerWorldPresetTags(dynamicRegistryManager.get(Registry.WORLD_PRESET_KEY));
|
||||
|
||||
Registry<Biome> biomeRegistry = dynamicRegistryManager.get(Registry.BIOME_KEY);
|
||||
TagUtil.registerBiomeTags(biomeRegistry);
|
||||
BiomeUtil.registerFlora(biomeRegistry);
|
||||
|
||||
@@ -24,6 +24,8 @@ import net.minecraft.world.gen.chunk.NoiseChunkGenerator;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -31,6 +33,7 @@ import java.util.Map;
|
||||
public class LifecycleUtil {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(LifecycleUtil.class);
|
||||
|
||||
private static final List<Identifier> PRESETS = new ArrayList<>();
|
||||
public static void initialize() {
|
||||
FabricEntryPoint.getPlatform().getEventManager().callEvent(
|
||||
new PlatformInitializationEvent());
|
||||
@@ -71,6 +74,8 @@ public class LifecycleUtil {
|
||||
.forEach((id, pack) -> {
|
||||
Identifier generatorID = Identifier.of("terra", pack.getID().toLowerCase(Locale.ROOT) + "/" + pack.getNamespace().toLowerCase(
|
||||
Locale.ROOT));
|
||||
|
||||
PRESETS.add(generatorID);
|
||||
|
||||
TerraBiomeSource biomeSource = new TerraBiomeSource(biomeRegistry, pack);
|
||||
ChunkGenerator generator = new FabricChunkGeneratorWrapper(structureSetRegistry, biomeSource, pack, overworld);
|
||||
@@ -88,4 +93,8 @@ public class LifecycleUtil {
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public static List<Identifier> getPresets() {
|
||||
return PRESETS;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,11 @@ package com.dfsek.terra.fabric.util;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import net.minecraft.tag.TagKey;
|
||||
import net.minecraft.tag.WorldPresetTags;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.registry.RegistryEntry;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.gen.WorldPreset;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -30,43 +32,63 @@ public final class TagUtil {
|
||||
HashMap::putAll);
|
||||
}
|
||||
|
||||
public static void registerWorldPresetTags(Registry<WorldPreset> registry) {
|
||||
logger.info("Doing preset tag garbage....");
|
||||
Map<TagKey<WorldPreset>, List<RegistryEntry<WorldPreset>>> collect = tagsToMutableMap(registry);
|
||||
|
||||
LifecycleUtil
|
||||
.getPresets()
|
||||
.forEach(id -> FabricUtil
|
||||
.getEntry(registry, id)
|
||||
.ifPresentOrElse(
|
||||
preset -> collect
|
||||
.computeIfAbsent(WorldPresetTags.NORMAL, tag -> new ArrayList<>())
|
||||
.add(preset),
|
||||
() -> logger.error("Preset {} does not exist!", id)));
|
||||
|
||||
registry.clearTags();
|
||||
registry.populateTags(ImmutableMap.copyOf(collect));
|
||||
}
|
||||
|
||||
public static void registerBiomeTags(Registry<Biome> registry) {
|
||||
logger.info("Doing tag garbage....");
|
||||
logger.info("Doing biome tag garbage....");
|
||||
Map<TagKey<Biome>, List<RegistryEntry<Biome>>> collect = tagsToMutableMap(registry);
|
||||
|
||||
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(terra));
|
||||
},
|
||||
() -> logger.error(
|
||||
"No such biome: {}",
|
||||
tb))),
|
||||
() -> logger.error("No vanilla biome: {}", vb)));
|
||||
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(terra));
|
||||
},
|
||||
() -> logger.error(
|
||||
"No such biome: {}",
|
||||
tb))),
|
||||
() -> logger.error("No vanilla biome: {}", vb)));
|
||||
|
||||
registry.clearTags();
|
||||
registry.populateTags(ImmutableMap.copyOf(collect));
|
||||
|
||||
Reference in New Issue
Block a user