Skip to content

Commit 079985e

Browse files
committed
Fix CustomChunkGenerator but....
1 parent 1aa96bc commit 079985e

1 file changed

Lines changed: 29 additions & 16 deletions

File tree

‎paper-server/src/main/java/org/bukkit/craftbukkit/generator/CustomChunkGenerator.java‎

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.mojang.serialization.MapCodec;
55
import java.util.List;
66
import java.util.Random;
7+
import java.util.Set;
78
import java.util.concurrent.CompletableFuture;
89
import java.util.function.Function;
910
import net.minecraft.core.BlockPos;
@@ -36,6 +37,7 @@
3637
import net.minecraft.world.level.levelgen.RandomState;
3738
import net.minecraft.world.level.levelgen.WorldgenRandom;
3839
import net.minecraft.world.level.levelgen.blending.Blender;
40+
import net.minecraft.world.level.levelgen.densityfunction.SamplerContext;
3941
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplateManager;
4042
import org.bukkit.block.Biome;
4143
import org.bukkit.craftbukkit.CraftHeightMap;
@@ -44,6 +46,7 @@
4446
import org.bukkit.generator.ChunkGenerator;
4547
import org.bukkit.generator.ChunkGenerator.BiomeGrid;
4648
import org.bukkit.generator.ChunkGenerator.ChunkData;
49+
import org.jspecify.annotations.Nullable;
4750

4851
public class CustomChunkGenerator extends InternalChunkGenerator {
4952

@@ -133,15 +136,16 @@ public void createStructures(RegistryAccess registryAccess, ChunkGeneratorStruct
133136
}
134137
}
135138

136-
@Override
139+
// TODO - snapshot - this was moved into NoiseChunkGenerator so...
137140
public void buildSurface(WorldGenRegion level, StructureManager structureManager, RandomState randomState, ChunkAccess protoChunk) {
138141
WorldgenRandom random = getSeededRandom();
139142
int x = protoChunk.getPos().x();
140143
int z = protoChunk.getPos().z();
141144

142145
random.setSeed(Mth.getSeed(x, "should-surface".hashCode(), z) ^ level.getSeed());
143146
if (this.generator.shouldGenerateSurface(this.world.getWorld(), new RandomSourceWrapper.RandomWrapper(random), x, z)) {
144-
this.delegate.buildSurface(level, structureManager, randomState, protoChunk);
147+
// TODO - snapshot
148+
//this.delegate.buildSurface(level, structureManager, randomState, protoChunk);
145149
}
146150

147151
CraftChunkData chunkData = new CraftChunkData(this.world.getWorld(), protoChunk);
@@ -231,15 +235,16 @@ public void buildSurface(WorldGenRegion level, StructureManager structureManager
231235
}
232236
}
233237

