diff --git a/plugin/rei/src/main/kotlin/net/shadowfacts/phycon/plugin/rei/PhyConPlugin.kt b/plugin/rei/src/main/kotlin/net/shadowfacts/phycon/plugin/rei/PhyConPlugin.kt index afb7118..a242cdb 100644 --- a/plugin/rei/src/main/kotlin/net/shadowfacts/phycon/plugin/rei/PhyConPlugin.kt +++ b/plugin/rei/src/main/kotlin/net/shadowfacts/phycon/plugin/rei/PhyConPlugin.kt @@ -41,4 +41,5 @@ object PhyConPlugin: ClientModInitializer, REIPluginV0 { ) } } + } diff --git a/plugin/rei/src/main/kotlin/net/shadowfacts/phycon/plugin/rei/PhyConPluginCommon.kt b/plugin/rei/src/main/kotlin/net/shadowfacts/phycon/plugin/rei/PhyConPluginCommon.kt new file mode 100644 index 0000000..388ee45 --- /dev/null +++ b/plugin/rei/src/main/kotlin/net/shadowfacts/phycon/plugin/rei/PhyConPluginCommon.kt @@ -0,0 +1,47 @@ +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 { + 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): List { + val handler = context.container + return (handler.craftingSlotsStart until handler.craftingSlotsEnd).map(context::getStack) + } + + override fun getInventoryStacks(context: ContainerContext): List { + val handler = context.container + val slots = (handler.playerSlotsStart until handler.playerSlotsEnd) + (handler.bufferSlotsStart until handler.bufferSlotsEnd) + return slots.map(context::getStack) + } + } + +} diff --git a/plugin/rei/src/main/resources/fabric.mod.json b/plugin/rei/src/main/resources/fabric.mod.json index a93fa92..6a6e093 100644 --- a/plugin/rei/src/main/resources/fabric.mod.json +++ b/plugin/rei/src/main/resources/fabric.mod.json @@ -12,8 +12,13 @@ "homepage": "https://git.shadowfacts.net/minecraft/PhysicalConnectivity" }, "license": "LGPL-3.0", - "environment": "client", "entrypoints": { + "main": [ + { + "adapter": "kotlin", + "value": "net.shadowfacts.phycon.plugin.rei.PhyConPluginCommon" + } + ], "client": [ { "adapter": "kotlin", @@ -34,7 +39,7 @@ "fabric": "*", "fabric-language-kotlin": ">=1.3.50", "phycon": "*", - "roughlyenoughitems": "*" + "roughlyenoughitems": "^5.0.0" }, "custom": { diff --git a/src/main/kotlin/net/shadowfacts/phycon/block/terminal/CraftingTerminalScreenHandler.kt b/src/main/kotlin/net/shadowfacts/phycon/block/terminal/CraftingTerminalScreenHandler.kt index 6998c63..6a506f3 100644 --- a/src/main/kotlin/net/shadowfacts/phycon/block/terminal/CraftingTerminalScreenHandler.kt +++ b/src/main/kotlin/net/shadowfacts/phycon/block/terminal/CraftingTerminalScreenHandler.kt @@ -29,6 +29,10 @@ class CraftingTerminalScreenHandler( val result = CraftingResultInventory() val resultSlot: CraftingResultSlot + val craftingSlotsStart: Int + val craftingSlotsEnd: Int + get() = craftingSlotsStart + 9 + override val xOffset: Int get() = 5 @@ -40,6 +44,7 @@ class CraftingTerminalScreenHandler( ) init { + craftingSlotsStart = slots.size for (y in 0 until 3) { for (x in 0 until 3) { this.addSlot(Slot(craftingInv, x + y * 3, 13 + x * 18, 140 + y * 18)) diff --git a/src/main/kotlin/net/shadowfacts/phycon/block/terminal/CraftingTerminalViewController.kt b/src/main/kotlin/net/shadowfacts/phycon/block/terminal/CraftingTerminalViewController.kt index 4489dd7..ba52b94 100644 --- a/src/main/kotlin/net/shadowfacts/phycon/block/terminal/CraftingTerminalViewController.kt +++ b/src/main/kotlin/net/shadowfacts/phycon/block/terminal/CraftingTerminalViewController.kt @@ -1,6 +1,7 @@ package net.shadowfacts.phycon.block.terminal import net.minecraft.client.MinecraftClient +import net.minecraft.client.gui.screen.Screen import net.minecraft.client.util.InputUtil import net.minecraft.text.TranslatableText import net.minecraft.util.Identifier @@ -89,7 +90,7 @@ class CraftingTerminalViewController( private fun plusPressed(button: Button) { val client = MinecraftClient.getInstance() val action = - if (InputUtil.isKeyPressed(client.window.handle, GLFW.GLFW_KEY_LEFT_SHIFT) || InputUtil.isKeyPressed(client.window.handle, GLFW.GLFW_KEY_RIGHT_SHIFT)) { + if (Screen.hasShiftDown()) { C2STerminalCraftingButton.Action.REQUEST_MAX_MORE } else { C2STerminalCraftingButton.Action.REQUEST_ONE_MORE