Add Console item
This commit is contained in:
parent
446a2a42c3
commit
584d8cd04e
|
@ -4,6 +4,7 @@ import net.minecraft.item.BlockItem
|
||||||
import net.minecraft.item.Item
|
import net.minecraft.item.Item
|
||||||
import net.minecraft.util.Identifier
|
import net.minecraft.util.Identifier
|
||||||
import net.minecraft.util.registry.Registry
|
import net.minecraft.util.registry.Registry
|
||||||
|
import net.shadowfacts.phycon.item.ConsoleItem
|
||||||
import net.shadowfacts.phycon.item.ScrewdriverItem
|
import net.shadowfacts.phycon.item.ScrewdriverItem
|
||||||
import net.shadowfacts.phycon.network.block.cable.CableBlock
|
import net.shadowfacts.phycon.network.block.cable.CableBlock
|
||||||
import net.shadowfacts.phycon.network.block.netinterface.InterfaceBlock
|
import net.shadowfacts.phycon.network.block.netinterface.InterfaceBlock
|
||||||
|
@ -25,6 +26,7 @@ object PhyItems {
|
||||||
val DEST = BlockItem(PhyBlocks.DEST , Item.Settings())
|
val DEST = BlockItem(PhyBlocks.DEST , Item.Settings())
|
||||||
|
|
||||||
val SCREWDRIVER = ScrewdriverItem()
|
val SCREWDRIVER = ScrewdriverItem()
|
||||||
|
val CONSOLE = ConsoleItem()
|
||||||
|
|
||||||
fun init() {
|
fun init() {
|
||||||
register(InterfaceBlock.ID, INTERFACE)
|
register(InterfaceBlock.ID, INTERFACE)
|
||||||
|
@ -35,6 +37,7 @@ object PhyItems {
|
||||||
register(DestBlock.ID, DEST)
|
register(DestBlock.ID, DEST)
|
||||||
|
|
||||||
register(ScrewdriverItem.ID, SCREWDRIVER)
|
register(ScrewdriverItem.ID, SCREWDRIVER)
|
||||||
|
register(ConsoleItem.ID, CONSOLE)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun register(id: Identifier, item: Item) {
|
private fun register(id: Identifier, item: Item) {
|
||||||
|
|
|
@ -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)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,5 +4,6 @@
|
||||||
"block.phycon.terminal": "Terminal",
|
"block.phycon.terminal": "Terminal",
|
||||||
"block.phycon.cable": "Cable",
|
"block.phycon.cable": "Cable",
|
||||||
|
|
||||||
"item.phycon.screwdriver": "Screwdriver"
|
"item.phycon.screwdriver": "Screwdriver",
|
||||||
|
"item.phycon.console": "Console"
|
||||||
}
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"parent": "minecraft:item/generated",
|
||||||
|
"textures": {
|
||||||
|
"layer0": "phycon:item/console"
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
After Width: | Height: | Size: 913 B |
Loading…
Reference in New Issue