mirror of
https://github.com/PaperMC/Paper.git
synced 2025-03-11 01:59:14 +01:00
#978: Add Material#isCompostable and Material#getCompostChance
By: mfnalex <mfnalex@jeff-media.com>
This commit is contained in:
parent
a3fb15bc23
commit
3dcb0dfc9a
2 changed files with 56 additions and 0 deletions
|
@ -5522,6 +5522,37 @@ public enum Material implements Keyed, Translatable {
|
||||||
return Bukkit.getDataPackManager().isEnabledByFeature(asBlockType(), world);
|
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
|
* Tries to convert this Material to an item type
|
||||||
*
|
*
|
||||||
|
|
|
@ -2360,6 +2360,31 @@ public interface ItemType extends Keyed, Translatable {
|
||||||
*/
|
*/
|
||||||
boolean isFuel();
|
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
|
* Determines the remaining item in a crafting grid after crafting with this
|
||||||
* ingredient.
|
* ingredient.
|
||||||
|
|
Loading…
Add table
Reference in a new issue