package ru.dbotthepony.mc.otm.container

import net.minecraft.world.inventory.CraftingContainer
import net.minecraft.world.item.ItemStack

open class MatteryCraftingContainer(listener: ContainerListener, private val width: Int, private val height: Int) : MatteryContainer(listener, width * height), CraftingContainer {
	constructor(listener: () -> Unit, width: Int, height: Int) : this({ _, _, _ -> listener.invoke() }, width, height)
	constructor(width: Int, height: Int) : this(EmptyListener, width, height)

	final override fun getWidth(): Int {
		return width
	}

	final override fun getHeight(): Int {
		return height
	}

	final override fun getItems(): MutableList<ItemStack> {
		val i = spliterator()
		val result = ArrayList<ItemStack>(i.estimateSize().toInt())
		i.forEachRemaining { result.add(it) }
		return result
	}
}
