PhysicalConnectivity/plugin/rei/src/main/kotlin/net/shadowfacts/phycon/plugin/rei/PhyConPluginCommon.kt

48 lines
1.6 KiB
Kotlin

package net.shadowfacts.phycon.plugin.rei
import me.shedaniel.rei.server.ContainerContext
import me.shedaniel.rei.server.ContainerInfo
import me.shedaniel.rei.server.ContainerInfoHandler
import me.shedaniel.rei.server.StackAccessor
import net.fabricmc.api.ModInitializer
import net.minecraft.util.Identifier
import net.shadowfacts.phycon.block.terminal.CraftingTerminalScreenHandler
/**
* @author shadowfacts
*/
object PhyConPluginCommon: ModInitializer {
override fun onInitialize() {
ContainerInfoHandler.registerContainerInfo(Identifier("minecraft", "plugins/crafting"), TerminalInfo)
}
object TerminalInfo: ContainerInfo<CraftingTerminalScreenHandler> {
override fun getContainerClass() = CraftingTerminalScreenHandler::class.java
override fun getCraftingResultSlotIndex(container: CraftingTerminalScreenHandler): Int {
return container.resultSlot.id
}
override fun getCraftingWidth(container: CraftingTerminalScreenHandler): Int {
return 3
}
override fun getCraftingHeight(container: CraftingTerminalScreenHandler): Int {
return 3
}
override fun getGridStacks(context: ContainerContext<CraftingTerminalScreenHandler>): List<StackAccessor> {
val handler = context.container
return (handler.craftingSlotsStart until handler.craftingSlotsEnd).map(context::getStack)
}
override fun getInventoryStacks(context: ContainerContext<CraftingTerminalScreenHandler>): List<StackAccessor> {
val handler = context.container
val slots = (handler.playerSlotsStart until handler.playerSlotsEnd) + (handler.bufferSlotsStart until handler.bufferSlotsEnd)
return slots.map(context::getStack)
}
}
}