This isn't going to be the last commit, is it
This commit is contained in:
@@ -2,6 +2,7 @@ package com.willfp.eco.internal.spigot.recipes
|
|||||||
|
|
||||||
import com.willfp.eco.core.EcoPlugin
|
import com.willfp.eco.core.EcoPlugin
|
||||||
import com.willfp.eco.core.recipe.Recipes
|
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.GroupedTestableItems
|
||||||
import com.willfp.eco.core.recipe.parts.TestableStack
|
import com.willfp.eco.core.recipe.parts.TestableStack
|
||||||
import org.bukkit.Material
|
import org.bukkit.Material
|
||||||
@@ -16,6 +17,11 @@ import kotlin.math.min
|
|||||||
class StackedRecipeListener(
|
class StackedRecipeListener(
|
||||||
private val plugin: EcoPlugin
|
private val plugin: EcoPlugin
|
||||||
) : Listener {
|
) : 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)
|
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||||
fun handleStacks(event: InventoryClickEvent) {
|
fun handleStacks(event: InventoryClickEvent) {
|
||||||
val inventory = event.clickedInventory as? CraftingInventory ?: return
|
val inventory = event.clickedInventory as? CraftingInventory ?: return
|
||||||
@@ -23,6 +29,11 @@ class StackedRecipeListener(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Just in case
|
||||||
|
if (EmptyTestableItem().matches(inventory.getItem(event.slot))) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
val matrix = inventory.matrix
|
val matrix = inventory.matrix
|
||||||
|
|
||||||
val recipe = Recipes.getMatch(matrix) ?: return
|
val recipe = Recipes.getMatch(matrix) ?: return
|
||||||
@@ -79,6 +90,10 @@ class StackedRecipeListener(
|
|||||||
}
|
}
|
||||||
item.amount = amount
|
item.amount = amount
|
||||||
|
|
||||||
|
/*
|
||||||
|
Everything below this point is unreadable garbage
|
||||||
|
*/
|
||||||
|
|
||||||
// Do it twice because spigot hates me
|
// Do it twice because spigot hates me
|
||||||
// Everything has to be cloned because the inventory changes the item
|
// Everything has to be cloned because the inventory changes the item
|
||||||
inventory.matrix[i] = item.clone() // Use un-cloned version first
|
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
|
// Multiply the result by the amount to craft if shift-clicking
|
||||||
existingResult ?: return
|
existingResult ?: return
|
||||||
|
|
||||||
// Run later as will be overridden by above check
|
// Modify the item and then set it
|
||||||
plugin.scheduler.run {
|
if (event.isShiftClick) {
|
||||||
if (event.isShiftClick) {
|
existingResult.amount *= maxCraftable
|
||||||
existingResult.amount *= maxCraftable
|
|
||||||
}
|
|
||||||
inventory.result = existingResult
|
|
||||||
}
|
}
|
||||||
|
inventory.result = existingResult
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun runTwice(block: () -> Unit) {
|
private fun runTwice(block: () -> Unit) {
|
||||||
|
|||||||
Reference in New Issue
Block a user