package net.shadowfacts.phycon.item import net.minecraft.client.MinecraftClient import net.minecraft.item.Item import net.minecraft.item.ItemUsageContext 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.console.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 } private fun openScreen(be: DeviceBlockEntity) { // val screen = TestCacaoScreen() val screen = DeviceConsoleScreen(be) MinecraftClient.getInstance().openScreen(screen) } }