feat: bukkit metapacks and clean up

This commit is contained in:
Zoe Gidiere committed 2026-11-09 19:42:48 -07:00
1 parent dcf38956c4
commit 02c2176222
36 files changed
+1026 -230

No files matched your search

+1
View File
@@ -40,4 +40,5 @@ dependencies {
testImplementation(testFixtures(project(":platforms:minecraft-common")))
testImplementation(project(":common:addons:minecraft-attributes"))
testImplementation("io.papermc.paper", "paper-api", Versions.Bukkit.paper)
testImplementation("com.dfsek.wyck", "Wyck", Versions.Bukkit.wyck)
}
@@ -6,7 +6,7 @@ import ca.solostudios.strata.version.Version;
import com.dfsek.terra.api.addon.BaseAddon;
import com.dfsek.terra.api.event.events.config.pack.ConfigPackPreLoadEvent;
import com.dfsek.terra.api.event.functional.FunctionalEventHandler;
import com.dfsek.terra.bukkit.config.PreLoadCompatibilityOptions;
import com.dfsek.terra.minecraft.config.MinecraftCompatibilityOptions;
public class BukkitAddon implements BaseAddon {
@@ -23,7 +23,7 @@ public class BukkitAddon implements BaseAddon {
terraBukkitPlugin.getEventManager()
.getHandler(FunctionalEventHandler.class)
.register(this, ConfigPackPreLoadEvent.class)
.then(event -> event.getPack().getContext().put(event.loadTemplate(new PreLoadCompatibilityOptions())))
.then(event -> event.getPack().getContext().put(event.loadTemplate(new MinecraftCompatibilityOptions())))
.global();
}
@@ -37,6 +37,7 @@ import java.util.concurrent.CancellationException;
import com.dfsek.terra.AbstractPlatform;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.config.MetaPack;
import com.dfsek.terra.api.handle.ItemHandle;
import com.dfsek.terra.api.handle.WorldHandle;
import com.dfsek.terra.api.world.attribute.AttributeParents;
@@ -121,12 +122,23 @@ public class BukkitPlatform extends AbstractPlatform {
BiomeHandler.addToVanillaTags(this);
Bukkit.getWorlds().forEach(world -> {
if(world.getGenerator() instanceof BukkitChunkGeneratorWrapper wrapper) {
if(!(world.getGenerator() instanceof BukkitChunkGeneratorWrapper wrapper)) return;
MetaPack metaPack = wrapper.getMetaPack();
if(metaPack == null) {
getConfigRegistry().get(wrapper.getPack().getRegistryKey()).ifPresent(pack -> {
wrapper.setPack(pack);
LOGGER.info("Replaced pack in chunk generator for world {}", world);
});
return;
}
getMetaConfigRegistry().get(metaPack.getRegistryKey()).ifPresent(reloaded -> {
try {
wrapper.setMetaPack(reloaded, world);
LOGGER.info("Replaced pack in chunk generator for world {} from metapack {}", world, reloaded.getID());
} catch(IllegalArgumentException e) {
LOGGER.warn("World {} keeps its pack: {}", world.getName(), e.getMessage());
}
});
});
}
@@ -36,6 +36,7 @@ import java.util.Map;
import com.dfsek.terra.api.command.CommandSender;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.api.config.MetaPack;
import com.dfsek.terra.api.event.events.platform.CommandRegistrationEvent;
import com.dfsek.terra.api.event.events.platform.PlatformInitializationEvent;
import com.dfsek.terra.bukkit.attribute.PaperVanilla;
@@ -110,11 +111,14 @@ public class TerraBukkitPlugin extends JavaPlugin {
public @Nullable
ChunkGenerator getDefaultWorldGenerator(@NotNull String worldName, String id) {
if(id == null || id.trim().isEmpty()) { return null; }
return new BukkitChunkGeneratorWrapper(generatorMap.computeIfAbsent(worldName, name -> {
ConfigPack pack = platform.getConfigRegistry().getByID(id).orElseThrow(
() -> new IllegalArgumentException("No such config pack \"" + id + "\""));
return pack.getGeneratorProvider().newInstance(pack);
}), platform.getRawConfigRegistry().getByID(id).orElseThrow(), platform.getWorldHandle().air());
ConfigPack pack = platform.getConfigRegistry().getByID(id).orElse(null);
if(pack == null) {
MetaPack metaPack = platform.getMetaConfigRegistry().getByID(id).orElseThrow(
() -> new IllegalArgumentException("No such config pack or metapack \"" + id + "\""));
return new BukkitChunkGeneratorWrapper(metaPack, platform.getWorldHandle().air());
}
var delegate = generatorMap.computeIfAbsent(worldName, name -> pack.getGeneratorProvider().newInstance(pack));
return new BukkitChunkGeneratorWrapper(delegate, pack, platform.getWorldHandle().air());
}
public GlobalRegionScheduler getGlobalRegionScheduler() {
@@ -222,7 +222,7 @@ public final class PaperDimensions {
* A new type isn't registered while players are online: their clients already hold the registries.
*/
public void onWorldInit(World world, BukkitChunkGeneratorWrapper wrapper) {
ConfigPack pack = wrapper.getPack();
ConfigPack pack = wrapper.bind(world);
String keeps = "Pack \"" + pack.getID() + "\": world \"" + world.getName() + "\" keeps its dimension type";
Built built;
try {
@@ -266,9 +266,7 @@ public final class PaperDimensions {
}
private VanillaContext context() {
VanillaContext context = parents.context();
if(context == null) throw new IllegalStateException("no registry load has begun");
return context;
return parents.requireContext();
}
private PackParents prepare(ConfigPack pack, Optional<PackAttributes> attributes) {
@@ -22,9 +22,14 @@ import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.npc.villager.VillagerType;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.block.state.BlockState;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.block.data.BlockData;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
@@ -82,7 +87,34 @@ public final class PaperVanilla {
}
}
public static BlockState blockState(BlockData data) {
try {
return (BlockState) BlockStates.GET_STATE.invokeExact(data);
} catch(Throwable e) {
throw new IllegalStateException("block data " + data + " has no vanilla state", e);
}
}
public static VanillaContext context(HolderLookup.Provider registries) {
return VanillaContext.of(registries, villagerTypes()::get);
}
/**
* Needs CraftBukkit; resolved on first use.
*/
private static final class BlockStates {
private static final MethodHandle GET_STATE;
static {
try {
Class<?> craft = Class.forName("org.bukkit.craftbukkit.block.data.CraftBlockData", false,
Bukkit.getServer().getClass().getClassLoader());
GET_STATE = MethodHandles.publicLookup()
.findVirtual(craft, "getState", MethodType.methodType(BlockState.class))
.asType(MethodType.methodType(BlockState.class, BlockData.class));
} catch(ReflectiveOperationException e) {
throw new ExceptionInInitializerError(e);
}
}
}
}
@@ -77,6 +77,10 @@ public final class WyckBridge {
LevelStemEditor.create().dimension(Dimension.reference(key(key))).apply(world);
}
public static void installGenerator(World world, net.minecraft.world.level.chunk.ChunkGenerator generator) {
LevelStemEditor.create().chunkGenerator(new MinecraftGenerator(generator)).apply(world);
}
public static void registerBiomes(List<dev.wyck.biome.Biome> biomes) {
BiomeRegistry.registry().register(biomes);
}
@@ -90,4 +94,27 @@ public final class WyckBridge {
private static ResourceKey key(Identifier id) {
return ResourceKey.of(id.getNamespace(), id.getPath());
}
/**
* Wyck installs whatever generator {@link #toMinecraft()} returns.
*/
private record MinecraftGenerator(net.minecraft.world.level.chunk.ChunkGenerator generator)
implements dev.wyck.worldgen.chunk.ChunkGenerator {
@Override
public dev.wyck.worldgen.biome.BiomeSource biomeSource() {
return new MinecraftBiomeSource(generator.getBiomeSource());
}
@Override
public Object toMinecraft() {
return generator;
}
}
private record MinecraftBiomeSource(net.minecraft.world.level.biome.BiomeSource source) implements dev.wyck.worldgen.biome.BiomeSource {
@Override
public Object toMinecraft() {
return source;
}
}
}
@@ -1,60 +0,0 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.bukkit.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;
@SuppressWarnings("FieldMayBeFinal")
public class PreLoadCompatibilityOptions implements ConfigTemplate, Properties {
@Value("minecraft.use-vanilla-biomes")
@Default
private boolean vanillaBiomes = false;
@Value("minecraft.beard.enable")
@Default
private boolean beard = true;
@Value("minecraft.beard.threshold")
@Default
private double beardThreshold = 0.5;
@Value("minecraft.beard.air-threshold")
@Default
private double airThreshold = -0.5;
public boolean useVanillaBiomes() {
return vanillaBiomes;
}
public boolean isBeard() {
return beard;
}
public double getBeardThreshold() {
return beardThreshold;
}
public double getAirThreshold() {
return airThreshold;
}
}
@@ -35,7 +35,7 @@ public class BukkitBiomeProvider extends BiomeProvider implements Handle {
.collect(Collectors.toList());
}
private static org.bukkit.block.Biome toBukkit(Biome biome) {
static org.bukkit.block.Biome toBukkit(Biome biome) {
BukkitPlatformBiome platformBiome = (BukkitPlatformBiome) biome.getPlatformBiome();
return platformBiome.getContext().has(BukkitBiomeInfo.class)
? platformBiome.getContext().get(BukkitBiomeInfo.class).bukkitBiome()
@@ -36,6 +36,7 @@ import java.util.Random;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.api.config.MetaPack;
import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator;
import com.dfsek.terra.api.world.chunk.generation.util.GeneratorWrapper;
import com.dfsek.terra.bukkit.util.BukkitUtils;
@@ -48,8 +49,9 @@ public class BukkitChunkGeneratorWrapper extends org.bukkit.generator.ChunkGener
private final BlockState air;
private final BukkitBlockPopulator blockPopulator;
private volatile @Nullable BukkitBiomeProvider biomeProvider;
private volatile ChunkGenerator delegate;
private volatile ConfigPack pack;
private volatile @Nullable ChunkGenerator delegate;
private volatile @Nullable ConfigPack pack;
private volatile @Nullable MetaPack metaPack;
private volatile boolean mobGeneration = true;
@@ -60,19 +62,38 @@ public class BukkitChunkGeneratorWrapper extends org.bukkit.generator.ChunkGener
this.blockPopulator = new BukkitBlockPopulator(pack, air);
}
public BukkitChunkGeneratorWrapper(MetaPack metaPack, BlockState air) {
this.metaPack = metaPack;
this.air = air;
this.blockPopulator = new BukkitBlockPopulator(null, air);
}
/**
* Picks the world's pack from the metapack on the first call.
*/
public ConfigPack bind(WorldInfo world) {
ConfigPack bound = pack;
if(bound != null) return bound;
synchronized(this) {
if(pack == null) setPack(MetaPackWorlds.packFor(metaPack, world.getEnvironment(), world.getName()));
return pack;
}
}
public void setDelegate(ChunkGenerator delegate) {
this.delegate = delegate;
}
@Override
public @Nullable BiomeProvider getDefaultBiomeProvider(@NotNull WorldInfo worldInfo) {
BukkitBiomeProvider provider = new BukkitBiomeProvider(pack.getBiomeProvider());
BukkitBiomeProvider provider = new BukkitBiomeProvider(bind(worldInfo).getBiomeProvider());
biomeProvider = provider;
return provider;
}
@Override
public void generateNoise(@NotNull WorldInfo worldInfo, @NotNull Random random, int x, int z, @NotNull ChunkData chunkData) {
ConfigPack pack = bind(worldInfo);
BukkitWorldProperties properties = new BukkitWorldProperties(worldInfo);
delegate.generateChunkData(new BukkitProtoChunk(chunkData), properties, pack.getBiomeProvider(), x, z);
}
@@ -80,7 +101,7 @@ public class BukkitChunkGeneratorWrapper extends org.bukkit.generator.ChunkGener
@Override
public int getBaseHeight(@NotNull WorldInfo worldInfo, @NotNull Random random, int x, int z, @NotNull HeightMap heightMap) {
BukkitWorldProperties properties = new BukkitWorldProperties(worldInfo);
com.dfsek.terra.api.world.biome.generation.BiomeProvider biomeProvider = pack.getBiomeProvider();
com.dfsek.terra.api.world.biome.generation.BiomeProvider biomeProvider = bind(worldInfo).getBiomeProvider();
int y = properties.getMaxHeight();
while(y > properties.getMinHeight() &&
!isHeightmapBlock(heightMap, ((BukkitBlockState) delegate.getBlock(properties, x, y - 1, z, biomeProvider)).getHandle())) {
@@ -105,6 +126,7 @@ public class BukkitChunkGeneratorWrapper extends org.bukkit.generator.ChunkGener
@Override
public @NotNull List<BlockPopulator> getDefaultPopulators(@NotNull World world) {
bind(world);
return List.of(blockPopulator);
}
@@ -134,15 +156,27 @@ public class BukkitChunkGeneratorWrapper extends org.bukkit.generator.ChunkGener
}
public ConfigPack getPack() {
return pack;
ConfigPack bound = pack;
if(bound == null) throw new IllegalStateException("Metapack \"" + metaPack.getID() + "\" has no world to pick a pack for yet");
return bound;
}
public @Nullable MetaPack getMetaPack() {
return metaPack;
}
public synchronized void setMetaPack(MetaPack metaPack, World world) {
ConfigPack pack = MetaPackWorlds.packFor(metaPack, world.getEnvironment(), world.getName());
this.metaPack = metaPack;
setPack(pack);
}
public void setPack(ConfigPack pack) {
this.pack = pack;
setDelegate(pack.getGeneratorProvider().newInstance(pack));
BukkitBiomeProvider provider = biomeProvider;
if(provider != null) provider.setDelegate(pack.getBiomeProvider());
blockPopulator.setPack(pack);
this.pack = pack; // last: bind() reads it without locking
}
@Override
@@ -0,0 +1,49 @@
package com.dfsek.terra.bukkit.generator;
import org.bukkit.World;
import org.jetbrains.annotations.Nullable;
import java.util.Map;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.api.config.MetaPack;
/**
* Finds a Bukkit world's pack in a metapack by the level stem for the world's environment.
*/
public final class MetaPackWorlds {
private static final String MINECRAFT = "minecraft:";
private MetaPackWorlds() {
}
public static @Nullable String stem(World.Environment environment) {
return switch(environment) {
case NORMAL -> "minecraft:overworld";
case NETHER -> "minecraft:the_nether";
case THE_END -> "minecraft:the_end";
case CUSTOM -> null;
};
}
public static ConfigPack packFor(MetaPack metaPack, World.Environment environment, String worldName) {
String stem = stem(environment);
if(stem == null) {
throw new IllegalArgumentException(
"Metapack \"" + metaPack.getID() + "\" has no pack for world \"" + worldName + "\": environment " + environment +
" has no level stem");
}
ConfigPack pack = lookup(metaPack.packs(), stem);
if(pack == null) {
throw new IllegalArgumentException(
"Metapack \"" + metaPack.getID() + "\" has no pack for " + stem + " (world \"" + worldName + "\")");
}
return pack;
}
private static @Nullable ConfigPack lookup(Map<String, ConfigPack> packs, String stem) {
ConfigPack pack = packs.get(stem);
return pack != null ? pack : packs.get(stem.substring(MINECRAFT.length()));
}
}
@@ -0,0 +1,100 @@
package com.dfsek.terra.bukkit.generator;
import com.mojang.serialization.MapCodec;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderGetter;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.Identifier;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.BiomeResolver;
import net.minecraft.world.level.biome.BiomeSource;
import net.minecraft.world.level.biome.Climate.Sampler;
import org.bukkit.NamespacedKey;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Stream;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
import com.dfsek.terra.bukkit.world.BukkitPlatformBiome;
/**
* Biomes come straight from the pack's biome provider, with no climate sampling.
*/
public final class PaperBiomeSource extends BiomeSource {
private final BukkitChunkGeneratorWrapper generator;
private final Function<com.dfsek.terra.api.world.biome.Biome, Holder<Biome>> vanilla;
private final long seed;
private volatile Biomes biomes;
public PaperBiomeSource(BukkitChunkGeneratorWrapper generator, Function<com.dfsek.terra.api.world.biome.Biome, Holder<Biome>> vanilla,
long seed) {
this.generator = generator;
this.vanilla = vanilla;
this.seed = seed;
this.biomes = biomes(generator.getPack());
}
public Holder<Biome> biome(int quartX, int quartY, int quartZ) {
Biomes current = current();
com.dfsek.terra.api.world.biome.Biome biome = current.provider.getBiome(quartX << 2, quartY << 2, quartZ << 2, seed);
Holder<Biome> holder = current.holders.get(biome);
return holder != null ? holder : vanilla.apply(biome);
}
@Override
public BiomeResolver createResolver(Sampler sampler) {
return this::biome;
}
@Override
protected Stream<Holder<Biome>> collectPossibleBiomes() {
return current().holders.values().stream().distinct();
}
@Override
protected MapCodec<? extends BiomeSource> codec() {
return MapCodec.assumeMapUnsafe(BiomeSource.CODEC);
}
private Biomes current() {
Biomes current = biomes;
ConfigPack pack = generator.getPack();
if(current.pack == pack) return current;
Biomes reloaded = biomes(pack);
biomes = reloaded;
return reloaded;
}
private Biomes biomes(ConfigPack pack) {
BiomeProvider provider = pack.getBiomeProvider();
Map<com.dfsek.terra.api.world.biome.Biome, Holder<Biome>> holders = new IdentityHashMap<>();
for(com.dfsek.terra.api.world.biome.Biome biome : provider.getBiomes()) holders.put(biome, vanilla.apply(biome));
return new Biomes(pack, provider, holders);
}
public static Function<com.dfsek.terra.api.world.biome.Biome, Holder<Biome>> registered(HolderGetter<Biome> registry) {
return biome -> holder(registry, key(BukkitBiomeProvider.toBukkit(biome).getKey()),
key(((BukkitPlatformBiome) biome.getPlatformBiome()).getHandle().getKey()), biome.getID());
}
/**
* Falls back to the vanilla parent for a biome added by a reload while players were online.
*/
static Holder<Biome> holder(HolderGetter<Biome> registry, ResourceKey<Biome> registered, ResourceKey<Biome> parent, String id) {
return registry.get(registered)
.or(() -> registry.get(parent))
.orElseThrow(() -> new IllegalStateException("Biome " + id + " has no registered vanilla biome"));
}
private static ResourceKey<Biome> key(NamespacedKey key) {
return ResourceKey.create(Registries.BIOME, Identifier.fromNamespaceAndPath(key.getNamespace(), key.getKey()));
}
private record Biomes(ConfigPack pack, BiomeProvider provider, Map<com.dfsek.terra.api.world.biome.Biome, Holder<Biome>> holders) {
}
}
@@ -0,0 +1,118 @@
package com.dfsek.terra.bukkit.generator;
import com.mojang.serialization.MapCodec;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.server.level.WorldGenRegion;
import net.minecraft.world.level.LevelHeightAccessor;
import net.minecraft.world.level.NoiseColumn;
import net.minecraft.world.level.StructureManager;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.BiomeManager;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraft.world.level.levelgen.RandomState;
import net.minecraft.world.level.levelgen.blending.Blender;
import net.minecraft.world.level.levelgen.densityfunction.SamplerContext;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.api.world.info.WorldProperties;
import com.dfsek.terra.bukkit.attribute.PaperVanilla;
import com.dfsek.terra.bukkit.world.block.data.BukkitBlockState;
import com.dfsek.terra.minecraft.config.MinecraftCompatibilityOptions;
import com.dfsek.terra.minecraft.generation.TerraTerrain;
public final class PaperChunkGenerator extends ChunkGenerator {
private final ChunkGenerator paper;
private final BukkitChunkGeneratorWrapper generator;
private final long seed;
public PaperChunkGenerator(ChunkGenerator paper, BukkitChunkGeneratorWrapper generator, PaperBiomeSource biomes, long seed) {
super(biomes);
this.paper = paper;
this.generator = generator;
this.seed = seed;
}
@Override
protected MapCodec<? extends ChunkGenerator> codec() {
return MapCodec.assumeMapUnsafe(ChunkGenerator.CODEC);
}
@Override
public CompletableFuture<ChunkAccess> buildTerrain(ChunkAccess chunk, Blender blender, RandomState randomState,
StructureManager structures, BiomeManager biomeManager, WorldGenRegion region,
Set<Holder<Biome>> biomes) {
return paper.buildTerrain(chunk, blender, randomState, structures, biomeManager, region, biomes)
.thenApply(built -> {
ConfigPack pack = generator.getPack();
TerraTerrain.beard(built, structures, generator.getHandle(), pack.getBiomeProvider(), properties(built),
pack.getContext().get(MinecraftCompatibilityOptions.class), PaperChunkGenerator::vanilla);
return built;
});
}
@Override
public int getBaseHeight(int x, int z, Heightmap.Types heightmap, LevelHeightAccessor height, RandomState randomState) {
return TerraTerrain.baseHeight(generator.getHandle(), generator.getPack().getBiomeProvider(), properties(height), height, x, z,
heightmap.isOpaque(), PaperChunkGenerator::vanilla);
}
@Override
public NoiseColumn getBaseColumn(int x, int z, LevelHeightAccessor height, RandomState randomState) {
return TerraTerrain.baseColumn(generator.getHandle(), generator.getPack().getBiomeProvider(), properties(height), height, x, z,
PaperChunkGenerator::vanilla);
}
private static BlockState vanilla(com.dfsek.terra.api.block.state.BlockState state) {
return PaperVanilla.blockState(((BukkitBlockState) state).getHandle());
}
private WorldProperties properties(LevelHeightAccessor height) {
return new VanillaWorldProperties(seed, height.getMinY(), height.getMinY() + height.getHeight());
}
@Override
public void applyBiomeDecoration(WorldGenLevel level, ChunkAccess chunk, StructureManager structures) {
paper.applyBiomeDecoration(level, chunk, structures);
}
@Override
public void spawnOriginalMobs(WorldGenRegion region) {
paper.spawnOriginalMobs(region);
}
@Override
public int getGenDepth() {
return paper.getGenDepth();
}
@Override
public int getSeaLevel() {
return paper.getSeaLevel();
}
@Override
public int getMinY() {
return paper.getMinY();
}
@Override
public void addDebugScreenInfo(List<String> text, RandomState randomState, BlockPos pos, SamplerContext context) {
}
private record VanillaWorldProperties(long getSeed, int getMinHeight, int getMaxHeight) implements WorldProperties {
@Override
public Object getHandle() {
return this;
}
}
}
@@ -0,0 +1,35 @@
package com.dfsek.terra.bukkit.generator;
import net.minecraft.core.registries.Registries;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.chunk.ChunkGenerator;
import org.bukkit.World;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.dfsek.terra.bukkit.attribute.PaperVanilla;
import com.dfsek.terra.bukkit.attribute.WyckBridge;
public final class PaperGenerators {
private static final Logger LOGGER = LoggerFactory.getLogger(PaperGenerators.class);
private PaperGenerators() {
}
public static void install(World world, BukkitChunkGeneratorWrapper wrapper) {
try {
wrapper.bind(world);
ServerLevel level = PaperVanilla.level(world);
ChunkGenerator paper = level.getChunkSource().getGenerator();
if(paper instanceof PaperChunkGenerator) return;
long seed = level.getSeed();
PaperBiomeSource biomes = new PaperBiomeSource(wrapper,
PaperBiomeSource.registered(level.registryAccess().lookupOrThrow(Registries.BIOME)), seed);
WyckBridge.installGenerator(world, new PaperChunkGenerator(paper, wrapper, biomes, seed));
} catch(RuntimeException e) {
LOGGER.warn("Could not replace Paper's generator in world \"{}\". Falling back to it: no structure beards, slower biome lookups",
world.getName(), e);
}
}
}
@@ -6,6 +6,7 @@ import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull;
import org.mvplugins.multiverse.external.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.stream.Stream;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.registry.key.Keyed;
@@ -26,22 +27,23 @@ public final class MultiverseGeneratorPluginHook implements GeneratorPlugin {
@Override
public @NotNull Collection<String> suggestIds(@Nullable String s) {
return platform.getConfigRegistry().entries().stream()
.map(Keyed::getID)
.toList();
return ids().toList();
}
@Override
public @Nullable Collection<String> getExampleUsages() {
return platform.getConfigRegistry()
.entries()
.stream()
.map(Keyed::getID)
return ids()
.map("/mv create example_world NORMAL -g Terra:%s"::formatted)
.limit(5) // reasonable amount
.toList();
}
private Stream<String> ids() {
return Stream.concat(platform.getConfigRegistry().entries().stream().map(Keyed::getID),
platform.getMetaConfigRegistry().entries().stream().map(Keyed::getID))
.distinct();
}
@Override
public @Nullable String getInfoLink() {
return "https://terra.polydev.org/";
@@ -24,6 +24,7 @@ import org.bukkit.event.world.WorldInitEvent;
import com.dfsek.terra.bukkit.attribute.PaperDimensions;
import com.dfsek.terra.bukkit.generator.BukkitChunkGeneratorWrapper;
import com.dfsek.terra.bukkit.generator.PaperGenerators;
public class DimensionListener implements Listener {
@@ -36,6 +37,8 @@ public class DimensionListener implements Listener {
@EventHandler(priority = EventPriority.LOWEST)
public void onWorldInit(WorldInitEvent event) {
World world = event.getWorld();
if(world.getGenerator() instanceof BukkitChunkGeneratorWrapper wrapper) dimensions.onWorldInit(world, wrapper);
if(!(world.getGenerator() instanceof BukkitChunkGeneratorWrapper wrapper)) return;
dimensions.onWorldInit(world, wrapper);
PaperGenerators.install(world, wrapper);
}
}
@@ -21,12 +21,10 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
@@ -46,6 +44,7 @@ import com.dfsek.terra.minecraft.attribute.BiomeTags.PlatformTagSource;
import com.dfsek.terra.minecraft.attribute.MinecraftAttributeParents;
import com.dfsek.terra.minecraft.attribute.MinecraftBiomeFactory;
import com.dfsek.terra.minecraft.attribute.PackParents;
import com.dfsek.terra.minecraft.attribute.TerraBiomeIndex;
import com.dfsek.terra.minecraft.attribute.VanillaContext;
import com.dfsek.terra.world.attribute.platform.AttributeReport;
import com.dfsek.terra.world.attribute.platform.AttributeSlots;
@@ -53,8 +52,7 @@ import com.dfsek.terra.world.attribute.platform.AttributeSlots;
public final class BiomeHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(BiomeHandler.class);
private static final Map<Identifier, List<Identifier>> BY_PARENT = new HashMap<>();
private static final Map<Identifier, PlatformTagSource> PLATFORM_TAGS = new HashMap<>();
private static TerraBiomeIndex biomes = new TerraBiomeIndex();
private BiomeHandler() { }
@@ -63,8 +61,7 @@ public final class BiomeHandler {
*/
public static synchronized void registerBiomes(BukkitPlatform platform) {
MinecraftAttributeParents parents = platform.attributeParents();
VanillaContext context = parents.context();
if(context == null) throw new IllegalStateException("no registry load has begun");
VanillaContext context = parents.requireContext();
MinecraftBiomeFactory factory = new MinecraftBiomeFactory(platform.getAttributeHandle(), context);
Registry<Biome> registry = PaperVanilla.server().registryAccess().lookupOrThrow(Registries.BIOME);
org.bukkit.Registry<org.bukkit.block.Biome> bukkitRegistry = RegistryAccess.registryAccess().getRegistry(RegistryKey.BIOME);
@@ -86,7 +83,7 @@ public final class BiomeHandler {
platformBiome.setParentEntries(parentEntries(() -> parents.biomeEntries(packParents, parentKey, parent), pack.getID(),
biome.getID(), LOGGER::warn));
Identifier terraId = Identifier.fromNamespaceAndPath("terra", createBiomeID(pack, id));
Identifier terraId = MinecraftBiomeFactory.terraId(pack, id);
packRun.add(terraId, parentKey.identifier(), registry.containsKey(terraId), () -> {
if(playersOnline) {
deferred.incrementAndGet();
@@ -109,16 +106,13 @@ public final class BiomeHandler {
}), LOGGER::warn);
if(deferred.get() > 0) {
LOGGER.info("Players are online, so {} new custom biomes generate as their vanilla biomes until the server restarts.",
LOGGER.info("{} new custom biomes generate as their vanilla parents until the server restarts (players were online during the reload).",
deferred.get());
}
registerNew(run.toRegister, WyckBridge::registerBiomes, LOGGER::info);
Map<ResourceKey<Biome>, ResourceKey<VillagerType>> villagerTypes = PaperVanilla.villagerTypes();
run.villagerTypes.forEach((terraId, type) -> villagerTypes.put(ResourceKey.create(Registries.BIOME, terraId), type));
BY_PARENT.clear();
BY_PARENT.putAll(run.byParent);
PLATFORM_TAGS.clear();
PLATFORM_TAGS.putAll(run.platformTags);
biomes = run.biomes;
run.afterRegistration.forEach(Runnable::run);
}
@@ -166,8 +160,7 @@ public final class BiomeHandler {
private final @Nullable Run<B> before;
final List<B> toRegister = new ArrayList<>();
final Map<Identifier, ResourceKey<VillagerType>> villagerTypes = new LinkedHashMap<>();
final Map<Identifier, List<Identifier>> byParent = new LinkedHashMap<>();
final Map<Identifier, PlatformTagSource> platformTags = new LinkedHashMap<>();
final TerraBiomeIndex biomes = new TerraBiomeIndex();
final List<Runnable> afterRegistration = new ArrayList<>();
Run(@Nullable Run<B> before) {
@@ -177,8 +170,7 @@ public final class BiomeHandler {
void add(Identifier terraId, Identifier parent, boolean registered, Supplier<@Nullable Registration<B>> registration,
PlatformTagSource tags, Runnable after, String pack, String config, Consumer<String> warn) {
if(recorded(terraId)) {
warn.accept("Pack \"" + pack + "\", config \"" + config + "\": biome \"" + terraId
+ "\" shared with another config: their IDs differ only in case");
warn.accept(TerraBiomeIndex.sharedBiome(pack, config, terraId));
afterRegistration.add(after);
return;
}
@@ -188,20 +180,18 @@ public final class BiomeHandler {
toRegister.add(queued.biome());
villagerTypes.put(terraId, queued.villagerType());
}
byParent.computeIfAbsent(parent, i -> new ArrayList<>()).add(terraId);
platformTags.put(terraId, tags);
biomes.record(terraId, parent, tags);
afterRegistration.add(after);
}
private boolean recorded(Identifier terraId) {
return platformTags.containsKey(terraId) || (before != null && before.recorded(terraId));
return biomes.contains(terraId) || (before != null && before.recorded(terraId));
}
private void addAll(Run<B> run) {
toRegister.addAll(run.toRegister);
villagerTypes.putAll(run.villagerTypes);
run.byParent.forEach((parent, biomes) -> byParent.computeIfAbsent(parent, i -> new ArrayList<>()).addAll(biomes));
platformTags.putAll(run.platformTags);
biomes.addAll(run.biomes);
afterRegistration.addAll(run.afterRegistration);
}
}
@@ -230,7 +220,7 @@ public final class BiomeHandler {
Map<TagKey<Biome>, List<Holder<Biome>>> after = new LinkedHashMap<>();
before.forEach((tag, members) -> after.put(tag, new ArrayList<>(members)));
BiomeTags.addTerraBiomes(after, id -> registry.get(id).map(h -> h), BY_PARENT, PLATFORM_TAGS);
BiomeTags.addTerraBiomes(after, id -> registry.get(id).map(h -> h), biomes);
Map<TagKey<Biome>, List<Identifier>> additions = additions(before, after);
int added = appendAll(additions, WyckBridge::appendBiomeTag, "wyck could not append to the tag", LOGGER::warn);
@@ -247,8 +237,7 @@ public final class BiomeHandler {
registrar.getAllTags().forEach((tag, members) -> tags.put(TagKey.create(Registries.BIOME, identifier(tag.key())),
members.stream().map(member -> identifier(member.key())).toList()));
Map<TagKey<Biome>, List<Identifier>> additions = reloadAdditions(tags, id -> registry.get(id).map(h -> h), BY_PARENT,
PLATFORM_TAGS);
Map<TagKey<Biome>, List<Identifier>> additions = reloadAdditions(tags, id -> registry.get(id).map(h -> h), biomes);
int added = appendAll(additions, (tag, biomes) -> registrar.addToTag(
io.papermc.paper.registry.tag.TagKey.create(RegistryKey.BIOME, key(tag.location())),
biomes.stream().map(biome -> TypedKey.create(RegistryKey.BIOME, key(biome))).toList()),
@@ -265,24 +254,23 @@ public final class BiomeHandler {
*/
static Map<TagKey<Biome>, List<Identifier>> reloadAdditions(Map<TagKey<Biome>, List<Identifier>> tags,
Function<Identifier, Optional<Holder<Biome>>> lookup,
Map<Identifier, List<Identifier>> byParent,
Map<Identifier, PlatformTagSource> platformTags) {
TerraBiomeIndex biomes) {
Map<TagKey<Biome>, List<Holder<Biome>>> before = new LinkedHashMap<>();
Map<TagKey<Biome>, List<Holder<Biome>>> after = new LinkedHashMap<>();
tags.forEach((tag, members) -> {
List<Holder<Biome>> old = members.stream().map(lookup).flatMap(Optional::stream).toList();
List<Holder<Biome>> biomes = new ArrayList<>(old);
List<Holder<Biome>> withTerra = new ArrayList<>(old);
for(Identifier member : members) {
for(Identifier terra : byParent.getOrDefault(member, List.of())) {
lookup.apply(terra).ifPresentOrElse(biomes::add,
() -> LOGGER.debug("Terra biome {} is not registered, so it is not added to the reloaded tag {}", terra,
for(Identifier terra : biomes.children(member)) {
lookup.apply(terra).ifPresentOrElse(withTerra::add,
() -> LOGGER.debug("Terra biome {} is not registered; left out of reloaded tag {}", terra,
tag.location()));
}
}
before.put(tag, old);
after.put(tag, biomes);
after.put(tag, withTerra);
});
BiomeTags.addTerraBiomes(after, lookup, Map.of(), platformTags);
BiomeTags.addPlatformTags(after, lookup, biomes.tags());
return additions(before, after);
}
@@ -359,9 +347,4 @@ public final class BiomeHandler {
return appended;
}
public static String createBiomeID(ConfigPack pack, com.dfsek.terra.api.registry.key.RegistryKey biomeID) {
return pack.getID().toLowerCase(Locale.ROOT)
+ "/" + biomeID.getNamespace().toLowerCase(Locale.ROOT)
+ "/" + biomeID.getID().toLowerCase(Locale.ROOT);
}
}
@@ -0,0 +1,83 @@
package com.dfsek.terra.bukkit.generator;
import org.bukkit.World.Environment;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import java.lang.reflect.Proxy;
import java.util.Map;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.api.config.MetaPack;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
class MetaPackWorldsTest {
private static final ConfigPack OVERWORLD = pack("OVERWORLD");
private static final ConfigPack NETHER = pack("NETHER");
@ParameterizedTest
@CsvSource({
"minecraft:overworld, NORMAL",
"overworld, NORMAL",
"minecraft:the_nether, NETHER",
"the_nether, NETHER"
})
void picksThePackForTheWorldsStem(String key, Environment environment) {
assertSame(OVERWORLD, MetaPackWorlds.packFor(metaPack(Map.of(key, OVERWORLD)), environment, "world"));
}
@Test
void namespacedKeyWins() {
MetaPack metaPack = metaPack(Map.of("overworld", NETHER, "minecraft:overworld", OVERWORLD));
assertSame(OVERWORLD, MetaPackWorlds.packFor(metaPack, Environment.NORMAL, "world"));
}
@Test
void missingStemNamesTheMetapackStemAndWorld() {
MetaPack metaPack = metaPack(Map.of("minecraft:overworld", OVERWORLD));
IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
() -> MetaPackWorlds.packFor(metaPack, Environment.THE_END, "world_the_end"));
assertEquals("Metapack \"DEFAULT\" has no pack for minecraft:the_end (world \"world_the_end\")", e.getMessage());
}
@Test
void customEnvironmentHasNoStem() {
MetaPack metaPack = metaPack(Map.of("minecraft:overworld", OVERWORLD));
assertThrows(IllegalArgumentException.class, () -> MetaPackWorlds.packFor(metaPack, Environment.CUSTOM, "custom"));
}
@Test
void unboundWrapperRefusesGetPack() {
BukkitChunkGeneratorWrapper wrapper = new BukkitChunkGeneratorWrapper(metaPack(Map.of()), null);
assertThrows(IllegalStateException.class, wrapper::getPack);
}
private static MetaPack metaPack(Map<String, ConfigPack> packs) {
return (MetaPack) Proxy.newProxyInstance(MetaPack.class.getClassLoader(), new Class<?>[]{ MetaPack.class },
(proxy, method, args) -> switch(method.getName()) {
case "packs" -> packs;
case "getID" -> "DEFAULT";
default -> throw new UnsupportedOperationException(method.getName());
});
}
private static ConfigPack pack(String id) {
return (ConfigPack) Proxy.newProxyInstance(ConfigPack.class.getClassLoader(), new Class<?>[]{ ConfigPack.class },
(proxy, method, args) -> switch(method.getName()) {
case "getID", "toString" -> id;
case "hashCode" -> System.identityHashCode(proxy);
case "equals" -> proxy == args[0];
default -> throw new UnsupportedOperationException(method.getName());
});
}
}
@@ -0,0 +1,118 @@
package com.dfsek.terra.bukkit.generator;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderGetter;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.Identifier;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.Biomes;
import org.junit.jupiter.api.Test;
import java.lang.reflect.Proxy;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
import com.dfsek.terra.api.world.chunk.generation.util.provider.ChunkGeneratorProvider;
import com.dfsek.terra.minecraft.attribute.MinecraftTestSupport;
import com.dfsek.terra.minecraft.attribute.TestBiome;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
class PaperBiomeSourceTest {
private static final HolderGetter<Biome> BIOMES = MinecraftTestSupport.REGISTRIES.lookupOrThrow(Registries.BIOME);
private static final ResourceKey<Biome> UNREGISTERED = ResourceKey.create(Registries.BIOME, Identifier.parse("terra:late"));
private static final TestBiome DESERT = new TestBiome("desert", 0, Biomes.DESERT.identifier());
private static final TestBiome PLAINS = new TestBiome("plains", 1, Biomes.PLAINS.identifier());
private static final Map<com.dfsek.terra.api.world.biome.Biome, ResourceKey<Biome>> KEYS = Map.of(DESERT, Biomes.DESERT, PLAINS,
Biomes.PLAINS);
private final List<List<Integer>> queries = new ArrayList<>();
@Test
void resolvesAtBlockCoordinatesWithoutTheSampler() {
PaperBiomeSource source = source(pack(provider(DESERT)));
Holder<Biome> holder = source.createResolver(null).getNoiseBiome(3, -2, 5);
assertEquals(Biomes.DESERT, key(holder));
assertEquals(List.of(List.of(12, -8, 20)), queries);
}
@Test
void possibleBiomesAreThePacksBiomes() {
PaperBiomeSource source = source(pack(provider(DESERT, DESERT, PLAINS)));
assertEquals(Set.of(Biomes.DESERT, Biomes.PLAINS),
source.possibleBiomes().stream().map(PaperBiomeSourceTest::key).collect(Collectors.toSet()));
}
@Test
void followsAReloadedPack() {
BukkitChunkGeneratorWrapper wrapper = new BukkitChunkGeneratorWrapper(null, pack(provider(DESERT)), null);
PaperBiomeSource source = new PaperBiomeSource(wrapper, biome -> BIOMES.getOrThrow(KEYS.get(biome)), 0);
wrapper.setPack(pack(provider(PLAINS)));
assertEquals(Biomes.PLAINS, key(source.biome(0, 0, 0)));
}
@Test
void registeredBiomeWins() {
assertEquals(Biomes.DESERT, key(PaperBiomeSource.holder(BIOMES, Biomes.DESERT, Biomes.JUNGLE, "desert")));
}
@Test
void unregisteredBiomeFallsBackToItsParent() {
assertEquals(Biomes.JUNGLE, key(PaperBiomeSource.holder(BIOMES, UNREGISTERED, Biomes.JUNGLE, "late")));
}
@Test
void neitherRegisteredFails() {
assertThrows(IllegalStateException.class, () -> PaperBiomeSource.holder(BIOMES, UNREGISTERED, UNREGISTERED, "late"));
}
private PaperBiomeSource source(ConfigPack pack) {
return new PaperBiomeSource(new BukkitChunkGeneratorWrapper(null, pack, null), biome -> BIOMES.getOrThrow(KEYS.get(biome)), 0);
}
private BiomeProvider provider(com.dfsek.terra.api.world.biome.Biome first, com.dfsek.terra.api.world.biome.Biome... rest) {
List<com.dfsek.terra.api.world.biome.Biome> all = new ArrayList<>(List.of(rest));
if(!all.contains(first)) all.addFirst(first);
return new BiomeProvider() {
@Override
public com.dfsek.terra.api.world.biome.Biome getBiome(int x, int y, int z, long seed) {
queries.add(List.of(x, y, z));
return first;
}
@Override
public Iterable<com.dfsek.terra.api.world.biome.Biome> getBiomes() {
return all;
}
};
}
private static ConfigPack pack(BiomeProvider provider) {
ChunkGeneratorProvider generators = pack -> null;
return (ConfigPack) Proxy.newProxyInstance(ConfigPack.class.getClassLoader(), new Class<?>[]{ ConfigPack.class },
(proxy, method, args) -> switch(method.getName()) {
case "getBiomeProvider" -> provider;
case "getGeneratorProvider" -> generators;
case "hashCode" -> System.identityHashCode(proxy);
case "equals" -> proxy == args[0];
default -> throw new UnsupportedOperationException(method.getName());
});
}
private static ResourceKey<Biome> key(Holder<Biome> holder) {
return holder.unwrapKey().orElseThrow();
}
}
@@ -45,6 +45,7 @@ import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.api.registry.key.RegistryKey;
import com.dfsek.terra.minecraft.attribute.BiomeTags.PlatformTagSource;
import com.dfsek.terra.minecraft.attribute.MinecraftBiomeFactory;
import com.dfsek.terra.minecraft.attribute.TerraBiomeIndex;
import com.dfsek.terra.world.attribute.platform.AttributeReport;
import com.dfsek.terra.world.attribute.platform.AttributeSlots;
@@ -188,8 +189,8 @@ class BiomeHandlerTest {
assertEquals(List.of("first/a", "last/a"), run.toRegister);
assertEquals(List.of(Identifier.parse("terra:first/a"), Identifier.parse("terra:last/a")),
List.copyOf(run.villagerTypes.keySet()));
assertEquals(Map.of(PLAINS, List.of(Identifier.parse("terra:first/a"), Identifier.parse("terra:last/a"))), run.byParent);
assertEquals(Set.of(Identifier.parse("terra:first/a"), Identifier.parse("terra:last/a")), run.platformTags.keySet());
assertEquals(Map.of(PLAINS, List.of(Identifier.parse("terra:first/a"), Identifier.parse("terra:last/a"))), run.biomes.byParent());
assertEquals(Set.of(Identifier.parse("terra:first/a"), Identifier.parse("terra:last/a")), run.biomes.tags().keySet());
assertEquals(List.of("first/a", "last/a"), after);
}
@@ -202,7 +203,7 @@ class BiomeHandlerTest {
assertEquals(List.of(), run.toRegister);
assertEquals(Map.of(), run.villagerTypes);
assertEquals(Map.of(PLAINS, List.of(Identifier.parse("terra:test/a"))), run.byParent);
assertEquals(Map.of(PLAINS, List.of(Identifier.parse("terra:test/a"))), run.biomes.byParent());
assertEquals(1, run.afterRegistration.size());
}
@@ -224,12 +225,12 @@ class BiomeHandlerTest {
Identifier snowy = Identifier.parse("terra:test/snowy");
assertEquals(List.of("test/Snowy"), run.toRegister);
assertEquals(Map.of(snowy, VillagerType.SNOW), run.villagerTypes);
assertEquals(Map.of(PLAINS, List.of(snowy)), run.byParent);
assertEquals("Snowy", run.platformTags.get(snowy).config());
assertEquals(Map.of(PLAINS, List.of(snowy)), run.biomes.byParent());
assertEquals("Snowy", run.biomes.tags().get(snowy).config());
assertEquals(List.of("test/Snowy", "test/SNOWY", "TEST/snowy"), after);
assertEquals(List.of(
"Pack \"test\", config \"SNOWY\": biome \"terra:test/snowy\" shared with another config: their IDs differ only in case",
"Pack \"TEST\", config \"snowy\": biome \"terra:test/snowy\" shared with another config: their IDs differ only in case"),
"Pack \"test\", config \"SNOWY\": reusing biome \"terra:test/snowy\"; another config's ID matches apart from case",
"Pack \"TEST\", config \"snowy\": reusing biome \"terra:test/snowy\"; another config's ID matches apart from case"),
warnings);
}
@@ -269,8 +270,10 @@ class BiomeHandlerTest {
RegistryKey.parse("minecraft:is_forest")));
PlatformTagSource source = new PlatformTagSource(new AttributeReport("test", warnings::add, m -> { }), "BIOME", platformTags);
Map<TagKey<Biome>, List<Identifier>> additions = BiomeHandler.reloadAdditions(tags, BiomeHandlerTest::lookup,
Map.of(plains, List.of(terra)), Map.of(terra, source));
TerraBiomeIndex biomes = new TerraBiomeIndex();
biomes.record(terra, plains, source);
Map<TagKey<Biome>, List<Identifier>> additions = BiomeHandler.reloadAdditions(tags, BiomeHandlerTest::lookup, biomes);
assertEquals(List.of(villagePlains, isForest, hasSnow), List.copyOf(additions.keySet()));
assertEquals(List.of(terra), additions.get(villagePlains));
@@ -280,7 +283,6 @@ class BiomeHandlerTest {
Map<TagKey<Biome>, List<Identifier>> reloaded = new LinkedHashMap<>(tags);
additions.forEach((tag, ids) -> reloaded.merge(tag, ids, (old, added) -> Stream.concat(old.stream(), added.stream()).toList()));
assertEquals(Map.of(), BiomeHandler.reloadAdditions(reloaded, BiomeHandlerTest::lookup, Map.of(plains, List.of(terra)),
Map.of(terra, source)));
assertEquals(Map.of(), BiomeHandler.reloadAdditions(reloaded, BiomeHandlerTest::lookup, biomes));
}
}