From b3863a282043440a1a53044de89bb62fc16e4487 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Sat, 19 Aug 2023 13:09:36 +0700 Subject: [PATCH] =?UTF-8?q?YuRaNnNzZZ=20=E2=80=94=20=D0=A1=D0=B5=D0=B3?= =?UTF-8?q?=D0=BE=D0=B4=D0=BD=D1=8F,=20=D0=B2=2011:46=20=D0=B0=20=D0=BA?= =?UTF-8?q?=D0=B0=D0=BA=D0=BE=D0=B9=20=D0=B8=D0=BC=D0=B5=D0=BD=D0=BD=D0=BE?= =?UTF-8?q?=20=D1=81=D1=82=D0=B0=D0=BA=20=D1=82=D0=BE=20=D0=B1=D0=BB=D1=8F?= =?UTF-8?q?=D1=82=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mc/otm/matter/MatterManager.kt | 142 +++++++++--------- 1 file changed, 75 insertions(+), 67 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/matter/MatterManager.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/matter/MatterManager.kt index eb7598029..4c306f697 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/matter/MatterManager.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/matter/MatterManager.kt @@ -449,15 +449,19 @@ object MatterManager { } stream.map { - ResolvedRecipe( - it.ingredients.stream() - .filter { !it.isActuallyEmpty } - .map { it.items.stream().map(::RecipeEntry) }, - ImmutableStack(it.getResultItem(server.registryAccess())), - isCritical = isCritical, - name = it.id, - allowBacktrack = allowBacktrack - ) + try { + ResolvedRecipe( + it.ingredients.stream() + .filter { !it.isActuallyEmpty } + .map { it.items.stream().map(::RecipeEntry) }, + ImmutableStack(it.getResultItem(server.registryAccess())), + isCritical = isCritical, + name = it.id, + allowBacktrack = allowBacktrack + ) + } catch(err: Throwable) { + throw RuntimeException("Processing simple recipe ${it.id}", err) + } } .filter { if (it.inputs.isEmpty()) { @@ -491,79 +495,83 @@ object MatterManager { } stream.map { - // avoid reality snap when recipe has no output - val resultItem = it.getResultItem(server.registryAccess()) + try { + // avoid reality snap when recipe has no output + val resultItem = it.getResultItem(server.registryAccess()) - if (resultItem.isEmpty) { - null - } else { - var width: Int - var height: Int - - if (it is IShapedRecipe<*>) { - width = it.recipeWidth - height = it.recipeHeight + if (resultItem.isEmpty) { + null } else { - width = 3 - height = 3 - } + var width: Int + var height: Int - if (width * height < it.ingredients.size) { - width = it.ingredients.size.coerceAtLeast(width) - height = it.ingredients.size.coerceAtLeast(height) - } - - val container = TransientCraftingContainer(object : AbstractContainerMenu(null, 0) { - override fun quickMoveStack(pPlayer: Player, pIndex: Int): ItemStack { - return ItemStack.EMPTY + if (it is IShapedRecipe<*>) { + width = it.recipeWidth + height = it.recipeHeight + } else { + width = 3 + height = 3 } - override fun stillValid(pPlayer: Player): Boolean { - return false - } - }, width, height) - - val realIngredients = ArrayList>() - - for (c in it.ingredients.indices) { - if (it.ingredients[c].isActuallyEmpty) { - continue + if (width * height < it.ingredients.size) { + width = it.ingredients.size.coerceAtLeast(width) + height = it.ingredients.size.coerceAtLeast(height) } - for ((i, ingredient) in it.ingredients.withIndex()) { - if (i != c) { - container[i] = if (ingredient.isActuallyEmpty) ItemStack.EMPTY else ingredient.items.firstOrNull() ?: ItemStack.EMPTY + val container = TransientCraftingContainer(object : AbstractContainerMenu(null, 0) { + override fun quickMoveStack(pPlayer: Player, pIndex: Int): ItemStack { + return ItemStack.EMPTY } - } - val result = ArrayList() + override fun stillValid(pPlayer: Player): Boolean { + return false + } + }, width, height) - for (item in it.ingredients[c].items) { - container[c] = item + val realIngredients = ArrayList>() - if (!it.assemble(container, server.registryAccess()).isEmpty) { - val residue = it.getRemainingItems(container) + for (c in it.ingredients.indices) { + if (it.ingredients[c].isActuallyEmpty) { + continue + } - val thisResidue = residue[c] - - if (thisResidue.isEmpty) { - result.add(RecipeEntry(item)) - } else { - result.add(RecipeEntry(ImmutableStack(item), ImmutableStack(thisResidue))) + for ((i, ingredient) in it.ingredients.withIndex()) { + if (i != c) { + container[i] = if (ingredient.isActuallyEmpty) ItemStack.EMPTY else ingredient.items.firstOrNull() ?: ItemStack.EMPTY } } + + val result = ArrayList() + + for (item in it.ingredients[c].items) { + container[c] = item + + if (!it.assemble(container, server.registryAccess()).isEmpty) { + val residue = it.getRemainingItems(container) + + val thisResidue = residue[c] + + if (thisResidue.isEmpty) { + result.add(RecipeEntry(item)) + } else { + result.add(RecipeEntry(ImmutableStack(item), ImmutableStack(thisResidue))) + } + } + } + + realIngredients.add(result) } - realIngredients.add(result) + ResolvedRecipe( + realIngredients.stream().map { it.stream() }, + ImmutableStack(resultItem), + isCritical = isCritical, + name = it.id, + allowBacktrack = allowBacktrack + ) } - - ResolvedRecipe( - realIngredients.stream().map { it.stream() }, - ImmutableStack(resultItem), - isCritical = isCritical, - name = it.id, - allowBacktrack = allowBacktrack - ) + } catch(err: Throwable) { + throw RuntimeException("Processing crafting table recipe ${it.id}", err) } }.filterNotNull().filter { if (it.inputs.isEmpty()) { @@ -1346,8 +1354,8 @@ object MatterManager { val multiplier: Double = 1.0 ) { init { - require(!multiplier.isNaN()) { "Provided stack cost multiplier is NaN" } - require(!multiplier.isInfinite()) { "Provided stack cost multiplier is infinite" } + require(!multiplier.isNaN()) { "Provided stack cost multiplier is NaN (item: $item)" } + require(!multiplier.isInfinite()) { "Provided stack cost multiplier is infinite (item: $item)" } } constructor(item: Item, count: Int) : this(item, 1.0 / count.toDouble())