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.block.DeviceBlock import net.shadowfacts.phycon.block.DeviceBlockEntity import net.shadowfacts.phycon.client.screen.console.DeviceConsoleScreen /** * @author shadowfacts */ class ConsoleItem: Item(Settings().maxCount(1)) { 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.markUpdate() } return ActionResult.SUCCESS } } return ActionResult.PASS } private fun openScreen(be: DeviceBlockEntity) { // val screen = TestCacaoScreen() val screen = DeviceConsoleScreen(be) MinecraftClient.getInstance().setScreen(screen) } }