SPIGOT-5877: Add scaffolding for custom dimensions and biomes

This commit is contained in:
Martoph 2021-04-11 17:54:48 +10:00 committed by md_5
parent 170d6febd5
commit 0e26ddb6a3
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11
4 changed files with 12 additions and 4 deletions

View File

@ -954,6 +954,7 @@ public class CraftWorld implements World {
@Override @Override
public void setBiome(int x, int y, int z, Biome bio) { public void setBiome(int x, int y, int z, Biome bio) {
Preconditions.checkArgument(bio != Biome.CUSTOM, "Cannot set the biome to %s", bio);
BiomeBase bb = CraftBlock.biomeToBiomeBase(getHandle().r().b(IRegistry.ay), bio); BiomeBase bb = CraftBlock.biomeToBiomeBase(getHandle().r().b(IRegistry.ay), bio);
BlockPosition pos = new BlockPosition(x, 0, z); BlockPosition pos = new BlockPosition(x, 0, z);
if (this.world.isLoaded(pos)) { if (this.world.isLoaded(pos)) {

View File

@ -499,11 +499,12 @@ public class CraftBlock implements Block {
return null; return null;
} }
return Registry.BIOME.get(CraftNamespacedKey.fromMinecraft(registry.getKey(base))); Biome biome = Registry.BIOME.get(CraftNamespacedKey.fromMinecraft(registry.getKey(base)));
return (biome == null) ? Biome.CUSTOM : biome;
} }
public static BiomeBase biomeToBiomeBase(IRegistry<BiomeBase> registry, Biome bio) { public static BiomeBase biomeToBiomeBase(IRegistry<BiomeBase> registry, Biome bio) {
if (bio == null) { if (bio == null || bio == Biome.CUSTOM) {
return null; return null;
} }

View File

@ -65,6 +65,7 @@ public class CustomChunkGenerator extends InternalChunkGenerator {
@Override @Override
public void setBiome(int x, int y, int z, Biome bio) { public void setBiome(int x, int y, int z, Biome bio) {
Preconditions.checkArgument(bio != Biome.CUSTOM, "Cannot set the biome to %s", bio);
biome.setBiome(x >> 2, y >> 2, z >> 2, CraftBlock.biomeToBiomeBase((IRegistry<BiomeBase>) biome.registry, bio)); biome.setBiome(x >> 2, y >> 2, z >> 2, CraftBlock.biomeToBiomeBase((IRegistry<BiomeBase>) biome.registry, bio));
} }
} }

View File

@ -13,14 +13,19 @@ public class BiomeTest extends AbstractTestingBase {
@Test @Test
public void testBukkitToMinecraft() { public void testBukkitToMinecraft() {
for (Biome biome : Biome.values()) { for (Biome biome : Biome.values()) {
if (biome == Biome.CUSTOM) {
continue;
}
Assert.assertNotNull("No NMS mapping for " + biome, CraftBlock.biomeToBiomeBase(RegistryGeneration.WORLDGEN_BIOME, biome)); Assert.assertNotNull("No NMS mapping for " + biome, CraftBlock.biomeToBiomeBase(RegistryGeneration.WORLDGEN_BIOME, biome));
} }
} }
@Test @Test
public void testMinecraftToBukkit() { public void testMinecraftToBukkit() {
for (Object biome : RegistryGeneration.WORLDGEN_BIOME) { for (BiomeBase biomeBase : RegistryGeneration.WORLDGEN_BIOME) {
Assert.assertNotNull("No Bukkit mapping for " + biome, CraftBlock.biomeBaseToBiome(RegistryGeneration.WORLDGEN_BIOME, (BiomeBase) biome)); Biome biome = CraftBlock.biomeBaseToBiome(RegistryGeneration.WORLDGEN_BIOME, biomeBase);
Assert.assertTrue("No Bukkit mapping for " + biomeBase, biome != null && biome != Biome.CUSTOM);
} }
} }
} }