SPIGOT-7051: Worldgen API does not run vanilla noise generation when shouldGenerateNoise is true

By: DerFrZocker <derrieple@gmail.com>
This commit is contained in:
CraftBukkit/Spigot 2022-06-10 19:08:36 +10:00
parent 766668f0db
commit 46523c1525
2 changed files with 29 additions and 12 deletions

View file

@ -1,18 +1,19 @@
--- a/net/minecraft/server/level/PlayerChunkMap.java
+++ b/net/minecraft/server/level/PlayerChunkMap.java
@@ -102,6 +102,11 @@
@@ -102,6 +102,12 @@
import org.apache.commons.lang3.mutable.MutableObject;
import org.slf4j.Logger;
+// CraftBukkit start
+import net.minecraft.world.level.levelgen.GeneratorSettings;
+import org.bukkit.craftbukkit.generator.CustomChunkGenerator;
+import org.bukkit.entity.Player;
+// CraftBukkit end
+
public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.e {
private static final byte CHUNK_TYPE_REPLACEABLE = -1;
@@ -144,6 +149,27 @@
@@ -144,6 +150,27 @@
private final Queue<Runnable> unloadQueue;
int viewDistance;
@ -40,7 +41,19 @@
public PlayerChunkMap(WorldServer worldserver, Convertable.ConversionSession convertable_conversionsession, DataFixer datafixer, StructureTemplateManager structuretemplatemanager, Executor executor, IAsyncTaskHandler<Runnable> iasynctaskhandler, ILightAccess ilightaccess, ChunkGenerator chunkgenerator, WorldLoadListener worldloadlistener, ChunkStatusUpdateListener chunkstatusupdatelistener, Supplier<WorldPersistentData> supplier, int i, boolean flag) {
super(convertable_conversionsession.getDimensionPath(worldserver.dimension()).resolve("region"), datafixer, flag);
this.visibleChunkMap = this.updatingChunkMap.clone();
@@ -313,9 +339,12 @@
@@ -162,6 +189,11 @@
this.storageName = path.getFileName().toString();
this.level = worldserver;
this.generator = chunkgenerator;
+ // CraftBukkit start - SPIGOT-7051: It's a rigged game! Use delegate for random state creation, otherwise it is not so random.
+ if (chunkgenerator instanceof CustomChunkGenerator) {
+ chunkgenerator = ((CustomChunkGenerator) chunkgenerator).getDelegate();
+ }
+ // CraftBukkit end
if (chunkgenerator instanceof ChunkGeneratorAbstract) {
ChunkGeneratorAbstract chunkgeneratorabstract = (ChunkGeneratorAbstract) chunkgenerator;
@@ -313,9 +345,12 @@
CompletableFuture<List<Either<IChunkAccess, PlayerChunk.Failure>>> completablefuture1 = SystemUtils.sequence(list);
CompletableFuture<Either<List<IChunkAccess>, PlayerChunk.Failure>> completablefuture2 = completablefuture1.thenApply((list2) -> {
List<IChunkAccess> list3 = Lists.newArrayList();
@ -55,7 +68,7 @@
final Either<IChunkAccess, PlayerChunk.Failure> either = (Either) iterator.next();
if (either == null) {
@@ -520,7 +549,7 @@
@@ -520,7 +555,7 @@
private void scheduleUnload(long i, PlayerChunk playerchunk) {
CompletableFuture<IChunkAccess> completablefuture = playerchunk.getChunkToSave();
@ -64,7 +77,7 @@
CompletableFuture<IChunkAccess> completablefuture1 = playerchunk.getChunkToSave();
if (completablefuture1 != completablefuture) {
@@ -609,9 +638,9 @@
@@ -609,9 +644,9 @@
ProtoChunk protochunk = ChunkRegionLoader.read(this.level, this.poiManager, chunkcoordintpair, (NBTTagCompound) optional.get());
this.markPosition(chunkcoordintpair, protochunk.getStatus().getChunkType());
@ -76,7 +89,7 @@
}
}, this.mainThreadExecutor).exceptionallyAsync((throwable) -> {
return this.handleChunkLoadFailure(throwable, chunkcoordintpair);
@@ -717,7 +746,21 @@
@@ -717,7 +752,21 @@
private static void postLoadProtoChunk(WorldServer worldserver, List<NBTTagCompound> list) {
if (!list.isEmpty()) {
@ -99,7 +112,7 @@
}
}
@@ -816,7 +859,7 @@
@@ -816,7 +865,7 @@
if (!playerchunk.wasAccessibleSinceLastSave()) {
return false;
} else {
@ -108,7 +121,7 @@
if (!(ichunkaccess instanceof ProtoChunkExtension) && !(ichunkaccess instanceof Chunk)) {
return false;
@@ -978,7 +1021,8 @@
@@ -978,7 +1027,8 @@
return ichunkaccess instanceof Chunk ? Optional.of((Chunk) ichunkaccess) : Optional.empty();
});
@ -118,7 +131,7 @@
return chunk.getBlockEntities().size();
}).orElse(0), tickingtracker.getTicketDebugString(i), tickingtracker.getLevel(i), optional1.map((chunk) -> {
return chunk.getBlockTicks().count();
@@ -991,7 +1035,7 @@
@@ -991,7 +1041,7 @@
private static String printFuture(CompletableFuture<Either<Chunk, PlayerChunk.Failure>> completablefuture) {
try {
@ -127,7 +140,7 @@
return either != null ? (String) either.map((chunk) -> {
return "done";
@@ -1007,12 +1051,14 @@
@@ -1007,12 +1057,14 @@
private CompletableFuture<Optional<NBTTagCompound>> readChunk(ChunkCoordIntPair chunkcoordintpair) {
return this.read(chunkcoordintpair).thenApplyAsync((optional) -> {
@ -145,7 +158,7 @@
}
boolean anyPlayerCloseEnoughForSpawning(ChunkCoordIntPair chunkcoordintpair) {
@@ -1433,7 +1479,7 @@
@@ -1433,7 +1485,7 @@
public final Set<ServerPlayerConnection> seenBy = Sets.newIdentityHashSet();
public EntityTracker(Entity entity, int i, int j, boolean flag) {
@ -154,7 +167,7 @@
this.entity = entity;
this.range = i;
this.lastSectionPos = SectionPosition.of((EntityAccess) entity);
@@ -1492,6 +1538,11 @@
@@ -1492,6 +1544,11 @@
double d2 = d0 * d0;
boolean flag = d1 <= d2 && this.entity.broadcastToPlayer(entityplayer);

View file

@ -92,6 +92,10 @@ public class CustomChunkGenerator extends InternalChunkGenerator {
this.generator = generator;
}
public net.minecraft.world.level.chunk.ChunkGenerator getDelegate() {
return delegate;
}
private static SeededRandom getSeededRandom() {
return new SeededRandom(new LegacyRandomSource(0));
}