Unable to set slot on craftingoutpot

val craftingGridInventory: Inventory = inventory.query(QueryOperationTypes.INVENTORY_TYPE.of(CraftingInventory::class.java))
val toCompareWithOutputSlots = craftingGridInventory.slots<Slot>().toList()
val toCompareWithOutput = toCompareWithOutputSlots.map { it.peek().orElse(null) }
val craftingOutput = toCompareWithOutputSlots[0]

val result = craftingOutput.slots<Slot>().first().set(stack)

if (result.rejectedItems.isNotEmpty()) {
   println("CraftingOutput slot set was rejected !!!")

how do I know why this set transaction is rejected / how do I set the result slot in my workbench? type of TransactioNResult is FAILURE


Ok found this solution. With this you can cut all the crap like get slots then first etc


(player as EntityPlayer).openContainer.inventorySlots[0].putStack(stack as net.minecraft.item.ItemStack)