From b55b3af9e189bbb8b9c30e239ba8a244a8659eba Mon Sep 17 00:00:00 2001 From: willies952002 Date: Mon, 3 Sep 2018 10:05:55 -0400 Subject: [PATCH] Add Force-Loaded Chunk API (#1387) --- .../0145-Add-Force-Loaded-Chunk-API.patch | 55 +++++++++++++++++ ...354-Implement-Force-Loaded-Chunk-API.patch | 59 +++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 Spigot-API-Patches/0145-Add-Force-Loaded-Chunk-API.patch create mode 100644 Spigot-Server-Patches/0354-Implement-Force-Loaded-Chunk-API.patch diff --git a/Spigot-API-Patches/0145-Add-Force-Loaded-Chunk-API.patch b/Spigot-API-Patches/0145-Add-Force-Loaded-Chunk-API.patch new file mode 100644 index 0000000000..9929063f14 --- /dev/null +++ b/Spigot-API-Patches/0145-Add-Force-Loaded-Chunk-API.patch @@ -0,0 +1,55 @@ +From d23e81f76200c6ce73ceff362b0bb061046285fb Mon Sep 17 00:00:00 2001 +From: willies952002 +Date: Wed, 29 Aug 2018 00:37:30 -0400 +Subject: [PATCH] Add Force-Loaded Chunk API + + +diff --git a/src/main/java/org/bukkit/Chunk.java b/src/main/java/org/bukkit/Chunk.java +index dc847340..51bc051f 100644 +--- a/src/main/java/org/bukkit/Chunk.java ++++ b/src/main/java/org/bukkit/Chunk.java +@@ -151,4 +151,20 @@ public interface Chunk { + * @return true if slimes are able to spawn in this chunk + */ + boolean isSlimeChunk(); ++ ++ // Paper start - Force-Loaded Chunk API ++ /** ++ * Checks if the chunk is currently force-loaded ++ * ++ * @return true if the chunk is force-loaded, otherwise false ++ */ ++ boolean isForceLoaded(); ++ ++ /** ++ * Set's whether a chunk is force-loaded or not ++ * ++ * @param force whether or not to force load this chunk ++ */ ++ void setForceLoaded(boolean force); ++ // Paper end + } +diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java +index 53764fae..00b02e36 100644 +--- a/src/main/java/org/bukkit/World.java ++++ b/src/main/java/org/bukkit/World.java +@@ -201,6 +201,16 @@ public interface World extends PluginMessageRecipient, Metadatable { + * @return true if the chunk has been generated, otherwise false + */ + public boolean isChunkGenerated(int x, int z); ++ ++ /** ++ * Checks if a chunk is force-loaded. ++ * Note: This will only return true if the chunk is also generated ++ * ++ * @param x X-coordinate of the chunk ++ * @param z Z-coordinate of the chunk ++ * @return true if the chunk is force-loaded. otherwise false ++ */ ++ public boolean isChunkForceLoaded(int x, int z); + // Paper end + + /** +-- +2.19.0.rc1 + diff --git a/Spigot-Server-Patches/0354-Implement-Force-Loaded-Chunk-API.patch b/Spigot-Server-Patches/0354-Implement-Force-Loaded-Chunk-API.patch new file mode 100644 index 0000000000..08b15d5787 --- /dev/null +++ b/Spigot-Server-Patches/0354-Implement-Force-Loaded-Chunk-API.patch @@ -0,0 +1,59 @@ +From 64a7e90d6fc4c9d64a49ea15cb90268f662086e0 Mon Sep 17 00:00:00 2001 +From: willies952002 +Date: Wed, 29 Aug 2018 00:37:42 -0400 +Subject: [PATCH] Implement Force-Loaded Chunk API + + +diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java +index 49809372d..2b5b0c4df 100644 +--- a/src/main/java/net/minecraft/server/World.java ++++ b/src/main/java/net/minecraft/server/World.java +@@ -3010,6 +3010,7 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc + return forcedchunk != null && forcedchunk.a().contains(ChunkCoordIntPair.a(i, j)); + } + ++ public boolean setForcedChunk(int i, int j, boolean flag) { return b(i, j, flag); } // Paper - OBFHELPER + public boolean b(int i, int j, boolean flag) { + String s = "chunks"; + ForcedChunk forcedchunk = (ForcedChunk) this.a(this.worldProvider.getDimensionManager(), ForcedChunk::new, "chunks"); +diff --git a/src/main/java/org/bukkit/craftbukkit/CraftChunk.java b/src/main/java/org/bukkit/craftbukkit/CraftChunk.java +index 12c6d850d..55394e0c1 100644 +--- a/src/main/java/org/bukkit/craftbukkit/CraftChunk.java ++++ b/src/main/java/org/bukkit/craftbukkit/CraftChunk.java +@@ -289,6 +289,18 @@ public class CraftChunk implements Chunk { + Preconditions.checkArgument(0 <= z && z <= 15, "z out of range (expected 0-15, got %s)", z); + } + ++ // Paper start - Force-Loaded Chunk API ++ @Override ++ public boolean isForceLoaded() { ++ return getHandle().getWorld().isForcedChunk(this.x, this.z); ++ } ++ ++ @Override ++ public void setForceLoaded(boolean force) { ++ getHandle().getWorld().setForcedChunk(this.x, this.z, force); ++ } ++ // Paper end ++ + static { + Arrays.fill(emptySkyLight, (byte) 0xFF); + } +diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +index 1ccf2a760..755d2632f 100644 +--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java ++++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +@@ -609,6 +609,10 @@ public class CraftWorld implements World { + public boolean isChunkGenerated(int x, int z) { + return this.getHandle().getChunkProviderServer().isChunkGenerated(x, z); + } ++ ++ public boolean isChunkForceLoaded(int x, int z) { ++ return this.isChunkGenerated(x, z) && this.getHandle().isForcedChunk(x, z); ++ } + // Paper end + + public ChunkGenerator getGenerator() { +-- +2.19.0.rc1 +