Make craftingGridTuples be sane
This commit is contained in:
parent
b6d3f59da0
commit
eed9ffaf96
@ -43,9 +43,10 @@ import ru.dbotthepony.mc.otm.registry.MBlockEntities
|
||||
import ru.dbotthepony.mc.otm.set
|
||||
import ru.dbotthepony.mc.otm.storage.*
|
||||
import java.math.BigInteger
|
||||
import java.util.IdentityHashMap
|
||||
import java.util.UUID
|
||||
import java.util.*
|
||||
import java.util.function.Supplier
|
||||
import kotlin.collections.HashMap
|
||||
import kotlin.collections.HashSet
|
||||
|
||||
class ItemMonitorPlayerSettings : INBTSerializable<CompoundTag> {
|
||||
enum class RefillSource(val component: TranslatableComponent) {
|
||||
@ -163,14 +164,12 @@ private fun takeOne(inventory: Inventory, item: ItemStack): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
private fun takeOne(set: Set<UUID>, view: IStorageProvider<ItemStackWrapper>): Boolean {
|
||||
for (id in set) {
|
||||
val extracted = view.extractStack(id, BigInteger.ONE, false)
|
||||
private fun takeOne(id: UUID?, view: IStorageProvider<ItemStackWrapper>): Boolean {
|
||||
val extracted = view.extractStack(id ?: return false, BigInteger.ONE, false)
|
||||
|
||||
if (!extracted.isEmpty) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
@ -230,9 +229,7 @@ class ItemMonitorBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
|
||||
val craftingRecipe = craftingRecipe
|
||||
|
||||
if (oldRecipe != craftingRecipe) {
|
||||
for (i in craftingGridTuples.indices) {
|
||||
craftingGridTuples[i] = HashSet()
|
||||
}
|
||||
Arrays.fill(craftingGridTuples, null)
|
||||
|
||||
val poweredView = poweredView
|
||||
|
||||
@ -241,14 +238,14 @@ class ItemMonitorBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
|
||||
val item = craftingGrid[i]
|
||||
|
||||
if (!item.isEmpty) {
|
||||
poweredView[ItemStackWrapper(item).key()]?.let(craftingGridTuples[i]::add)
|
||||
craftingGridTuples[i] = poweredView[ItemStackWrapper(item).key()]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val craftingGridTuples = Array(3 * 3) { HashSet<UUID>() }
|
||||
private val craftingGridTuples = arrayOfNulls<UUID>(3 * 3)
|
||||
|
||||
private val craftingMenu = object : AbstractContainerMenu(null, Int.MIN_VALUE) {
|
||||
override fun stillValid(p_38874_: Player): Boolean {
|
||||
@ -262,7 +259,7 @@ class ItemMonitorBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
|
||||
get() = ITEM_STORAGE
|
||||
|
||||
override fun addStack(stack: ItemStackWrapper, id: UUID, provider: IStorageProvider<ItemStackWrapper>) {
|
||||
// TODO("Not yet implemented")
|
||||
// no op
|
||||
}
|
||||
|
||||
override fun changeStack(stack: ItemStackWrapper, id: UUID, oldCount: BigInteger) {
|
||||
@ -270,7 +267,11 @@ class ItemMonitorBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
|
||||
}
|
||||
|
||||
override fun removeStack(stack: ItemStackWrapper, id: UUID) {
|
||||
// TODO("Not yet implemented")
|
||||
for (i in craftingGridTuples.indices) {
|
||||
if (craftingGridTuples[i] == id) {
|
||||
craftingGridTuples[i] = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
|
Loading…
Reference in New Issue
Block a user