From 1de93777a54603c074f05779ccb2879ded7b1cd5 Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Thu, 4 Nov 2021 11:50:35 -0700 Subject: [PATCH] Add hasCollision methods to various places --- paper-api/src/main/java/org/bukkit/Material.java | 15 +++++++++++++++ .../src/main/java/org/bukkit/block/Block.java | 7 +++++++ .../main/java/org/bukkit/block/BlockState.java | 9 +++++++++ .../src/main/java/org/bukkit/block/BlockType.java | 9 +++++++++ 4 files changed, 40 insertions(+) diff --git a/paper-api/src/main/java/org/bukkit/Material.java b/paper-api/src/main/java/org/bukkit/Material.java index e8985981de..b28ab97ff8 100644 --- a/paper-api/src/main/java/org/bukkit/Material.java +++ b/paper-api/src/main/java/org/bukkit/Material.java @@ -4877,6 +4877,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/paper-api/src/main/java/org/bukkit/block/Block.java b/paper-api/src/main/java/org/bukkit/block/Block.java index bd50ec2a93..7f9acd155c 100644 --- a/paper-api/src/main/java/org/bukkit/block/Block.java +++ b/paper-api/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/paper-api/src/main/java/org/bukkit/block/BlockState.java b/paper-api/src/main/java/org/bukkit/block/BlockState.java index 555d0492c2..ee4cbbc584 100644 --- a/paper-api/src/main/java/org/bukkit/block/BlockState.java +++ b/paper-api/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/paper-api/src/main/java/org/bukkit/block/BlockType.java b/paper-api/src/main/java/org/bukkit/block/BlockType.java index f0c3343e20..a2376f08c8 100644 --- a/paper-api/src/main/java/org/bukkit/block/BlockType.java +++ b/paper-api/src/main/java/org/bukkit/block/BlockType.java @@ -3625,4 +3625,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. + *

+ * @return false if this block never has collision, true if it might have collision + */ + boolean hasCollision(); + // Paper end - hasCollision API }