aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTrollyLoki <[email protected]>2023-11-04 17:32:10 -0400
committerGitHub <[email protected]>2023-11-04 16:32:10 -0500
commit8a3980c60bd09eb1d0d21bfc846181a49c0d74df (patch)
treea58cfa872910340e12b9682939eeccc231a39a26
parent0cdce89d595a2c1c097c9e2a5ff96687977b3b25 (diff)
downloadPaper-8a3980c60bd09eb1d0d21bfc846181a49c0d74df.tar.gz
Paper-8a3980c60bd09eb1d0d21bfc846181a49c0d74df.zip
Add API to get the collision shape of a block before it's placed (#9821)
* Add API to get the collision shape of a block before it's placed * Tweak API documentation * Clarify behavior * Rebase * Rebase
-rw-r--r--patches/api/0443-Add-API-to-get-the-collision-shape-of-a-block-before.patch31
-rw-r--r--patches/server/1041-Add-API-to-get-the-collision-shape-of-a-block-before.patch32
2 files changed, 63 insertions, 0 deletions
diff --git a/patches/api/0443-Add-API-to-get-the-collision-shape-of-a-block-before.patch b/patches/api/0443-Add-API-to-get-the-collision-shape-of-a-block-before.patch
new file mode 100644
index 0000000000..8c93339e29
--- /dev/null
+++ b/patches/api/0443-Add-API-to-get-the-collision-shape-of-a-block-before.patch
@@ -0,0 +1,31 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: TrollyLoki <[email protected]>
+Date: Wed, 11 Oct 2023 00:45:54 -0400
+Subject: [PATCH] Add API to get the collision shape of a block before it's
+ placed
+
+
+diff --git a/src/main/java/org/bukkit/block/data/BlockData.java b/src/main/java/org/bukkit/block/data/BlockData.java
+index 31111cea5ffd018c3c011c1f3b8befbbd33db5e5..66903e0fa65052ede789a163dad723ba05a2cc8c 100644
+--- a/src/main/java/org/bukkit/block/data/BlockData.java
++++ b/src/main/java/org/bukkit/block/data/BlockData.java
+@@ -204,6 +204,19 @@ public interface BlockData extends Cloneable {
+ */
+ boolean isFaceSturdy(@NotNull BlockFace face, @NotNull BlockSupport support);
+
++ // Paper start
++ /**
++ * Calculates the collision shape this block data would have at a particular location.
++ * <p>
++ * This does not take into account any block updates that may occur if the block was to be actually placed in the world.
++ *
++ * @param location the location to calculate the collision shape at
++ *
++ * @return a {@link org.bukkit.util.VoxelShape} representing the collision shape of this block data.
++ */
++ @NotNull org.bukkit.util.VoxelShape getCollisionShape(@NotNull Location location);
++ // Paper end
++
+ /**
+ * Gets the material that a player would use to place this block.
+ * <p>
diff --git a/patches/server/1041-Add-API-to-get-the-collision-shape-of-a-block-before.patch b/patches/server/1041-Add-API-to-get-the-collision-shape-of-a-block-before.patch
new file mode 100644
index 0000000000..1db7a2132f
--- /dev/null
+++ b/patches/server/1041-Add-API-to-get-the-collision-shape-of-a-block-before.patch
@@ -0,0 +1,32 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: TrollyLoki <[email protected]>
+Date: Wed, 11 Oct 2023 00:45:53 -0400
+Subject: [PATCH] Add API to get the collision shape of a block before it's
+ placed
+
+
+diff --git a/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java b/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java
+index 0bf863f597f3657a0f158756a2a91bda7eb453f6..2a9dba6d4a94f1488ef9d86ee4f60b7fd06419fb 100644
+--- a/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java
++++ b/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java
+@@ -669,6 +669,20 @@ public class CraftBlockData implements BlockData {
+ return this.state.isFaceSturdy(EmptyBlockGetter.INSTANCE, BlockPos.ZERO, CraftBlock.blockFaceToNotch(face), CraftBlockSupport.toNMS(support));
+ }
+
++ // Paper start
++ @Override
++ public org.bukkit.util.VoxelShape getCollisionShape(Location location) {
++ Preconditions.checkArgument(location != null, "location must not be null");
++
++ CraftWorld world = (CraftWorld) location.getWorld();
++ Preconditions.checkArgument(world != null, "location must not have a null world");
++
++ BlockPos position = CraftLocation.toBlockPosition(location);
++ net.minecraft.world.phys.shapes.VoxelShape shape = this.state.getCollisionShape(world.getHandle(), position);
++ return new org.bukkit.craftbukkit.util.CraftVoxelShape(shape);
++ }
++ // Paper end
++
+ @Override
+ public Material getPlacementMaterial() {
+ return CraftMagicNumbers.getMaterial(this.state.getBlock().asItem());