From b9fe54e883b4944becd0ec87bb038b966734b03e Mon Sep 17 00:00:00 2001 From: Auxilor Date: Tue, 1 Mar 2022 10:49:09 +0000 Subject: [PATCH] This isn't going to be the last commit, is it --- .../spigot/recipes/StackedRecipeListener.kt | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/recipes/StackedRecipeListener.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/recipes/StackedRecipeListener.kt index 98ae3e8f..f043ab59 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/recipes/StackedRecipeListener.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/recipes/StackedRecipeListener.kt @@ -2,6 +2,7 @@ package com.willfp.eco.internal.spigot.recipes import com.willfp.eco.core.EcoPlugin import com.willfp.eco.core.recipe.Recipes +import com.willfp.eco.core.recipe.parts.EmptyTestableItem import com.willfp.eco.core.recipe.parts.GroupedTestableItems import com.willfp.eco.core.recipe.parts.TestableStack import org.bukkit.Material @@ -16,6 +17,11 @@ import kotlin.math.min class StackedRecipeListener( private val plugin: EcoPlugin ) : Listener { + /* + If you think you can fix this code, you're wrong. + Or, pray to whatever god you have that you can figure it out. + Best of luck, you're going to need it. + */ @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) fun handleStacks(event: InventoryClickEvent) { val inventory = event.clickedInventory as? CraftingInventory ?: return @@ -23,6 +29,11 @@ class StackedRecipeListener( return } + // Just in case + if (EmptyTestableItem().matches(inventory.getItem(event.slot))) { + return + } + val matrix = inventory.matrix val recipe = Recipes.getMatch(matrix) ?: return @@ -79,6 +90,10 @@ class StackedRecipeListener( } item.amount = amount + /* + Everything below this point is unreadable garbage + */ + // Do it twice because spigot hates me // Everything has to be cloned because the inventory changes the item inventory.matrix[i] = item.clone() // Use un-cloned version first @@ -99,13 +114,11 @@ class StackedRecipeListener( // Multiply the result by the amount to craft if shift-clicking existingResult ?: return - // Run later as will be overridden by above check - plugin.scheduler.run { - if (event.isShiftClick) { - existingResult.amount *= maxCraftable - } - inventory.result = existingResult + // Modify the item and then set it + if (event.isShiftClick) { + existingResult.amount *= maxCraftable } + inventory.result = existingResult } private fun runTwice(block: () -> Unit) {