Update REI plugin

This commit is contained in:
Shadowfacts 2021-12-22 22:17:25 -05:00
parent 5488cc295a
commit 30300dbc40
3 changed files with 51 additions and 42 deletions

View File

@ -11,7 +11,7 @@ import net.shadowfacts.phycon.block.terminal.AbstractTerminalScreen
/**
* @author shadowfacts
*/
object PhyConPlugin: ClientModInitializer, REIClientPlugin {
object PhyConPluginClient: ClientModInitializer, REIClientPlugin {
const val MODID = "phycon_rei"
override fun onInitializeClient() {

View File

@ -1,45 +1,56 @@
package net.shadowfacts.phycon.plugin.rei
import me.shedaniel.rei.api.common.display.Display
import me.shedaniel.rei.api.common.transfer.info.MenuInfo
import net.fabricmc.api.ModInitializer
import net.minecraft.util.Identifier
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.shadowfacts.phycon.block.terminal.CraftingTerminalScreenHandler
import java.util.stream.IntStream
/**
* @author shadowfacts
*/
object PhyConPluginCommon: ModInitializer {
object PhyConPluginCommon: REIServerPlugin {
override fun onInitialize() {
// ContainerInfoHandler.registerContainerInfo(Identifier("minecraft", "plugins/crafting"), TerminalInfo)
override fun registerMenuInfo(registry: MenuInfoRegistry) {
registry.register(CategoryIdentifier.of("minecraft", "plugins/crafting"), CraftingTerminalScreenHandler::class.java, SimpleMenuInfoProvider.of(::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)
// }
// }
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
}
}
}

View File

@ -13,22 +13,20 @@
},
"license": "LGPL-3.0",
"entrypoints": {
"main": [
{
"adapter": "kotlin",
"value": "net.shadowfacts.phycon.plugin.rei.PhyConPluginCommon"
}
],
"client": [
{
"adapter": "kotlin",
"value": "net.shadowfacts.phycon.plugin.rei.PhyConPlugin"
"value": "net.shadowfacts.phycon.plugin.rei.PhyConPluginClient"
}
],
"rei": [
{
"adapter": "kotlin",
"value": "net.shadowfacts.phycon.plugin.rei.PhyConPlugin"
"value": "net.shadowfacts.phycon.plugin.rei.PhyConPluginClient"
},
{
"adapter": "kotlin",
"value": "net.shadowfacts.phycon.plugin.rei.PhyConPluginCommon"
}
]
},