diff --git a/paper-api/src/main/java/org/bukkit/Material.java b/paper-api/src/main/java/org/bukkit/Material.java index da961703ba..471da1c5b7 100644 --- a/paper-api/src/main/java/org/bukkit/Material.java +++ b/paper-api/src/main/java/org/bukkit/Material.java @@ -5522,6 +5522,37 @@ public enum Material implements Keyed, Translatable { return Bukkit.getDataPackManager().isEnabledByFeature(asBlockType(), world); } + /** + * Checks whether this material is compostable (can be inserted into a + * composter). + * + * @return true if this material is compostable + * @see #getCompostChance() + */ + public boolean isCompostable() { + return isItem() && asItemType().isCompostable(); + } + + /** + * Get the chance that this material will successfully compost. The returned + * value is between 0 and 1 (inclusive). + * + * Materials with a compost chance of 1 will always raise the composter's + * level, while materials with a compost chance of 0 will never raise it. + * + * Plugins should check that {@link #isCompostable} returns true before + * calling this method. + * + * @return the chance that this material will successfully compost + * @throws IllegalArgumentException if the material is not compostable + * @see #isCompostable() + */ + public float getCompostChance() { + ItemType type = asItemType(); + Preconditions.checkArgument(type != null, "The Material is not an item!"); + return type.getCompostChance(); + } + /** * Tries to convert this Material to an item type * 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 2dec823442..a1e14d1891 100644 --- a/paper-api/src/main/java/org/bukkit/inventory/ItemType.java +++ b/paper-api/src/main/java/org/bukkit/inventory/ItemType.java @@ -2360,6 +2360,31 @@ public interface ItemType extends Keyed, Translatable { */ boolean isFuel(); + /** + * Checks whether this item type is compostable (can be inserted into a + * composter). + * + * @return true if this item type is compostable + * @see #getCompostChance() + */ + boolean isCompostable(); + + /** + * Get the chance that this item type will successfully compost. The + * returned value is between 0 and 1 (inclusive). + * + * Items with a compost chance of 1 will always raise the composter's level, + * while items with a compost chance of 0 will never raise it. + * + * Plugins should check that {@link #isCompostable} returns true before + * calling this method. + * + * @return the chance that this item type will successfully compost + * @throws IllegalArgumentException if this item type is not compostable + * @see #isCompostable() + */ + float getCompostChance(); + /** * Determines the remaining item in a crafting grid after crafting with this * ingredient.