REI: Add support for filling recipes in the Crafting Terminal

This commit is contained in:
Shadowfacts 2021-03-29 19:18:15 -04:00
parent 236d6707f6
commit 87f0bdb85a
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
5 changed files with 62 additions and 3 deletions

View File

@ -41,4 +41,5 @@ object PhyConPlugin: ClientModInitializer, REIPluginV0 {
)
}
}
}

View File

@ -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<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)
}
}
}

View File

@ -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": {

View File

@ -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))

View File

@ -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