69 lines
2.5 KiB
Kotlin
69 lines
2.5 KiB
Kotlin
package net.shadowfacts.phycon.plugin.rei
|
|
|
|
import me.shedaniel.rei.api.common.category.CategoryIdentifier
|
|
import me.shedaniel.rei.api.common.display.SimpleGridMenuDisplay
|
|
import me.shedaniel.rei.api.common.plugins.REIServerPlugin
|
|
import me.shedaniel.rei.api.common.transfer.info.MenuInfoContext
|
|
import me.shedaniel.rei.api.common.transfer.info.MenuInfoRegistry
|
|
import me.shedaniel.rei.api.common.transfer.info.simple.SimpleGridMenuInfo
|
|
import me.shedaniel.rei.api.common.transfer.info.simple.SimpleMenuInfoProvider
|
|
import me.shedaniel.rei.api.common.transfer.info.stack.SlotAccessor
|
|
import net.minecraft.util.Identifier
|
|
import net.shadowfacts.phycon.api.PhyConAPI
|
|
import net.shadowfacts.phycon.api.PhyConPlugin
|
|
import net.shadowfacts.phycon.api.TerminalSettingKey
|
|
import net.shadowfacts.phycon.block.terminal.CraftingTerminalScreenHandler
|
|
import java.util.stream.IntStream
|
|
|
|
/**
|
|
* @author shadowfacts
|
|
*/
|
|
object PhyConPluginCommon: REIServerPlugin, PhyConPlugin {
|
|
const val MODID = "phycon_rei"
|
|
|
|
lateinit var REI_SYNC_KEY: TerminalSettingKey<REISyncMode>
|
|
private set
|
|
|
|
override fun registerMenuInfo(registry: MenuInfoRegistry) {
|
|
registry.register(CategoryIdentifier.of("minecraft", "plugins/crafting"), CraftingTerminalScreenHandler::class.java, SimpleMenuInfoProvider.of(::TerminalInfo))
|
|
}
|
|
|
|
override fun initializePhyCon(api: PhyConAPI) {
|
|
REI_SYNC_KEY = api.registerTerminalSetting(Identifier(MODID, "rei_sync"), REISyncMode.OFF)
|
|
}
|
|
|
|
class TerminalInfo<D: SimpleGridMenuDisplay>(
|
|
private val display: D,
|
|
): SimpleGridMenuInfo<CraftingTerminalScreenHandler, D> {
|
|
|
|
override fun getCraftingResultSlotIndex(menu: CraftingTerminalScreenHandler): Int {
|
|
return menu.resultSlot.id
|
|
}
|
|
|
|
override fun getInputStackSlotIds(context: MenuInfoContext<CraftingTerminalScreenHandler, *, D>): IntStream {
|
|
return IntStream.range(context.menu.craftingSlotsStart, context.menu.craftingSlotsEnd)
|
|
}
|
|
|
|
override fun getInventorySlots(context: MenuInfoContext<CraftingTerminalScreenHandler, *, D>): Iterable<SlotAccessor> {
|
|
val slots = super.getInventorySlots(context).toMutableList()
|
|
for (i in (context.menu.bufferSlotsStart until context.menu.bufferSlotsEnd)) {
|
|
slots.add(SlotAccessor.fromSlot(context.menu.getSlot(i)))
|
|
}
|
|
return slots
|
|
}
|
|
|
|
override fun getCraftingWidth(menu: CraftingTerminalScreenHandler): Int {
|
|
return 3
|
|
}
|
|
|
|
override fun getCraftingHeight(menu: CraftingTerminalScreenHandler): Int {
|
|
return 3
|
|
}
|
|
|
|
override fun getDisplay(): D {
|
|
return display
|
|
}
|
|
}
|
|
|
|
}
|