/**
* Expends a use of the given toolType from the furnaceInventory. If the
* furnaceInventory's smelting slot is empty, attempts to retrieve a new
* tool from the given supplyInventory. Returns true if successful.
*
* @param furnaceInventory The furnace from which the tool should be used.
* @param toolType A predicate specifying what tool should be used.
* @param supplyInventory Supply inventory to search in case the furnaceInventory is empty. May be null to not search.
* @return True if a single use was expended for the given tool type.
*/
public static boolean useInFurnace(FurnaceInventory furnaceInventory, Predicate<ItemStack> toolType, Inventory supplyInventory) {
ItemStack tool = furnaceInventory.getSmelting();
if (tool == null || tool.getType() == Material.AIR) {
// Try and find a tool in the chest.
InventoryManager manager = new InventoryManager(supplyInventory);
if (supplyInventory == null || !manager.find(toolType))
return false;
tool = manager.get();
furnaceInventory.setSmelting(tool);
manager.decrement();
tool = furnaceInventory.getSmelting();
} else if (!toolType.apply(tool))
return false;
// Use up durability.
short newDurability = (short) (tool.getDurability() + 1);
if (newDurability >= tool.getType().getMaxDurability()) {
furnaceInventory.setSmelting(null);
} else {
tool.setDurability(newDurability);
}
return true;
}
Tool.java 文件源码
java
阅读 27
收藏 0
点赞 0
评论 0
项目:StarQuestCode
作者:
评论列表
文章目录