mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-08-28 08:25:56 +02:00
55 lines
No EOL
1.8 KiB
Kotlin
55 lines
No EOL
1.8 KiB
Kotlin
package xyz.alexcrea.cuanvil.util
|
|
|
|
import io.delilaheve.CustomAnvil
|
|
import org.bukkit.inventory.ItemStack
|
|
import xyz.alexcrea.cuanvil.config.ConfigHolder
|
|
import xyz.alexcrea.cuanvil.recipe.AnvilCustomRecipe
|
|
import xyz.alexcrea.cuanvil.util.MaterialUtil.isAir
|
|
import kotlin.math.min
|
|
|
|
object CustomRecipeUtil {
|
|
|
|
fun getCustomRecipe (
|
|
leftItem: ItemStack,
|
|
rightItem: ItemStack?) : AnvilCustomRecipe? {
|
|
|
|
val recipeList = ConfigHolder.CUSTOM_RECIPE_HOLDER.recipeManager.recipeByMat[leftItem.type] ?: return null
|
|
|
|
CustomAnvil.verboseLog("Testing " + recipeList.size + " recipe...")
|
|
for (recipe in recipeList) {
|
|
if(recipe.testItem(leftItem, rightItem)){
|
|
return recipe
|
|
}
|
|
}
|
|
|
|
return null
|
|
}
|
|
|
|
fun getCustomRecipeAmount(
|
|
recipe: AnvilCustomRecipe,
|
|
leftItem: ItemStack,
|
|
rightItem: ItemStack?
|
|
): Int{
|
|
return if(recipe.exactCount) {
|
|
if(leftItem.amount != recipe.leftItem!!.amount){
|
|
0
|
|
}else if(!rightItem.isAir && rightItem!!.amount != recipe.rightItem!!.amount){
|
|
0
|
|
}else{
|
|
1
|
|
}
|
|
}
|
|
else {
|
|
// test amount
|
|
val resultItem = recipe.resultItem!! // we know exist as the recipe was returned to us
|
|
val maxResultAmount = resultItem.maxStackSize/resultItem.amount
|
|
val maxLeftAmount = leftItem.amount/recipe.leftItem!!.amount
|
|
val maxRightAmount = if(rightItem.isAir){ maxLeftAmount } else{ rightItem!!.amount/recipe.rightItem!!.amount }
|
|
|
|
CustomAnvil.verboseLog("resultItem: $resultItem, maxResultAmount: $maxResultAmount, maxLeftAmount: $maxLeftAmount, maxRightAmount: $maxRightAmount")
|
|
|
|
min(min(maxResultAmount, maxLeftAmount), maxRightAmount)
|
|
}
|
|
}
|
|
|
|
} |