Paper/patches/api/0175-Add-Heightmap-API.patch

196 lines
10 KiB
Diff
Raw Normal View History

2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Sat, 1 Dec 2018 19:00:36 -0800
Subject: [PATCH] Add Heightmap API
Changed to use upstream's heightmap API - Machine_Maker
diff --git a/src/main/java/com/destroystokyo/paper/HeightmapType.java b/src/main/java/com/destroystokyo/paper/HeightmapType.java
new file mode 100644
index 0000000000000000000000000000000000000000..1c832d69bb3717dcfccf21e45f6f060a64eb4f11
2021-06-11 14:02:28 +02:00
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/HeightmapType.java
@@ -0,0 +1,39 @@
+package com.destroystokyo.paper;
+
+import org.jetbrains.annotations.ApiStatus;
2021-06-11 14:02:28 +02:00
+
+/**
+ * Enumeration of different heightmap types maintained by the server. Generally using these maps is much faster
+ * than using an iterative search for a block in a given x, z coordinate.
+ *
+ * @deprecated Upstream has added their own API for using the game heightmaps. See {@link org.bukkit.HeightMap} and the
+ * non-deprecated getHighestBlock methods on World such as {@link org.bukkit.World#getHighestBlockAt(org.bukkit.Location, org.bukkit.HeightMap)}.
2021-06-11 14:02:28 +02:00
+ */
+@Deprecated(forRemoval = true) @ApiStatus.ScheduledForRemoval(inVersion = "1.21")
2021-06-11 14:02:28 +02:00
+public enum HeightmapType {
+
+ /**
+ * The highest block used for lighting in the world. Also the block returned by {@link org.bukkit.World#getHighestBlockYAt(int, int)}}
2021-06-11 14:02:28 +02:00
+ */
+ LIGHT_BLOCKING,
+
+ /**
+ * References the highest block in the world.
+ */
+ ANY,
+
+ /**
+ * References the highest solid block in a world.
+ */
+ SOLID,
+
+ /**
+ * References the highest solid or liquid block in a world.
+ */
+ SOLID_OR_LIQUID,
+
+ /**
+ * References the highest solid or liquid block in a world, excluding leaves.
+ */
+ SOLID_OR_LIQUID_NO_LEAVES;
+}
diff --git a/src/main/java/org/bukkit/Location.java b/src/main/java/org/bukkit/Location.java
index f7564581c18425c903e54f949728dd3742ca7bf2..1bfe465b9aaeea7d3c871140145b7de1b8f1d93d 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/Location.java
+++ b/src/main/java/org/bukkit/Location.java
@@ -640,6 +640,46 @@ public class Location implements Cloneable, ConfigurationSerializable, io.paperm
2021-06-11 14:02:28 +02:00
return centerLoc;
}
+ // Paper start - Add heightmap api
+ /**
+ * Returns a copy of this location except with y = getWorld().getHighestBlockYAt(this.getBlockX(), this.getBlockZ())
+ * @return A copy of this location except with y = getWorld().getHighestBlockYAt(this.getBlockX(), this.getBlockZ())
+ * @throws NullPointerException if {{@link #getWorld()}} is {@code null}
+ */
+ @NotNull
+ public Location toHighestLocation() {
+ return this.toHighestLocation(HeightMap.WORLD_SURFACE);
+ }
+
+ /**
+ * Returns a copy of this location except with y = getWorld().getHighestBlockYAt(this.getBlockX(), this.getBlockZ(), heightmap)
+ * @param heightmap The heightmap to use for finding the highest y location.
+ * @return A copy of this location except with y = getWorld().getHighestBlockYAt(this.getBlockX(), this.getBlockZ(), heightmap)
+ * @throws NullPointerException if {{@link #getWorld()}} is {@code null}
+ * @throws UnsupportedOperationException if {@link World#getHighestBlockYAt(int, int, com.destroystokyo.paper.HeightmapType)} does not support the specified heightmap
+ * @deprecated Use {@link org.bukkit.Location#toHighestLocation(HeightMap)}
+ */
+ @NotNull
+ @Deprecated(forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.21")
2021-06-11 14:02:28 +02:00
+ public Location toHighestLocation(@NotNull final com.destroystokyo.paper.HeightmapType heightmap) {
+ final Location ret = this.clone();
+ ret.setY(this.getWorld().getHighestBlockYAt(this, heightmap));
+ return ret;
+ }
+
+ /**
+ * Returns a copy of this location except with y = getWorld().getHighestBlockYAt(this.getBlockX(), this.getBlockZ(), heightMap)
+ * @param heightMap The heightmap to use for finding the highest y location.
+ * @return A copy of this location except with y = getWorld().getHighestBlockYAt(this.getBlockX(), this.getBlockZ(), heightMap)
+ */
+ @NotNull
+ public Location toHighestLocation(@NotNull final HeightMap heightMap) {
+ final Location ret = this.clone();
+ ret.setY(this.getWorld().getHighestBlockYAt(this, heightMap));
+ return ret;
+ }
+ // Paper end - Add heightmap api
2021-06-11 14:02:28 +02:00
+
// Paper start - Expand Explosions API
2021-06-11 14:02:28 +02:00
/**
* Creates explosion at this location with given power
diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java
index e673e05c3d94c28d6809a0de7f7d070712b85741..5d3b645eb24f5c0e3309143fc0e53545c6de8083 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
@@ -151,6 +151,87 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
2021-06-11 14:02:28 +02:00
@NotNull
public Block getHighestBlockAt(@NotNull Location location);
+ // Paper start - Add heightmap API
+ /**
+ * Returns the highest block's y-coordinate at the specified block coordinates that match the specified heightmap's conditions.
+ * <p>
+ * <b>implNote:</b> Implementations are recommended to use an iterative search as a fallback before resorting to
+ * throwing an {@code UnsupportedOperationException}.
+ * </p>
+ *
+ * @param x The block's x-coordinate.
+ * @param z The block's z-coordinate.
+ * @param heightmap The specified heightmap to use. See {@link com.destroystokyo.paper.HeightmapType}
+ * @return The highest block's y-coordinate at (x, z) that matches the specified heightmap's conditions.
+ * @throws UnsupportedOperationException If the heightmap type is not supported.
+ * @deprecated Upstream has added support for this, use {@link World#getHighestBlockYAt(int, int, HeightMap)}
+ *
+ * @see com.destroystokyo.paper.HeightmapType
+ */
+ @Deprecated(forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.21")
2021-06-11 14:02:28 +02:00
+ public int getHighestBlockYAt(int x, int z, @NotNull com.destroystokyo.paper.HeightmapType heightmap) throws UnsupportedOperationException;
+
+ /**
+ * Returns the highest block's y-coordinate at the specified block coordinates that match the specified heightmap's conditions.
+ * Note that the y-coordinate of the specified location is ignored.
+ * <p>
+ * <b>implNote:</b> Implementations are recommended to use an iterative search as a fallback before resorting to
+ * throwing an {@code UnsupportedOperationException}.
+ * </p>
+ *
+ * @param location The specified block coordinates.
+ * @param heightmap The specified heightmap to use. See {@link com.destroystokyo.paper.HeightmapType}
+ * @return The highest block's y-coordinate at {@code location} that matches the specified heightmap's conditions.
+ * @throws UnsupportedOperationException If the heightmap type is not supported.
+ * @deprecated Upstream has added support for this, use {@link World#getHighestBlockYAt(Location, HeightMap)}
+ * @see com.destroystokyo.paper.HeightmapType
+ */
+ @Deprecated(forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.21")
2021-06-11 14:02:28 +02:00
+ default int getHighestBlockYAt(@NotNull Location location, @NotNull com.destroystokyo.paper.HeightmapType heightmap) throws UnsupportedOperationException {
+ return this.getHighestBlockYAt(location.getBlockX(), location.getBlockZ(), heightmap);
+ }
+
+ /**
+ * Returns the highest {@link Block} at the specified block coordinates that match the specified heightmap's conditions.
+ * <p>
+ * <b>implNote:</b> Implementations are recommended to use an iterative search as a fallback before resorting to
+ * throwing an {@code UnsupportedOperationException}.
+ * </p>
+ * @param x The block's x-coordinate.
+ * @param z The block's z-coordinate.
+ * @param heightmap The specified heightmap to use. See {@link com.destroystokyo.paper.HeightmapType}
+ * @return The highest {@link Block} at (x, z) that matches the specified heightmap's conditions.
+ * @throws UnsupportedOperationException If the heightmap type is not supported.
+ * @deprecated Upstream has added support for this, use {@link World#getHighestBlockAt(int, int, HeightMap)}
+ * @see com.destroystokyo.paper.HeightmapType
+ */
+ @Deprecated(forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.21")
2021-06-11 14:02:28 +02:00
+ @NotNull
+ default Block getHighestBlockAt(int x, int z, @NotNull com.destroystokyo.paper.HeightmapType heightmap) throws UnsupportedOperationException {
+ return this.getBlockAt(x, this.getHighestBlockYAt(x, z, heightmap), z);
+ }
+
+ /**
+ * Returns the highest {@link Block} at the specified block coordinates that match the specified heightmap's conditions.
+ * Note that the y-coordinate of the specified location is ignored.
+ * <p>
+ * <b>implNote:</b> Implementations are recommended to use an iterative search as a fallback before resorting to
+ * throwing an {@code UnsupportedOperationException}.
+ * </p>
+ * @param location The specified block coordinates.
+ * @param heightmap The specified heightmap to use. See {@link com.destroystokyo.paper.HeightmapType}
+ * @return The highest {@link Block} at {@code location} that matches the specified heightmap's conditions.
+ * @throws UnsupportedOperationException If the heightmap type is not supported.
+ * @deprecated Upstream has added support for this, use {@link World#getHighestBlockAt(Location, HeightMap)}
+ * @see com.destroystokyo.paper.HeightmapType
+ */
+ @Deprecated(forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.21")
2021-06-11 14:02:28 +02:00
+ @NotNull
+ default Block getHighestBlockAt(@NotNull Location location, @NotNull com.destroystokyo.paper.HeightmapType heightmap) throws UnsupportedOperationException {
+ return this.getHighestBlockAt(location.getBlockX(), location.getBlockZ(), heightmap);
+ }
+ // Paper end
+
/**
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#9188) * Updated Upstream (Bukkit/CraftBukkit/Spigot) Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 2fcba9b2 SPIGOT-7347: Add missing documentation and details to ShapedRecipe c278419d PR-854: Move getHighestBlockYAt methods from World to RegionAccessor 201399fb PR-853: Add API for directly setting Display transformation matrices ecfa559a PR-849: Add InventoryView#setTitle 653d7edb SPIGOT-519: Add TNTPrimeEvent 22fccc09 PR-846: Add method to get chunk load level a070a52c PR-844: Add methods to convert Vector to and from JOML vectors cc7111fe PR-276: Add accessors to Wither's invulnerability ticks 777d24e9 SPIGOT-7209: Accessors and events for player's exp cooldown ccb2d01b SPIGOT-6308: Deprecate the location name property of map items cd04a31b PR-780: Add PlayerSpawnChangeEvent 7d1f5b64 SPIGOT-6780: Improve documentation for World#spawnFallingBlock 5696668a SPIGOT-6885: Add test and easier to debug code for reference in yaml configuration comments 2e13cff7 PR-589: Expand the FishHook API 2c7d3da5 PR-279: Minor edits to various Javadocs CraftBukkit Changes: 01b2e1af4 SPIGOT-7346: Disallow players from executing commands after disconnecting 7fe5ee022 PR-1186: Move getHighestBlockYAt methods from World to RegionAccessor bcc85ef67 PR-1185: Add API for directly setting Display transformation matrices a7cfc778f PR-1176: Add InventoryView#setTitle 563d42226 SPIGOT-519: Add TNTPrimeEvent ccbc6abca Add test for Chunk.LoadLevel mirroring 2926e0513 PR-1171: Add method to get chunk load level 63cad7f84 PR-375: Add accessors to Wither's invulnerability ticks bfd8b1ac8 SPIGOT-7209: Accessors and events for player's exp cooldown f92a41c39 PR-1181: Consolidate Location conversion code 10f866759 SPIGOT-6308: Deprecate the location name property of map items 82f7b658a PR-1095: Add PlayerSpawnChangeEvent b421af7e4 PR-808: Expand the FishHook API 598ad7b3f Increase outdated build delay Spigot Changes: d1bd3bd2 Rebuild patches e4265cc8 SPIGOT-7297: Entity Tracking Range option for Display entities * Work around javac bug * Call PlayerSpawnChangeEvent * Updated Upstream (Bukkit/CraftBukkit/Spigot) Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 2fcba9b2 SPIGOT-7347: Add missing documentation and details to ShapedRecipe c278419d PR-854: Move getHighestBlockYAt methods from World to RegionAccessor 201399fb PR-853: Add API for directly setting Display transformation matrices CraftBukkit Changes: 01b2e1af4 SPIGOT-7346: Disallow players from executing commands after disconnecting 7fe5ee022 PR-1186: Move getHighestBlockYAt methods from World to RegionAccessor bcc85ef67 PR-1185: Add API for directly setting Display transformation matrices Spigot Changes: 7da74dae Rebuild patches
2023-05-12 13:10:08 +02:00
* Gets the highest block corresponding to the {@link HeightMap} at the
2021-06-11 14:02:28 +02:00
* given coordinates.