From 584d8cd04eb22ef10bc79a4ba39af9fa25e15c40 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 14 Feb 2021 12:07:05 -0500 Subject: [PATCH] Add Console item --- .../net/shadowfacts/phycon/init/PhyItems.kt | 3 ++ .../shadowfacts/phycon/item/ConsoleItem.kt | 47 ++++++++++++++++++ .../phycon/screen/DeviceConsoleScreen.kt | 38 ++++++++++++++ .../resources/assets/phycon/lang/en_us.json | 3 +- .../assets/phycon/models/item/console.json | 6 +++ .../assets/phycon/textures/item/console.png | Bin 0 -> 913 bytes 6 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/net/shadowfacts/phycon/item/ConsoleItem.kt create mode 100644 src/main/kotlin/net/shadowfacts/phycon/screen/DeviceConsoleScreen.kt create mode 100644 src/main/resources/assets/phycon/models/item/console.json create mode 100644 src/main/resources/assets/phycon/textures/item/console.png diff --git a/src/main/kotlin/net/shadowfacts/phycon/init/PhyItems.kt b/src/main/kotlin/net/shadowfacts/phycon/init/PhyItems.kt index c48c222..6db41c5 100644 --- a/src/main/kotlin/net/shadowfacts/phycon/init/PhyItems.kt +++ b/src/main/kotlin/net/shadowfacts/phycon/init/PhyItems.kt @@ -4,6 +4,7 @@ import net.minecraft.item.BlockItem import net.minecraft.item.Item import net.minecraft.util.Identifier import net.minecraft.util.registry.Registry +import net.shadowfacts.phycon.item.ConsoleItem import net.shadowfacts.phycon.item.ScrewdriverItem import net.shadowfacts.phycon.network.block.cable.CableBlock import net.shadowfacts.phycon.network.block.netinterface.InterfaceBlock @@ -25,6 +26,7 @@ object PhyItems { val DEST = BlockItem(PhyBlocks.DEST , Item.Settings()) val SCREWDRIVER = ScrewdriverItem() + val CONSOLE = ConsoleItem() fun init() { register(InterfaceBlock.ID, INTERFACE) @@ -35,6 +37,7 @@ object PhyItems { register(DestBlock.ID, DEST) register(ScrewdriverItem.ID, SCREWDRIVER) + register(ConsoleItem.ID, CONSOLE) } private fun register(id: Identifier, item: Item) { diff --git a/src/main/kotlin/net/shadowfacts/phycon/item/ConsoleItem.kt b/src/main/kotlin/net/shadowfacts/phycon/item/ConsoleItem.kt new file mode 100644 index 0000000..cd4ef8f --- /dev/null +++ b/src/main/kotlin/net/shadowfacts/phycon/item/ConsoleItem.kt @@ -0,0 +1,47 @@ +package net.shadowfacts.phycon.item + +import net.fabricmc.api.EnvType +import net.fabricmc.api.Environment +import net.minecraft.client.MinecraftClient +import net.minecraft.item.Item +import net.minecraft.item.ItemUsageContext +import net.minecraft.text.LiteralText +import net.minecraft.util.ActionResult +import net.minecraft.util.Identifier +import net.shadowfacts.phycon.PhysicalConnectivity +import net.shadowfacts.phycon.network.DeviceBlock +import net.shadowfacts.phycon.network.DeviceBlockEntity +import net.shadowfacts.phycon.screen.DeviceConsoleScreen + +/** + * @author shadowfacts + */ +class ConsoleItem: Item(Settings()) { + companion object { + val ID = Identifier(PhysicalConnectivity.MODID, "console") + } + + override fun useOnBlock(context: ItemUsageContext): ActionResult { + val state = context.world.getBlockState(context.blockPos) + val block = state.block + if (block is DeviceBlock<*>) { + val be = block.getBlockEntity(context.world, context.blockPos) + if (be != null) { + if (context.world.isClient) { + this.openScreen(be) + } else { + be.sync() + } + return ActionResult.SUCCESS + } + } + return ActionResult.PASS + } + + @Environment(EnvType.CLIENT) + private fun openScreen(be: DeviceBlockEntity) { + val screen = DeviceConsoleScreen(be) + MinecraftClient.getInstance().openScreen(screen) + } + +} \ No newline at end of file diff --git a/src/main/kotlin/net/shadowfacts/phycon/screen/DeviceConsoleScreen.kt b/src/main/kotlin/net/shadowfacts/phycon/screen/DeviceConsoleScreen.kt new file mode 100644 index 0000000..37f9751 --- /dev/null +++ b/src/main/kotlin/net/shadowfacts/phycon/screen/DeviceConsoleScreen.kt @@ -0,0 +1,38 @@ +package net.shadowfacts.phycon.screen + +import net.minecraft.client.gui.screen.Screen +import net.minecraft.client.util.math.MatrixStack +import net.minecraft.text.TranslatableText +import net.shadowfacts.phycon.network.DeviceBlockEntity +import org.lwjgl.glfw.GLFW + +/** + * @author shadowfacts + */ +class DeviceConsoleScreen( + val device: DeviceBlockEntity, +): Screen(TranslatableText("item.phycon.onsole")) { + + override fun init() { + super.init() + } + + override fun isPauseScreen() = false + + override fun keyPressed(key: Int, j: Int, k: Int): Boolean { + if (key == GLFW.GLFW_KEY_E) { + onClose(); + return true; + } + return super.keyPressed(key, j, k) + } + + override fun render(matrixStack: MatrixStack, mouseX: Int, mouseY: Int, delta: Float) { + renderBackground(matrixStack) + + super.render(matrixStack, mouseX, mouseY, delta) + + drawCenteredString(matrixStack, textRenderer, device.macAddress.toString(), width / 2, height / 2 - 5, 0xffffff) + drawCenteredString(matrixStack, textRenderer, device.ipAddress.toString(), width / 2, height / 2 + 5, 0xffffff) + } +} \ No newline at end of file diff --git a/src/main/resources/assets/phycon/lang/en_us.json b/src/main/resources/assets/phycon/lang/en_us.json index 7f87630..332003b 100644 --- a/src/main/resources/assets/phycon/lang/en_us.json +++ b/src/main/resources/assets/phycon/lang/en_us.json @@ -4,5 +4,6 @@ "block.phycon.terminal": "Terminal", "block.phycon.cable": "Cable", - "item.phycon.screwdriver": "Screwdriver" + "item.phycon.screwdriver": "Screwdriver", + "item.phycon.console": "Console" } \ No newline at end of file diff --git a/src/main/resources/assets/phycon/models/item/console.json b/src/main/resources/assets/phycon/models/item/console.json new file mode 100644 index 0000000..4e7be5e --- /dev/null +++ b/src/main/resources/assets/phycon/models/item/console.json @@ -0,0 +1,6 @@ +{ + "parent": "minecraft:item/generated", + "textures": { + "layer0": "phycon:item/console" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/phycon/textures/item/console.png b/src/main/resources/assets/phycon/textures/item/console.png new file mode 100644 index 0000000000000000000000000000000000000000..f53b48506a94efec6197a0bf3c618d8b3691143d GIT binary patch literal 913 zcmV;C18)3@P)EX>4Tx04R}tkv&MmKpe$iQ$>;b0d^2^$WR@`f~bh2R-p(LLaorMgUO{|(4-+r zad8w}3l4rPRvlcNb#-tR1i=pwH#a9m7b)?7NufoI2gm(*ckglc4iIW3rde&{fTr7K zG9DAtnN_jl6#{zD2N9z(vy3@OO2Bt~-6O!)yC~1{KlkV8RN#J&iAq7)K7rmGjOFh{pA`k^GSNO zsYQ-}-fiIGx~VC9z~v4w@MOrQ>`FnJLM{iqpV2pEfc{&cYt8Gev5(USAVpmzZh(VB zU?fl3>pt)9Z0+seGmZX!0Ch}qsEh=&3;+NC24YJ`L;xQEEC4tHro1))000SaNLh0L z04^f{04^f|c%?sf00007bV*G`2jv0|5HLCwE=cnL00E6jL_t(I%WacAa@#Nvg}=AZ zAwpI8xr0YZn~|&7lkhxBC!fcKQYHsTE@2h1;!AK}3IHTMHYx&K?7sc*7Jw*)z9b>3 z?=%)uCfH&9MAmt{-H*-v&=+5Xd!NUNdP7dR&YAJ<;(GmR2fLL zhcTH|4K{Ac6{RxhLAQ4g2y;5Te@6V~_^`CFCStQu&9!0=w|8gkL~UPv5d_8pDL}$b z!m~wKq_ys*%;jHBWRqcMWh4>3#&){}sXcYQ7!lB%*zIdz7`AhJ8&}(wDLoBuhDAwt zq1zLRc&sZMG5-*d3{{;m@!8 ne0^3{hUqIJW(8Ueu_XQjVm-N$#xk$w00000NkvXXu0mjf7n7AC literal 0 HcmV?d00001