package ru.dbotthepony.mc.otm.container

import net.minecraft.world.entity.player.StackedContents
import net.minecraft.world.inventory.CraftingContainer
import net.minecraft.world.item.ItemStack
import ru.dbotthepony.mc.otm.container.util.iterator
import ru.dbotthepony.mc.otm.core.collect.toList

class ShadowCraftingContainer(private val parent: CraftingContainer) : IContainer by ShadowContainer(parent), CraftingContainer {
	override fun fillStackedContents(contents: StackedContents) {
		for (item in iterator()) {
			contents.accountStack(item)
		}
	}

	override fun getWidth(): Int {
		return parent.width
	}

	override fun getHeight(): Int {
		return parent.height
	}

	override fun getItems(): MutableList<ItemStack> {
		return iterator().toList()
	}

	companion object {
		fun shadow(container: CraftingContainer, slot: Int, itemStack: ItemStack): CraftingContainer {
			return ShadowCraftingContainer(container).also { it[slot] = itemStack }
		}
	}
}
