From 6c32ee4a5ccc139401593fd76cd587f71690cd67 Mon Sep 17 00:00:00 2001 From: Christopher White Date: Wed, 22 Aug 2018 18:13:03 -0700 Subject: [PATCH] Add isChunkGenerated API (#1363) Resolves #1329 --- .../0130-isChunkGenerated-API.patch | 69 +++++++++++++++++++ .../0356-isChunkGenerated-API.patch | 44 ++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 Spigot-API-Patches/0130-isChunkGenerated-API.patch create mode 100644 Spigot-Server-Patches/0356-isChunkGenerated-API.patch diff --git a/Spigot-API-Patches/0130-isChunkGenerated-API.patch b/Spigot-API-Patches/0130-isChunkGenerated-API.patch new file mode 100644 index 000000000..4268e40d9 --- /dev/null +++ b/Spigot-API-Patches/0130-isChunkGenerated-API.patch @@ -0,0 +1,69 @@ +From b036cb38ebab110e948775363f38ffb16c149199 Mon Sep 17 00:00:00 2001 +From: cswhite2000 <18whitechristop@gmail.com> +Date: Tue, 21 Aug 2018 19:39:46 -0700 +Subject: [PATCH] isChunkGenerated API + +Resolves #1329 + +diff --git a/src/main/java/org/bukkit/Location.java b/src/main/java/org/bukkit/Location.java +index 7e1ee875..9457832b 100644 +--- a/src/main/java/org/bukkit/Location.java ++++ b/src/main/java/org/bukkit/Location.java +@@ -9,6 +9,7 @@ import org.bukkit.util.NumberConversions; + import org.bukkit.util.Vector; + + // Paper start ++import com.google.common.base.Preconditions; + import java.util.Collection; + import java.util.function.Predicate; + import org.bukkit.entity.Entity; +@@ -502,6 +503,15 @@ public class Location implements Cloneable, ConfigurationSerializable { + public boolean isChunkLoaded() { return world.isChunkLoaded(locToBlock(x) >> 4, locToBlock(z) >> 4); } // Paper + + // Paper start ++ /** ++ * Checks if a {@link Chunk} has been generated at this location. ++ * ++ * @return true if a chunk has been generated at this location ++ */ ++ public boolean isGenerated() { ++ Preconditions.checkNotNull(world, "Location has no world!"); ++ return world.isChunkGenerated(locToBlock(x) >> 4, locToBlock(z) >> 4); ++ } + + /** + * Sets the position of this Location and returns itself +diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java +index a6facc4b..d5058634 100644 +--- a/src/main/java/org/bukkit/World.java ++++ b/src/main/java/org/bukkit/World.java +@@ -210,6 +210,26 @@ public interface World extends PluginMessageRecipient, Metadatable { + public default Chunk getChunkAt(long chunkKey) { + return getChunkAt((int) chunkKey, (int) (chunkKey >> 32)); + } ++ ++ /** ++ * Checks if a {@link Chunk} has been generated at the specified chunk key, ++ * which is the X and Z packed into a long. ++ * ++ * @param chunkKey The Chunk Key to look up the chunk by ++ * @return true if the chunk has been generated, otherwise false ++ */ ++ public default boolean isChunkGenerated(long chunkKey) { ++ return isChunkGenerated((int) chunkKey, (int) (chunkKey >> 32)); ++ } ++ ++ /** ++ * Checks if a {@link Chunk} has been generated at the given coordinates. ++ * ++ * @param x X-coordinate of the chunk ++ * @param z Z-coordinate of the chunk ++ * @return true if the chunk has been generated, otherwise false ++ */ ++ public boolean isChunkGenerated(int x, int z); + // Paper end + + /** +-- +2.18.0 + diff --git a/Spigot-Server-Patches/0356-isChunkGenerated-API.patch b/Spigot-Server-Patches/0356-isChunkGenerated-API.patch new file mode 100644 index 000000000..2fd75c25a --- /dev/null +++ b/Spigot-Server-Patches/0356-isChunkGenerated-API.patch @@ -0,0 +1,44 @@ +From 2f16be2d68ab57aac9b4568aa113b15f6b0d6af2 Mon Sep 17 00:00:00 2001 +From: cswhite2000 <18whitechristop@gmail.com> +Date: Tue, 21 Aug 2018 19:44:10 -0700 +Subject: [PATCH] isChunkGenerated API + +Resolves #1329 + +diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java +index 0eba3df5..ad548590 100644 +--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java ++++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java +@@ -85,6 +85,12 @@ public class ChunkProviderServer implements IChunkProvider { + + } + ++ // Paper start ++ public boolean isChunkGenerated(int x, int z) { ++ return this.chunks.containsKey(ChunkCoordIntPair.asLong(x, z)) || this.chunkLoader.chunkExists(x, z); ++ } ++ // Paper end ++ + @Nullable + public Chunk getLoadedChunkAt(int i, int j) { + long k = ChunkCoordIntPair.a(i, j); +diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +index 567e9acb..afb141c6 100644 +--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java ++++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +@@ -630,6 +630,12 @@ public class CraftWorld implements World { + return getChunkAt(location.getBlockX() >> 4, location.getBlockZ() >> 4); + } + ++ // Paper start ++ public boolean isChunkGenerated(int x, int z) { ++ return this.getHandle().getChunkProviderServer().isChunkGenerated(x, z); ++ } ++ // Paper end ++ + public ChunkGenerator getGenerator() { + return generator; + } +-- +2.18.0 +