234-
@Override
238+
// TODO - snapshot - this no longer exists?
235239
public void applyCarvers(WorldGenRegion region, long seed, RandomState randomState, BiomeManager biomeManager, StructureManager structureManager, ChunkAccess chunk) {
236240
WorldgenRandom random = getSeededRandom();
237241
int x = chunk.getPos().x();
238242
int z = chunk.getPos().z();
239243

240244
random.setSeed(Mth.getSeed(x, "should-caves".hashCode(), z) ^ region.getSeed());
241245
if (this.generator.shouldGenerateCaves(this.world.getWorld(), new RandomSourceWrapper.RandomWrapper(random), x, z)) {
242-
this.delegate.applyCarvers(region, seed, randomState, biomeManager, structureManager, chunk);
246+
// TODO - snapshot
247+
//this.delegate.applyCarvers(region, seed, randomState, biomeManager, structureManager, chunk);
243248
}
244249

245250
// Minecraft removed the LIQUID_CARVERS stage from world generation, without removing the LIQUID Carving enum.
@@ -252,27 +257,35 @@ public void applyCarvers(WorldGenRegion region, long seed, RandomState randomSta
252257
}
253258

254259
@Override
255-
public CompletableFuture<ChunkAccess> fillFromNoise(Blender blender, RandomState randomState, StructureManager structureManager, ChunkAccess centerChunk) {
260+
public CompletableFuture<ChunkAccess> buildTerrain(
261+
final ChunkAccess chunk,
262+
final Blender blender,
263+
final RandomState randomState,
264+
final StructureManager structureManager,
265+
final BiomeManager biomeManager,
266+
final @Nullable WorldGenRegion carverBiomeRegion,
267+
final Set<Holder<net.minecraft.world.level.biome.Biome>> possibleBiomes
268+
) {
256269
CompletableFuture<ChunkAccess> future = null;
257270
WorldgenRandom random = getSeededRandom();
258-
int x = centerChunk.getPos().x();
259-
int z = centerChunk.getPos().z();
271+
int x = chunk.getPos().x();
272+
int z = chunk.getPos().z();
260273

261274
random.setSeed(Mth.getSeed(x, "should-noise".hashCode(), z) ^ this.world.getSeed());
262275
if (this.generator.shouldGenerateNoise(this.world.getWorld(), new RandomSourceWrapper.RandomWrapper(random), x, z)) {
263-
future = this.delegate.fillFromNoise(blender, randomState, structureManager, centerChunk);
276+
future = this.delegate.buildTerrain(chunk, blender, randomState, structureManager, biomeManager, carverBiomeRegion, possibleBiomes);
264277
}
265278

266-
Function<ChunkAccess, ChunkAccess> work = chunk -> {
267-
CraftChunkData chunkData = new CraftChunkData(this.world.getWorld(), chunk);
279+
Function<ChunkAccess, ChunkAccess> work = chunkAccess -> {
280+
CraftChunkData chunkData = new CraftChunkData(this.world.getWorld(), chunkAccess);
268281
random.setLargeFeatureWithSalt(INITIAL_SEED, x, z, 0);
269282

270283
this.generator.generateNoise(this.world.getWorld(), new RandomSourceWrapper.RandomWrapper(random), x, z, chunkData);
271284
chunkData.breakLink();
272-
return chunk;
285+
return chunkAccess;
273286
};
274287

275-
return future == null ? CompletableFuture.supplyAsync(() -> work.apply(centerChunk), io.papermc.paper.FeatureHooks.getWorldgenExecutor()) : future.thenApply(work); // Paper - chunk system
288+
return future == null ? CompletableFuture.supplyAsync(() -> work.apply(chunk), io.papermc.paper.FeatureHooks.getWorldgenExecutor()) : future.thenApply(work); // Paper - chunk system
276289
}
277290

278291
@Override
@@ -292,8 +305,8 @@ public int getBaseHeight(int x, int z, Heightmap.Types type, LevelHeightAccessor
292305
}
293306

294307
@Override
295-
public WeightedList<MobSpawnSettings.SpawnerData> getMobsAt(Holder<net.minecraft.world.level.biome.Biome> biome, StructureManager structureManager, MobCategory mobCategory, BlockPos pos) {
296-
return this.delegate.getMobsAt(biome, structureManager, mobCategory, pos);
308+
public WeightedList<MobSpawnSettings.SpawnerData> getMobsAt(final Level level, StructureManager structureManager, MobCategory mobCategory, BlockPos pos) {
309+
return this.delegate.getMobsAt(level, structureManager, mobCategory, pos);
297310
}
298311

299312
@Override
@@ -307,8 +320,8 @@ public void applyBiomeDecoration(WorldGenLevel level, ChunkAccess chunk, Structu
307320
}
308321

309322
@Override
310-
public void addDebugScreenInfo(List<String> result, RandomState randomState, BlockPos feetPos) {
311-
this.delegate.addDebugScreenInfo(result, randomState, feetPos);
323+
public void addDebugScreenInfo(List<String> result, RandomState randomState, BlockPos feetPos, SamplerContext samplerContext) {
324+
this.delegate.addDebugScreenInfo(result, randomState, feetPos, samplerContext);
312325
}
313326

314327
@Override

0 commit comments

Comments
 (0)