From d01f8d5706a1d828f40feb0f8fb3c548303b2a00 Mon Sep 17 00:00:00 2001 From: aerulion Date: Wed, 26 Nov 2025 21:03:27 +0100 Subject: [PATCH] Fix ItemType#isEdible to also check for DataComponents#CONSUMABLE This fix only allows items that can actually be eaten by the player. For example, since version 1.21.11, fish buckets have also provided the FOOD component, but they cannot be eaten. --- paper-api/src/main/java/org/bukkit/Material.java | 5 +++-- paper-api/src/main/java/org/bukkit/inventory/ItemType.java | 3 ++- .../java/org/bukkit/craftbukkit/inventory/CraftItemType.java | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/paper-api/src/main/java/org/bukkit/Material.java b/paper-api/src/main/java/org/bukkit/Material.java index 24acfb4f89a1..797d09ec8782 100644 --- a/paper-api/src/main/java/org/bukkit/Material.java +++ b/paper-api/src/main/java/org/bukkit/Material.java @@ -3001,13 +3001,14 @@ public boolean isBlock() { } /** - * Checks if this Material is edible. + * Checks if this Material provides the {@link io.papermc.paper.datacomponent.DataComponentTypes#FOOD} and + * {@link io.papermc.paper.datacomponent.DataComponentTypes#CONSUMABLE} and, thereby, is edible by a player. * * @return true if this Material is edible. */ public boolean isEdible() { ItemType type = asItemType(); - return type == null ? false : type.isEdible(); + return type != null && type.isEdible(); } /** diff --git a/paper-api/src/main/java/org/bukkit/inventory/ItemType.java b/paper-api/src/main/java/org/bukkit/inventory/ItemType.java index 228d11a6d2bb..d1a5e35ccc6e 100644 --- a/paper-api/src/main/java/org/bukkit/inventory/ItemType.java +++ b/paper-api/src/main/java/org/bukkit/inventory/ItemType.java @@ -3189,7 +3189,8 @@ private static M getItemType(@KeyPattern.Value final String short getMaxDurability(); /** - * Checks if this item type is edible. + * Checks if this item type provides the {@link io.papermc.paper.datacomponent.DataComponentTypes#FOOD} and + * {@link io.papermc.paper.datacomponent.DataComponentTypes#CONSUMABLE} and, thereby, is edible by a player. * * @return true if this item type is edible. */ diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemType.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemType.java index c4380d970fb6..ae571d4de2b4 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemType.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemType.java @@ -143,7 +143,7 @@ public short getMaxDurability() { @Override public boolean isEdible() { - return this.getHandle().components().has(DataComponents.FOOD); + return this.getHandle().components().has(DataComponents.FOOD) && this.getHandle().components().has(DataComponents.CONSUMABLE); } @Override