package ru.dbotthepony.mc.otm.capability.item

import net.minecraft.world.item.ItemStack
import net.neoforged.neoforge.items.IItemHandler

class ProxiedItemHandler<T : IItemHandler>(var parent: T? = null) : IItemHandler {
	override fun getSlots(): Int {
		return parent?.slots ?: 0
	}

	override fun getStackInSlot(slot: Int): ItemStack {
		return parent?.getStackInSlot(slot) ?: ItemStack.EMPTY
	}

	override fun insertItem(slot: Int, stack: ItemStack, simulate: Boolean): ItemStack {
		return parent?.insertItem(slot, stack, simulate) ?: stack
	}

	override fun extractItem(slot: Int, amount: Int, simulate: Boolean): ItemStack {
		return parent?.extractItem(slot, amount, simulate) ?: ItemStack.EMPTY
	}

	override fun getSlotLimit(slot: Int): Int {
		return parent?.getSlotLimit(slot) ?: 0
	}

	override fun isItemValid(slot: Int, stack: ItemStack): Boolean {
		return parent?.isItemValid(slot, stack) ?: false
	}
}
