PhysicalConnectivity/src/main/kotlin/net/shadowfacts/phycon/item/ConsoleItem.kt

45 lines
1.2 KiB
Kotlin
Raw Normal View History

2021-02-14 17:07:05 +00:00
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
2021-02-28 18:48:39 +00:00
import net.shadowfacts.phycon.block.DeviceBlock
import net.shadowfacts.phycon.block.DeviceBlockEntity
2021-03-26 02:15:46 +00:00
import net.shadowfacts.phycon.client.screen.console.DeviceConsoleScreen
2021-02-14 17:07:05 +00:00
/**
* @author shadowfacts
*/
class ConsoleItem: Item(Settings().maxCount(1)) {
2021-02-14 17:07:05 +00:00
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 {
2021-12-22 23:59:51 +00:00
be.markUpdate()
2021-02-14 17:07:05 +00:00
}
return ActionResult.SUCCESS
}
}
return ActionResult.PASS
}
private fun openScreen(be: DeviceBlockEntity) {
2021-02-28 02:48:40 +00:00
// val screen = TestCacaoScreen()
val screen = DeviceConsoleScreen(be)
2021-12-22 23:59:51 +00:00
MinecraftClient.getInstance().setScreen(screen)
2021-02-14 17:07:05 +00:00
}
2021-02-24 03:05:05 +00:00
}