Skip to content

Commit d9fb602

Browse files
authored
Expose vanilla BiomeProvider from WorldInfo (#7295)
1 parent eb48ada commit d9fb602

File tree

2 files changed

+150
-0
lines changed

2 files changed

+150
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Jason Penilla <11360596+jpenilla@users.noreply.github.com>
3+
Date: Thu, 6 Jan 2022 15:56:16 -0800
4+
Subject: [PATCH] Expose vanilla BiomeProvider from WorldInfo
5+
6+
7+
diff --git a/src/main/java/org/bukkit/generator/WorldInfo.java b/src/main/java/org/bukkit/generator/WorldInfo.java
8+
index 5bf00f46e8f3a80fec2a8a738e4d0d92461cfc92..5067f1371433cccd3287af7f03e152f2c3c1ece3 100644
9+
--- a/src/main/java/org/bukkit/generator/WorldInfo.java
10+
+++ b/src/main/java/org/bukkit/generator/WorldInfo.java
11+
@@ -57,4 +57,13 @@ public interface WorldInfo {
12+
* @return Maximum height of the world
13+
*/
14+
int getMaxHeight();
15+
+
16+
+ // Paper start
17+
+ /**
18+
+ * Get the vanilla {@link BiomeProvider} for this world.
19+
+ *
20+
+ * @return vanilla biome provider
21+
+ */
22+
+ @NotNull BiomeProvider vanillaBiomeProvider();
23+
+ // Paper end
24+
}
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Jason Penilla <11360596+jpenilla@users.noreply.github.com>
3+
Date: Thu, 6 Jan 2022 15:59:06 -0800
4+
Subject: [PATCH] Expose vanilla BiomeProvider from WorldInfo
5+
6+
7+
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
8+
index 481a5dbad82f3f8dd5b1bf8ab207d82ec73d5bbd..c4e8e6af67b57406012612b617a7dcaa6e391d09 100644
9+
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
10+
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
11+
@@ -654,7 +654,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
12+
chunkgenerator = worlddimension.generator();
13+
}
14+
15+
- org.bukkit.generator.WorldInfo worldInfo = new org.bukkit.craftbukkit.generator.CraftWorldInfo(iworlddataserver, worldSession, org.bukkit.World.Environment.getEnvironment(dimension), dimensionmanager);
16+
+ org.bukkit.generator.WorldInfo worldInfo = new org.bukkit.craftbukkit.generator.CraftWorldInfo(iworlddataserver, worldSession, org.bukkit.World.Environment.getEnvironment(dimension), dimensionmanager, chunkgenerator, this.registryAccess().registryOrThrow(net.minecraft.core.Registry.BIOME_REGISTRY)); // Paper
17+
if (biomeProvider == null && gen != null) {
18+
biomeProvider = gen.getDefaultBiomeProvider(worldInfo);
19+
}
20+
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
21+
index ba7023e7ca5d29375ff53c2951892138d155f69f..54e8f0f367645f3aa8af5b1cb69c39c0cec9381f 100644
22+
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
23+
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
24+
@@ -1237,7 +1237,7 @@ public final class CraftServer implements Server {
25+
chunkgenerator = worlddimension.generator();
26+
}
27+
28+
- WorldInfo worldInfo = new CraftWorldInfo(worlddata, worldSession, creator.environment(), dimensionmanager);
29+
+ WorldInfo worldInfo = new CraftWorldInfo(worlddata, worldSession, creator.environment(), dimensionmanager, chunkgenerator, this.getHandle().getServer().registryAccess().registryOrThrow(net.minecraft.core.Registry.BIOME_REGISTRY)); // Paper
30+
if (biomeProvider == null && generator != null) {
31+
biomeProvider = generator.getDefaultBiomeProvider(worldInfo);
32+
}
33+
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
34+
index ac41bc23d2f7e16bbacdc9b33fcf6c0d706fa023..c28f7074a07051ea9aee5dc67dfef9193426a42d 100644
35+
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
36+
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
37+
@@ -202,6 +202,31 @@ public class CraftWorld extends CraftRegionAccessor implements World {
38+
39+
return this.getHandle().clip(new ClipContext(vec3d, vec3d1, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, null)).getType() == HitResult.Type.MISS;
40+
}
41+
+
42+
+ @Override
43+
+ public BiomeProvider vanillaBiomeProvider() {
44+
+ final net.minecraft.world.level.chunk.ChunkGenerator chunkGenerator;
45+
+ if (this.getHandle().chunkSource.getGenerator() instanceof org.bukkit.craftbukkit.generator.CustomChunkGenerator bukkit) {
46+
+ chunkGenerator = bukkit.delegate;
47+
+ } else {
48+
+ chunkGenerator = this.getHandle().chunkSource.getGenerator();
49+
+ }
50+
+ final net.minecraft.core.Registry<net.minecraft.world.level.biome.Biome> biomeRegistry = this.getHandle().registryAccess().registryOrThrow(net.minecraft.core.Registry.BIOME_REGISTRY);
51+
+ final List<Biome> possibleBiomes = chunkGenerator.getBiomeSource().possibleBiomes().stream()
52+
+ .map(biome -> CraftBlock.biomeBaseToBiome(biomeRegistry, biome))
53+
+ .toList();
54+
+ return new BiomeProvider() {
55+
+ @Override
56+
+ public Biome getBiome(final org.bukkit.generator.WorldInfo worldInfo, final int x, final int y, final int z) {
57+
+ return CraftBlock.biomeBaseToBiome(biomeRegistry, chunkGenerator.getNoiseBiome(x >> 2, y >> 2, z >> 2));
58+
+ }
59+
+
60+
+ @Override
61+
+ public List<Biome> getBiomes(final org.bukkit.generator.WorldInfo worldInfo) {
62+
+ return possibleBiomes;
63+
+ }
64+
+ };
65+
+ }
66+
// Paper end
67+
68+
private static final Random rand = new Random();
69+
diff --git a/src/main/java/org/bukkit/craftbukkit/generator/CraftWorldInfo.java b/src/main/java/org/bukkit/craftbukkit/generator/CraftWorldInfo.java
70+
index aeffb30cd91d4b21850059d33070c537bd5cb25e..3918c24dfb6cda4cff18016cca807c2dbc2a9156 100644
71+
--- a/src/main/java/org/bukkit/craftbukkit/generator/CraftWorldInfo.java
72+
+++ b/src/main/java/org/bukkit/craftbukkit/generator/CraftWorldInfo.java
73+
@@ -17,8 +17,17 @@ public class CraftWorldInfo implements WorldInfo {
74+
private final long seed;
75+
private final int minHeight;
76+
private final int maxHeight;
77+
+ // Paper start
78+
+ private final net.minecraft.world.level.chunk.ChunkGenerator vanillaChunkGenerator;
79+
+ private final net.minecraft.core.Registry<net.minecraft.world.level.biome.Biome> biomeRegistry;
80+
81+
public CraftWorldInfo(ServerLevelData worldDataServer, LevelStorageSource.LevelStorageAccess session, World.Environment environment, DimensionType dimensionManager) {
82+
+ this(worldDataServer, session, environment, dimensionManager, null, null);
83+
+ }
84+
+ public CraftWorldInfo(ServerLevelData worldDataServer, LevelStorageSource.LevelStorageAccess session, World.Environment environment, DimensionType dimensionManager, net.minecraft.world.level.chunk.ChunkGenerator chunkGenerator, net.minecraft.core.Registry<net.minecraft.world.level.biome.Biome> biomeRegistry) {
85+
+ this.biomeRegistry = biomeRegistry;
86+
+ this.vanillaChunkGenerator = chunkGenerator;
87+
+ // Paper end
88+
this.name = worldDataServer.getLevelName();
89+
this.uuid = WorldUUID.getUUID(session.levelPath.toFile());
90+
this.environment = environment;
91+
@@ -28,6 +37,10 @@ public class CraftWorldInfo implements WorldInfo {
92+
}
93+
94+
public CraftWorldInfo(String name, UUID uuid, World.Environment environment, long seed, int minHeight, int maxHeight) {
95+
+ // Paper start
96+
+ this.vanillaChunkGenerator = null;
97+
+ this.biomeRegistry = null;
98+
+ // Paper end
99+
this.name = name;
100+
this.uuid = uuid;
101+
this.environment = environment;
102+
@@ -65,4 +78,24 @@ public class CraftWorldInfo implements WorldInfo {
103+
public int getMaxHeight() {
104+
return this.maxHeight;
105+
}
106+
+
107+
+ // Paper start
108+
+ @Override
109+
+ public org.bukkit.generator.BiomeProvider vanillaBiomeProvider() {
110+
+ final java.util.List<org.bukkit.block.Biome> possibleBiomes = CraftWorldInfo.this.vanillaChunkGenerator.getBiomeSource().possibleBiomes().stream()
111+
+ .map(biome -> org.bukkit.craftbukkit.block.CraftBlock.biomeBaseToBiome(CraftWorldInfo.this.biomeRegistry, biome))
112+
+ .toList();
113+
+ return new org.bukkit.generator.BiomeProvider() {
114+
+ @Override
115+
+ public org.bukkit.block.Biome getBiome(final WorldInfo worldInfo, final int x, final int y, final int z) {
116+
+ return org.bukkit.craftbukkit.block.CraftBlock.biomeBaseToBiome(CraftWorldInfo.this.biomeRegistry, CraftWorldInfo.this.vanillaChunkGenerator.getNoiseBiome(x >> 2, y >> 2, z >> 2));
117+
+ }
118+
+
119+
+ @Override
120+
+ public java.util.List<org.bukkit.block.Biome> getBiomes(final org.bukkit.generator.WorldInfo worldInfo) {
121+
+ return possibleBiomes;
122+
+ }
123+
+ };
124+
+ }
125+
+ // Paper end
126+
}

0 commit comments

Comments
 (0)