|
| 1 | +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Nassim Jahnke <jahnke.nassim@gmail.com> |
| 3 | +Date: Mon, 31 Jan 2022 11:21:50 +0100 |
| 4 | +Subject: [PATCH] Implement regenerateChunk |
| 5 | + |
| 6 | +Co-authored-by: Jason Penilla <11360596+jpenilla@users.noreply.github.com> |
| 7 | + |
| 8 | +diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java |
| 9 | +index 5fb475b3ccaa98861e2c817b37cd1740e5bfed8d..f2deb875992ad2d5c9dbcfe9ee7071a773fed684 100644 |
| 10 | +--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java |
| 11 | ++++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java |
| 12 | +@@ -121,6 +121,7 @@ import org.bukkit.util.Vector; |
| 13 | + |
| 14 | + public class CraftWorld extends CraftRegionAccessor implements World { |
| 15 | + public static final int CUSTOM_DIMENSION_OFFSET = 10; |
| 16 | ++ private static final ChunkStatus[] REGEN_CHUNK_STATUSES = {ChunkStatus.BIOMES, ChunkStatus.NOISE, ChunkStatus.SURFACE, ChunkStatus.CARVERS, ChunkStatus.LIQUID_CARVERS, ChunkStatus.FEATURES}; // Paper - implement regenerate chunk method |
| 17 | + |
| 18 | + private final ServerLevel world; |
| 19 | + private WorldBorder worldBorder; |
| 20 | +@@ -435,27 +436,61 @@ public class CraftWorld extends CraftRegionAccessor implements World { |
| 21 | + @Override |
| 22 | + public boolean regenerateChunk(int x, int z) { |
| 23 | + org.spigotmc.AsyncCatcher.catchOp("chunk regenerate"); // Spigot |
| 24 | +- throw new UnsupportedOperationException("Not supported in this Minecraft version! Unless you can fix it, this is not a bug :)"); |
| 25 | +- /* |
| 26 | +- if (!unloadChunk0(x, z, false)) { |
| 27 | +- return false; |
| 28 | +- } |
| 29 | +- |
| 30 | +- final long chunkKey = ChunkCoordIntPair.pair(x, z); |
| 31 | +- world.getChunkProvider().unloadQueue.remove(chunkKey); |
| 32 | ++ // Paper start - implement regenerateChunk method |
| 33 | ++ final ServerLevel serverLevel = this.world; |
| 34 | ++ final net.minecraft.server.level.ServerChunkCache serverChunkCache = serverLevel.getChunkSource(); |
| 35 | ++ final ChunkPos chunkPos = new ChunkPos(x, z); |
| 36 | ++ final net.minecraft.world.level.chunk.LevelChunk levelChunk = serverChunkCache.getChunk(chunkPos.x, chunkPos.z, true); |
| 37 | ++ for (final BlockPos blockPos : BlockPos.betweenClosed(chunkPos.getMinBlockX(), serverLevel.getMinBuildHeight(), chunkPos.getMinBlockZ(), chunkPos.getMaxBlockX(), serverLevel.getMaxBuildHeight() - 1, chunkPos.getMaxBlockZ())) { |
| 38 | ++ levelChunk.removeBlockEntity(blockPos); |
| 39 | ++ serverLevel.setBlock(blockPos, Blocks.AIR.defaultBlockState(), 16); |
| 40 | ++ } |
| 41 | ++ |
| 42 | ++ for (final ChunkStatus chunkStatus : REGEN_CHUNK_STATUSES) { |
| 43 | ++ final List<ChunkAccess> list = new ArrayList<>(); |
| 44 | ++ final int range = Math.max(1, chunkStatus.getRange()); |
| 45 | ++ for (int chunkX = chunkPos.z - range; chunkX <= chunkPos.z + range; chunkX++) { |
| 46 | ++ for (int chunkZ = chunkPos.x - range; chunkZ <= chunkPos.x + range; chunkZ++) { |
| 47 | ++ ChunkAccess chunkAccess = serverChunkCache.getChunk(chunkZ, chunkX, chunkStatus.getParent(), true); |
| 48 | ++ if (chunkAccess instanceof ImposterProtoChunk accessProtoChunk) { |
| 49 | ++ chunkAccess = new ImposterProtoChunk(accessProtoChunk.getWrapped(), true); |
| 50 | ++ } else if (chunkAccess instanceof net.minecraft.world.level.chunk.LevelChunk accessLevelChunk) { |
| 51 | ++ chunkAccess = new ImposterProtoChunk(accessLevelChunk, true); |
| 52 | ++ } |
| 53 | ++ list.add(chunkAccess); |
| 54 | ++ } |
| 55 | ++ } |
| 56 | + |
| 57 | +- net.minecraft.server.Chunk chunk = world.getChunkProvider().generateChunk(x, z); |
| 58 | +- PlayerChunk playerChunk = world.getPlayerChunkMap().getChunk(x, z); |
| 59 | +- if (playerChunk != null) { |
| 60 | +- playerChunk.chunk = chunk; |
| 61 | ++ final com.mojang.datafixers.util.Either<ChunkAccess, ChunkHolder.ChunkLoadingFailure> either = chunkStatus.generate( |
| 62 | ++ Runnable::run, |
| 63 | ++ serverLevel, |
| 64 | ++ serverChunkCache.getGenerator(), |
| 65 | ++ serverLevel.getStructureManager(), |
| 66 | ++ serverChunkCache.getLightEngine(), |
| 67 | ++ chunk -> { |
| 68 | ++ throw new UnsupportedOperationException("Not creating full chunks here"); |
| 69 | ++ }, |
| 70 | ++ list, |
| 71 | ++ true |
| 72 | ++ ).join(); |
| 73 | ++ if (chunkStatus == ChunkStatus.NOISE) { |
| 74 | ++ either.left().ifPresent(chunk -> net.minecraft.world.level.levelgen.Heightmap.primeHeightmaps(chunk, ChunkStatus.POST_FEATURES)); |
| 75 | ++ } |
| 76 | + } |
| 77 | + |
| 78 | +- if (chunk != null) { |
| 79 | +- refreshChunk(x, z); |
| 80 | ++ for (final BlockPos blockPos : BlockPos.betweenClosed(chunkPos.getMinBlockX(), serverLevel.getMinBuildHeight(), chunkPos.getMinBlockZ(), chunkPos.getMaxBlockX(), serverLevel.getMaxBuildHeight() - 1, chunkPos.getMaxBlockZ())) { |
| 81 | ++ serverChunkCache.blockChanged(blockPos); |
| 82 | + } |
| 83 | + |
| 84 | +- return chunk != null; |
| 85 | +- */ |
| 86 | ++ final Set<ChunkPos> chunksToRelight = new HashSet<>(9); |
| 87 | ++ for (int chunkX = chunkPos.x - 1; chunkX <= chunkPos.x + 1 ; chunkX++) { |
| 88 | ++ for (int chunkZ = chunkPos.z - 1; chunkZ <= chunkPos.z + 1 ; chunkZ++) { |
| 89 | ++ chunksToRelight.add(new ChunkPos(chunkX, chunkZ)); |
| 90 | ++ } |
| 91 | ++ } |
| 92 | ++ serverChunkCache.getLightEngine().relight(chunksToRelight, pos -> {}, relit -> {}); |
| 93 | ++ return true; |
| 94 | ++ // Paper end |
| 95 | + } |
| 96 | + |
| 97 | + @Override |
0 commit comments