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

54 lines
1.7 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
import net.shadowfacts.phycon.network.DeviceBlock
import net.shadowfacts.phycon.network.DeviceBlockEntity
2021-02-24 03:05:05 +00:00
import net.shadowfacts.phycon.network.block.redstone.RedstoneControllerBlockEntity
import net.shadowfacts.phycon.network.component.ActivationController
import net.shadowfacts.phycon.screen.ActivatableDeviceConsoleScreen
2021-02-14 17:07:05 +00:00
import net.shadowfacts.phycon.screen.DeviceConsoleScreen
2021-02-24 03:05:05 +00:00
import net.shadowfacts.phycon.screen.RedstoneControllerConsoleScreen
2021-02-19 04:27:18 +00:00
import net.shadowfacts.phycon.screen.TestCacaoScreen
2021-02-14 17:07:05 +00:00
/**
* @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) {
2021-02-19 04:27:18 +00:00
val screen = TestCacaoScreen()
2021-02-26 23:52:23 +00:00
// val screen = when (be) {
// is ActivationController.ActivatableDevice -> ActivatableDeviceConsoleScreen(be)
// is RedstoneControllerBlockEntity -> RedstoneControllerConsoleScreen(be)
// else -> DeviceConsoleScreen(be)
// }
2021-02-14 17:07:05 +00:00
MinecraftClient.getInstance().openScreen(screen)
}
2021-02-24 03:05:05 +00:00
}