Make craftingGridTuples be sane

This commit is contained in:
DBotThePony 2022-06-29 22:05:53 +07:00
parent b6d3f59da0
commit eed9ffaf96
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -43,9 +43,10 @@ import ru.dbotthepony.mc.otm.registry.MBlockEntities
import ru.dbotthepony.mc.otm.set import ru.dbotthepony.mc.otm.set
import ru.dbotthepony.mc.otm.storage.* import ru.dbotthepony.mc.otm.storage.*
import java.math.BigInteger import java.math.BigInteger
import java.util.IdentityHashMap import java.util.*
import java.util.UUID
import java.util.function.Supplier import java.util.function.Supplier
import kotlin.collections.HashMap
import kotlin.collections.HashSet
class ItemMonitorPlayerSettings : INBTSerializable<CompoundTag> { class ItemMonitorPlayerSettings : INBTSerializable<CompoundTag> {
enum class RefillSource(val component: TranslatableComponent) { enum class RefillSource(val component: TranslatableComponent) {
@ -163,13 +164,11 @@ private fun takeOne(inventory: Inventory, item: ItemStack): Boolean {
return false return false
} }
private fun takeOne(set: Set<UUID>, view: IStorageProvider<ItemStackWrapper>): Boolean { private fun takeOne(id: UUID?, view: IStorageProvider<ItemStackWrapper>): Boolean {
for (id in set) { val extracted = view.extractStack(id ?: return false, BigInteger.ONE, false)
val extracted = view.extractStack(id, BigInteger.ONE, false)
if (!extracted.isEmpty) { if (!extracted.isEmpty) {
return true return true
}
} }
return false return false
@ -230,9 +229,7 @@ class ItemMonitorBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
val craftingRecipe = craftingRecipe val craftingRecipe = craftingRecipe
if (oldRecipe != craftingRecipe) { if (oldRecipe != craftingRecipe) {
for (i in craftingGridTuples.indices) { Arrays.fill(craftingGridTuples, null)
craftingGridTuples[i] = HashSet()
}
val poweredView = poweredView val poweredView = poweredView
@ -241,14 +238,14 @@ class ItemMonitorBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
val item = craftingGrid[i] val item = craftingGrid[i]
if (!item.isEmpty) { 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) { private val craftingMenu = object : AbstractContainerMenu(null, Int.MIN_VALUE) {
override fun stillValid(p_38874_: Player): Boolean { override fun stillValid(p_38874_: Player): Boolean {
@ -262,7 +259,7 @@ class ItemMonitorBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
get() = ITEM_STORAGE get() = ITEM_STORAGE
override fun addStack(stack: ItemStackWrapper, id: UUID, provider: IStorageProvider<ItemStackWrapper>) { 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) { 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) { override fun removeStack(stack: ItemStackWrapper, id: UUID) {
// TODO("Not yet implemented") for (i in craftingGridTuples.indices) {
if (craftingGridTuples[i] == id) {
craftingGridTuples[i] = null
}
}
} }
init { init {