0
0
mirror of https://github.com/PaperMC/Paper.git synced 2024-11-24 19:56:25 +00:00
Paper/patches/api/0309-Add-hasCollision-methods-to-various-places.patch
2024-10-22 18:23:19 +02:00

87 lines
3.2 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Thu, 4 Nov 2021 11:50:35 -0700
Subject: [PATCH] Add hasCollision methods to various places
diff --git a/src/main/java/org/bukkit/Material.java b/src/main/java/org/bukkit/Material.java
index 3b344a49c26e9f4b3a7ae54ecb90da7c08d0ad49..615eb24ffdd8f6d55ccd4f21760b809c1098bc68 100644
--- a/src/main/java/org/bukkit/Material.java
+++ b/src/main/java/org/bukkit/Material.java
@@ -4906,6 +4906,21 @@ public enum Material implements Keyed, Translatable, net.kyori.adventure.transla
}
// Paper end - item default attributes API
+ // Paper start - isCollidable API
+ /**
+ * Checks if this material is collidable.
+ *
+ * @return true if collidable
+ * @throws IllegalArgumentException if {@link #isBlock()} is false
+ */
+ public boolean isCollidable() {
+ if (this.isBlock()) {
+ return this.asBlockType().hasCollision();
+ }
+ throw new IllegalArgumentException(this + " isn't a block type");
+ }
+ // Paper end - isCollidable API
+
/**
* Do not use for any reason.
*
diff --git a/src/main/java/org/bukkit/block/Block.java b/src/main/java/org/bukkit/block/Block.java
index 9b0a3b4a62387d07143341756b858e15e61a9c03..cfa49e21feec7226e83e97e1053388f854b70337 100644
--- a/src/main/java/org/bukkit/block/Block.java
+++ b/src/main/java/org/bukkit/block/Block.java
@@ -486,6 +486,13 @@ public interface Block extends Metadatable, Translatable, net.kyori.adventure.tr
* @return true if block is solid
*/
boolean isSolid();
+
+ /**
+ * Checks if this block is collidable.
+ *
+ * @return true if collidable
+ */
+ boolean isCollidable();
// Paper end
/**
diff --git a/src/main/java/org/bukkit/block/BlockState.java b/src/main/java/org/bukkit/block/BlockState.java
index f4a739d8022d19a7ae0ee9bf93eb5c4846b4bd40..94e1278340c0d9d2be9edc68f645414380aab353 100644
--- a/src/main/java/org/bukkit/block/BlockState.java
+++ b/src/main/java/org/bukkit/block/BlockState.java
@@ -245,4 +245,13 @@ public interface BlockState extends Metadatable {
* or 'virtual' (e.g. on an itemstack)
*/
boolean isPlaced();
+
+ // Paper start
+ /**
+ * Checks if this block state is collidable.
+ *
+ * @return true if collidable
+ */
+ boolean isCollidable();
+ // Paper end
}
diff --git a/src/main/java/org/bukkit/block/BlockType.java b/src/main/java/org/bukkit/block/BlockType.java
index aebd34785bb2070389ad2e2803fa9ff803b318c5..c080c2a3323d19cb3d549aa0fe6c164666d7da75 100644
--- a/src/main/java/org/bukkit/block/BlockType.java
+++ b/src/main/java/org/bukkit/block/BlockType.java
@@ -3650,4 +3650,13 @@ public interface BlockType extends Keyed, Translatable, net.kyori.adventure.tran
@Override
@NotNull String getTranslationKey();
// Paper end - add Translatable
+
+ // Paper start - hasCollision API
+ /**
+ * Checks if this block type has collision.
+ * <p>
+ * @return false if this block never has collision, true if it <b>might</b> have collision
+ */
+ boolean hasCollision();
+ // Paper end - hasCollision API
}