2021-06-11 14:02:28 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Jake Potrebic <jake.m.potrebic@gmail.com>
|
|
|
|
Date: Tue, 7 Jul 2020 10:53:22 -0700
|
|
|
|
Subject: [PATCH] More World API
|
|
|
|
|
|
|
|
|
|
|
|
diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java
|
Rework async chunk api implementation
Firstly, the old methods all routed to the CompletableFuture method.
However, the CF method could not guarantee that if the caller
was off-main that the future would be "completed" on-main. Since
the callback methods used the CF one, this meant that the callback
methods did not guarantee that the callbacks were to be called on
the main thread.
Now, all methods route to getChunkAtAsync(x, z, gen, urgent, cb)
so that the methods with the callback are guaranteed to invoke
the callback on the main thread. The CF behavior remains unchanged;
it may still appear to complete on main if invoked off-main.
Secondly, remove the scheduleOnMain invocation in the async
chunk completion. This unnecessarily delays the callback
by 1 tick.
Thirdly, add getChunksAtAsync(minX, minZ, maxX, maxZ, ...) which
will load chunks within an area. This method is provided as a helper
as keeping all chunks loaded within an area can be complicated to
implement for plugins (due to the lacking ticket API), and is
already implemented internally anyways.
Fourthly, remove the ticket addition that occured with getChunkAt
and getChunkAtAsync. The ticket addition may delay the unloading
of the chunk unnecessarily. It also fixes a very rare timing bug
where the future/callback would be completed after the chunk
unloads.
2024-11-19 07:34:32 +01:00
|
|
|
index 7ef12976430272d814374ee066e975457111b7f3..b22530070b95667e2b548ef1e68e536a5b8ee138 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/org/bukkit/World.java
|
|
|
|
+++ b/src/main/java/org/bukkit/World.java
|
Rework async chunk api implementation
Firstly, the old methods all routed to the CompletableFuture method.
However, the CF method could not guarantee that if the caller
was off-main that the future would be "completed" on-main. Since
the callback methods used the CF one, this meant that the callback
methods did not guarantee that the callbacks were to be called on
the main thread.
Now, all methods route to getChunkAtAsync(x, z, gen, urgent, cb)
so that the methods with the callback are guaranteed to invoke
the callback on the main thread. The CF behavior remains unchanged;
it may still appear to complete on main if invoked off-main.
Secondly, remove the scheduleOnMain invocation in the async
chunk completion. This unnecessarily delays the callback
by 1 tick.
Thirdly, add getChunksAtAsync(minX, minZ, maxX, maxZ, ...) which
will load chunks within an area. This method is provided as a helper
as keeping all chunks loaded within an area can be complicated to
implement for plugins (due to the lacking ticket API), and is
already implemented internally anyways.
Fourthly, remove the ticket addition that occured with getChunkAt
and getChunkAtAsync. The ticket addition may delay the unloading
of the chunk unnecessarily. It also fixes a very rare timing bug
where the future/callback would be completed after the chunk
unloads.
2024-11-19 07:34:32 +01:00
|
|
|
@@ -3848,6 +3848,72 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
|
2021-06-11 14:02:28 +02:00
|
|
|
@Nullable
|
2022-07-04 16:38:06 +02:00
|
|
|
StructureSearchResult locateNearestStructure(@NotNull Location origin, @NotNull Structure structure, int radius, boolean findUnexplored);
|
2021-06-11 14:02:28 +02:00
|
|
|
|
|
|
|
+ // Paper start
|
|
|
|
+ /**
|
|
|
|
+ * Locates the nearest biome based on an origin, biome type, and radius to search.
|
|
|
|
+ * Step defaults to {@code 8}.
|
|
|
|
+ *
|
|
|
|
+ * @param origin Origin location
|
|
|
|
+ * @param biome Biome to find
|
|
|
|
+ * @param radius radius to search
|
|
|
|
+ * @return Location of biome or null if not found in specified radius
|
2023-10-22 21:12:00 +02:00
|
|
|
+ * @deprecated use {@link #locateNearestBiome(Location, int, Biome...)}
|
2021-06-11 14:02:28 +02:00
|
|
|
+ */
|
2023-10-22 21:12:00 +02:00
|
|
|
+ @Deprecated
|
2021-06-11 14:02:28 +02:00
|
|
|
+ @Nullable
|
2023-10-22 21:12:00 +02:00
|
|
|
+ default Location locateNearestBiome(@NotNull Location origin, @NotNull Biome biome, int radius) {
|
|
|
|
+ return java.util.Optional.ofNullable(this.locateNearestBiome(origin, radius, 8, 8, biome)).map(BiomeSearchResult::getLocation).orElse(null);
|
|
|
|
+ }
|
2021-06-11 14:02:28 +02:00
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Locates the nearest biome based on an origin, biome type, and radius to search
|
|
|
|
+ * and step
|
|
|
|
+ *
|
|
|
|
+ * @param origin Origin location
|
|
|
|
+ * @param biome Biome to find
|
|
|
|
+ * @param radius radius to search
|
|
|
|
+ * @param step Search step 1 would mean checking every block, 8 would be every 8th block
|
|
|
|
+ * @return Location of biome or null if not found in specified radius
|
2023-10-22 21:12:00 +02:00
|
|
|
+ * @deprecated use {@link #locateNearestBiome(Location, int, int, int, Biome...)}
|
2021-06-11 14:02:28 +02:00
|
|
|
+ */
|
2023-10-22 21:12:00 +02:00
|
|
|
+ @Deprecated
|
2021-06-11 14:02:28 +02:00
|
|
|
+ @Nullable
|
2023-10-22 21:12:00 +02:00
|
|
|
+ default Location locateNearestBiome(@NotNull Location origin, @NotNull Biome biome, int radius, int step) {
|
|
|
|
+ return java.util.Optional.ofNullable(this.locateNearestBiome(origin, radius, step, step, biome)).map(BiomeSearchResult::getLocation).orElse(null);
|
|
|
|
+ }
|
2021-06-11 14:02:28 +02:00
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets the coordinate scaling of this world.
|
|
|
|
+ *
|
|
|
|
+ * @return the coordinate scale
|
|
|
|
+ */
|
|
|
|
+ double getCoordinateScale();
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Checks if this world has a fixed time
|
|
|
|
+ *
|
|
|
|
+ * @return whether this world has fixed time
|
|
|
|
+ */
|
|
|
|
+ boolean isFixedTime();
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets the collection of materials that burn infinitely in this world.
|
|
|
|
+ *
|
|
|
|
+ * @return the materials that will forever stay lit by fire
|
|
|
|
+ */
|
|
|
|
+ @NotNull
|
|
|
|
+ Collection<Material> getInfiniburn();
|
2021-08-21 16:26:42 +02:00
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Posts a specified game event at a location
|
|
|
|
+ *
|
|
|
|
+ * @param sourceEntity optional source entity
|
|
|
|
+ * @param gameEvent the game event to post
|
|
|
|
+ * @param position the position in the world where to post the event to listeners
|
|
|
|
+ */
|
|
|
|
+ void sendGameEvent(@Nullable Entity sourceEntity, @NotNull GameEvent gameEvent, @NotNull Vector position);
|
2021-06-11 14:02:28 +02:00
|
|
|
+ // Paper end
|
|
|
|
+
|
|
|
|
// Spigot start
|
2023-12-25 23:51:56 +01:00
|
|
|
@Deprecated(forRemoval = true) // Paper
|
|
|
|
public class Spigot {
|