YuRaNnNzZZ — Сегодня, в 11:46

а какой именно стак то блять
This commit is contained in:
DBotThePony 2023-08-19 13:09:36 +07:00
parent 62df3558e7
commit b3863a2820
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -449,15 +449,19 @@ object MatterManager {
} }
stream.map { stream.map {
ResolvedRecipe( try {
it.ingredients.stream() ResolvedRecipe(
.filter { !it.isActuallyEmpty } it.ingredients.stream()
.map { it.items.stream().map(::RecipeEntry) }, .filter { !it.isActuallyEmpty }
ImmutableStack(it.getResultItem(server.registryAccess())), .map { it.items.stream().map(::RecipeEntry) },
isCritical = isCritical, ImmutableStack(it.getResultItem(server.registryAccess())),
name = it.id, isCritical = isCritical,
allowBacktrack = allowBacktrack name = it.id,
) allowBacktrack = allowBacktrack
)
} catch(err: Throwable) {
throw RuntimeException("Processing simple recipe ${it.id}", err)
}
} }
.filter { .filter {
if (it.inputs.isEmpty()) { if (it.inputs.isEmpty()) {
@ -491,79 +495,83 @@ object MatterManager {
} }
stream.map { stream.map {
// avoid reality snap when recipe has no output try {
val resultItem = it.getResultItem(server.registryAccess()) // avoid reality snap when recipe has no output
val resultItem = it.getResultItem(server.registryAccess())
if (resultItem.isEmpty) { if (resultItem.isEmpty) {
null null
} else {
var width: Int
var height: Int
if (it is IShapedRecipe<*>) {
width = it.recipeWidth
height = it.recipeHeight
} else { } else {
width = 3 var width: Int
height = 3 var height: Int
}
if (width * height < it.ingredients.size) { if (it is IShapedRecipe<*>) {
width = it.ingredients.size.coerceAtLeast(width) width = it.recipeWidth
height = it.ingredients.size.coerceAtLeast(height) height = it.recipeHeight
} } else {
width = 3
val container = TransientCraftingContainer(object : AbstractContainerMenu(null, 0) { height = 3
override fun quickMoveStack(pPlayer: Player, pIndex: Int): ItemStack {
return ItemStack.EMPTY
} }
override fun stillValid(pPlayer: Player): Boolean { if (width * height < it.ingredients.size) {
return false width = it.ingredients.size.coerceAtLeast(width)
} height = it.ingredients.size.coerceAtLeast(height)
}, width, height)
val realIngredients = ArrayList<ArrayList<RecipeEntry>>()
for (c in it.ingredients.indices) {
if (it.ingredients[c].isActuallyEmpty) {
continue
} }
for ((i, ingredient) in it.ingredients.withIndex()) { val container = TransientCraftingContainer(object : AbstractContainerMenu(null, 0) {
if (i != c) { override fun quickMoveStack(pPlayer: Player, pIndex: Int): ItemStack {
container[i] = if (ingredient.isActuallyEmpty) ItemStack.EMPTY else ingredient.items.firstOrNull() ?: ItemStack.EMPTY return ItemStack.EMPTY
} }
}
val result = ArrayList<RecipeEntry>() override fun stillValid(pPlayer: Player): Boolean {
return false
}
}, width, height)
for (item in it.ingredients[c].items) { val realIngredients = ArrayList<ArrayList<RecipeEntry>>()
container[c] = item
if (!it.assemble(container, server.registryAccess()).isEmpty) { for (c in it.ingredients.indices) {
val residue = it.getRemainingItems(container) if (it.ingredients[c].isActuallyEmpty) {
continue
}
val thisResidue = residue[c] for ((i, ingredient) in it.ingredients.withIndex()) {
if (i != c) {
if (thisResidue.isEmpty) { container[i] = if (ingredient.isActuallyEmpty) ItemStack.EMPTY else ingredient.items.firstOrNull() ?: ItemStack.EMPTY
result.add(RecipeEntry(item))
} else {
result.add(RecipeEntry(ImmutableStack(item), ImmutableStack(thisResidue)))
} }
} }
val result = ArrayList<RecipeEntry>()
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
)
} }
} catch(err: Throwable) {
ResolvedRecipe( throw RuntimeException("Processing crafting table recipe ${it.id}", err)
realIngredients.stream().map { it.stream() },
ImmutableStack(resultItem),
isCritical = isCritical,
name = it.id,
allowBacktrack = allowBacktrack
)
} }
}.filterNotNull().filter { }.filterNotNull().filter {
if (it.inputs.isEmpty()) { if (it.inputs.isEmpty()) {
@ -1346,8 +1354,8 @@ object MatterManager {
val multiplier: Double = 1.0 val multiplier: Double = 1.0
) { ) {
init { init {
require(!multiplier.isNaN()) { "Provided stack cost multiplier is NaN" } require(!multiplier.isNaN()) { "Provided stack cost multiplier is NaN (item: $item)" }
require(!multiplier.isInfinite()) { "Provided stack cost multiplier is infinite" } require(!multiplier.isInfinite()) { "Provided stack cost multiplier is infinite (item: $item)" }
} }
constructor(item: Item, count: Int) : this(item, 1.0 / count.toDouble()) constructor(item: Item, count: Int) : this(item, 1.0 / count.toDouble())