3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-15 04:20:04 +01:00
Paper/patches/api/0176-Add-Heightmap-API.patch
Nassim Jahnke 31699ae9a8
Updated Upstream (Bukkit/CraftBukkit) (#10242)
* Updated Upstream (Bukkit/CraftBukkit)

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:
a6a9d2a4 Remove some old ApiStatus.Experimental annotations
be72314c SPIGOT-7300, PR-829: Add new DamageSource API providing enhanced information about entity damage
b252cf05 SPIGOT-7576, PR-970: Add methods in MushroomCow to change stew effects
b1c689bd PR-902: Add Server#isLoggingIPs to get log-ips configuration
08f86d1c PR-971: Add Player methods for client-side potion effects
2e3024a9 PR-963: Add API for in-world structures
a23292a7 SPIGOT-7530, PR-948: Improve Resource Pack API with new 1.20.3 functionality
1851857b SPIGOT-3071, PR-969: Add entity spawn method with spawn reason
cde4c52a SPIGOT-5553, PR-964: Add EntityKnockbackEvent

CraftBukkit Changes:
38fd4bd50 Fix accidentally renamed internal damage method
80f0ce4be SPIGOT-7300, PR-1180: Add new DamageSource API providing enhanced information about entity damage
7e43f3b16 SPIGOT-7581: Fix typo in BlockMushroom
ea14b7d90 SPIGOT-7576, PR-1347: Add methods in MushroomCow to change stew effects
4c687f243 PR-1259: Add Server#isLoggingIPs to get log-ips configuration
22a541a29 Improve support for per-world game rules
cb7dccce2 PR-1348: Add Player methods for client-side potion effects
b8d6109f0 PR-1335: Add API for in-world structures
4398a1b5b SPIGOT-7577: Make CraftWindCharge#explode discard the entity
e74107678 Fix Crafter maximum stack size
0bb0f4f6a SPIGOT-7530, PR-1314: Improve Resource Pack API with new 1.20.3 functionality
4949f556d SPIGOT-3071, PR-1345: Add entity spawn method with spawn reason
20ac73ca2 PR-1353: Fix Structure#place not working as documented with 0 palette
3c1b77871 SPIGOT-6911, PR-1349: Change max book length in CraftMetaBook
333701839 SPIGOT-7572: Bee nests generated without bees
f48f4174c SPIGOT-5553, PR-1336: Add EntityKnockbackEvent
2024-02-11 22:28:00 +01:00

196 Zeilen
10 KiB
Diff

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
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/HeightmapType.java
@@ -0,0 +1,39 @@
+package com.destroystokyo.paper;
+
+import org.jetbrains.annotations.ApiStatus;
+
+/**
+ * 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)}.
+ */
+@Deprecated(forRemoval = true) @ApiStatus.ScheduledForRemoval(inVersion = "1.21")
+public enum HeightmapType {
+
+ /**
+ * The highest block used for lighting in the world. Also the block returned by {@link org.bukkit.World#getHighestBlockYAt(int, int)}}
+ */
+ 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 f0878c7539696cc0676e6010e88914d3850acf20..c6049747fc286acb4e8053901fcc517e5170afa2 100644
--- a/src/main/java/org/bukkit/Location.java
+++ b/src/main/java/org/bukkit/Location.java
@@ -649,6 +649,46 @@ public class Location implements Cloneable, ConfigurationSerializable, io.paperm
}
// Paper end - expand Location API
+ // 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")
+ 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
+
// Paper start - Expand Explosions API
/**
* 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 bc5dd4182c5dd0a0d576410a68c445e3d006ae18..24ce9966140730c581c0709b14280e62a58331fa 100644
--- a/src/main/java/org/bukkit/World.java
+++ b/src/main/java/org/bukkit/World.java
@@ -153,6 +153,87 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
@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")
+ 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")
+ 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")
+ @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")
+ @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
+
/**
* Gets the highest block corresponding to the {@link HeightMap} at the
* given coordinates.