Fix matter entangler not working
This commit is contained in:
parent
5166bf20ad
commit
9947c94414
@ -77,12 +77,12 @@ class MatterEntanglerBlockEntity(blockPos: BlockPos, blockState: BlockState) : M
|
|||||||
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
||||||
val list = inputs.toList()
|
val list = inputs.toList()
|
||||||
list[slot] = stack
|
list[slot] = stack
|
||||||
val shadow = CraftingInput.of(3, 3, list)
|
val shadow = CraftingInput.ofPositioned(3, 3, list)
|
||||||
|
|
||||||
return (level ?: return false)
|
return (level ?: return false)
|
||||||
.recipeManager
|
.recipeManager
|
||||||
.byType(MRecipes.MATTER_ENTANGLER)
|
.byType(MRecipes.MATTER_ENTANGLER)
|
||||||
.any { it.value.preemptivelyMatches(shadow, level!!) }
|
.any { it.value.preemptivelyMatches(shadow, level!!, 3, 3) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun canExtract(slot: Int, amount: Int, stack: ItemStack): Boolean {
|
override fun canExtract(slot: Int, amount: Int, stack: ItemStack): Boolean {
|
||||||
|
@ -72,7 +72,16 @@ import kotlin.reflect.KProperty
|
|||||||
|
|
||||||
operator fun RecipeInput.get(index: Int): ItemStack = getItem(index)
|
operator fun RecipeInput.get(index: Int): ItemStack = getItem(index)
|
||||||
operator fun CraftingInput.get(x: Int, y: Int): ItemStack = getItem(x, y)
|
operator fun CraftingInput.get(x: Int, y: Int): ItemStack = getItem(x, y)
|
||||||
operator fun CraftingInput.get(x: Int, y: Int, flop: Boolean): ItemStack = if (flop) getItem(x, y) else getItem(width() - x - 1, y)
|
|
||||||
|
operator fun CraftingInput.Positioned.get(x: Int, y: Int): ItemStack {
|
||||||
|
val actualX = x - left
|
||||||
|
val actualY = y - top
|
||||||
|
|
||||||
|
if (actualX !in 0 until input.width() || actualY !in 0 until input.height())
|
||||||
|
return ItemStack.EMPTY
|
||||||
|
|
||||||
|
return input.getItem(actualX, actualY)
|
||||||
|
}
|
||||||
|
|
||||||
fun FriendlyByteBuf.writeBigInteger(value: BigInteger) {
|
fun FriendlyByteBuf.writeBigInteger(value: BigInteger) {
|
||||||
writeByteArray(value.toByteArray())
|
writeByteArray(value.toByteArray())
|
||||||
|
@ -48,13 +48,13 @@ class MatterEntanglerMenu(
|
|||||||
override fun mayPlace(itemStack: ItemStack): Boolean {
|
override fun mayPlace(itemStack: ItemStack): Boolean {
|
||||||
val list = it.toList()
|
val list = it.toList()
|
||||||
list[i] = itemStack
|
list[i] = itemStack
|
||||||
val shadow = CraftingInput.of(3, 3, list)
|
val shadow = CraftingInput.ofPositioned(3, 3, list)
|
||||||
val level = player.level()
|
val level = player.level()
|
||||||
|
|
||||||
return super.mayPlace(itemStack) && (level ?: return false)
|
return super.mayPlace(itemStack) && (level ?: return false)
|
||||||
.recipeManager
|
.recipeManager
|
||||||
.byType(MRecipes.MATTER_ENTANGLER)
|
.byType(MRecipes.MATTER_ENTANGLER)
|
||||||
.any { it.value.preemptivelyMatches(shadow, level) }
|
.any { it.value.preemptivelyMatches(shadow, level, 3, 3) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,63 +16,47 @@ operator fun ShapedRecipePattern.get(column: Int, row: Int): Ingredient {
|
|||||||
return ingredients()[column + row * width]
|
return ingredients()[column + row * width]
|
||||||
}
|
}
|
||||||
|
|
||||||
operator fun ShapedRecipePattern.get(column: Int, row: Int, flop: Boolean): Ingredient {
|
fun ShapedRecipePattern.preemptiveTest(t: CraftingInput.Positioned, craftingWidth: Int, craftingHeight: Int): Boolean {
|
||||||
return if (flop)
|
if (
|
||||||
get(width - column - 1, row)
|
t.input.width() > width ||
|
||||||
else
|
t.input.height() > height
|
||||||
get(column, row)
|
) {
|
||||||
}
|
|
||||||
|
|
||||||
fun ShapedRecipePattern.preemptiveTest(t: CraftingInput, fromColumn: Int, fromRow: Int, flop: Boolean): Boolean {
|
|
||||||
if (t.width() - fromColumn < width || t.height() - fromRow < height)
|
|
||||||
return false
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
for (column in 0 until width) {
|
for (columnPadding in 0 .. craftingWidth - width) {
|
||||||
for (row in 0 until height) {
|
for (rowPadding in 0 .. craftingHeight - height) {
|
||||||
val item = t[fromColumn + column, fromRow + row, flop]
|
var invalid = false
|
||||||
val ingredient = this[column, row, flop]
|
|
||||||
|
|
||||||
if (!ingredient.test(item) && item.isNotEmpty) {
|
outer@for (column in 0 until width) {
|
||||||
return false
|
for (row in 0 until height) {
|
||||||
|
val ingredient = this[column, row]
|
||||||
|
val item = t[column + columnPadding, row + rowPadding]
|
||||||
|
|
||||||
|
if (!ingredient.test(item) && item.isNotEmpty) {
|
||||||
|
invalid = true
|
||||||
|
break@outer
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!invalid) {
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
fun ShapedRecipePattern.preemptiveTest(t: CraftingInput): Boolean {
|
|
||||||
if (t.width() < width || t.height() < height)
|
|
||||||
return false
|
|
||||||
|
|
||||||
for (column in 0 .. t.width() - width)
|
|
||||||
for (row in 0 .. t.height() - height)
|
|
||||||
if (preemptiveTest(t, column, row, false) || preemptiveTest(t, column, row, true))
|
|
||||||
return true
|
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
fun ShapedRecipePattern.test(t: CraftingInput, fromColumn: Int, fromRow: Int, flop: Boolean): Boolean {
|
fun ShapedRecipePattern.test(t: CraftingInput): Boolean {
|
||||||
if (t.width() - fromColumn < width || t.height() - fromRow < height)
|
if (t.width() != width || t.height() != height)
|
||||||
return false
|
return false
|
||||||
|
|
||||||
for (column in 0 until width)
|
for (column in 0 until width)
|
||||||
for (row in 0 until height)
|
for (row in 0 until height)
|
||||||
if (!this[column, row, flop].test(t[fromColumn + column, fromRow + row, flop]))
|
if (!this[column, row].test(t[column, row]))
|
||||||
return false
|
return false
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
fun ShapedRecipePattern.test(t: CraftingInput): Boolean {
|
|
||||||
if (t.width() < width || t.height() < height)
|
|
||||||
return false
|
|
||||||
|
|
||||||
for (column in 0 .. t.width() - width)
|
|
||||||
for (row in 0 .. t.height() - height)
|
|
||||||
if (test(t, column, row, false) || test(t, column, row, true))
|
|
||||||
return true
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
@ -39,7 +39,7 @@ interface IMatterEntanglerRecipe : IMatteryRecipe<CraftingInput> {
|
|||||||
val result: ItemStack
|
val result: ItemStack
|
||||||
val experience: Float
|
val experience: Float
|
||||||
|
|
||||||
fun preemptivelyMatches(container: CraftingInput, level: Level): Boolean
|
fun preemptivelyMatches(container: CraftingInput.Positioned, level: Level, craftingWidth: Int, craftingHeight: Int): Boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
open class MatterEntanglerRecipe(
|
open class MatterEntanglerRecipe(
|
||||||
@ -56,9 +56,9 @@ open class MatterEntanglerRecipe(
|
|||||||
return ingredients.test(container)
|
return ingredients.test(container)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun preemptivelyMatches(container: CraftingInput, level: Level): Boolean {
|
override fun preemptivelyMatches(container: CraftingInput.Positioned, level: Level, craftingWidth: Int, craftingHeight: Int): Boolean {
|
||||||
if (isIncomplete) return false
|
if (isIncomplete) return false
|
||||||
return ingredients.preemptiveTest(container)
|
return ingredients.preemptiveTest(container, craftingWidth, craftingHeight)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun assemble(container: CraftingInput, registry: HolderLookup.Provider): ItemStack {
|
override fun assemble(container: CraftingInput, registry: HolderLookup.Provider): ItemStack {
|
||||||
|
Loading…
Reference in New Issue
Block a user