46 lines
1.4 KiB
Kotlin
46 lines
1.4 KiB
Kotlin
package net.shadowfacts.asmr.manager
|
|
|
|
import net.fabricmc.api.EnvType
|
|
import net.fabricmc.api.Environment
|
|
import net.minecraft.block.Block
|
|
import net.minecraft.block.BlockEntityProvider
|
|
import net.minecraft.block.BlockState
|
|
import net.minecraft.block.Material
|
|
import net.minecraft.block.entity.BlockEntity
|
|
import net.minecraft.client.MinecraftClient
|
|
import net.minecraft.entity.player.PlayerEntity
|
|
import net.minecraft.util.Hand
|
|
import net.minecraft.util.hit.BlockHitResult
|
|
import net.minecraft.util.math.BlockPos
|
|
import net.minecraft.world.BlockView
|
|
import net.minecraft.world.World
|
|
import net.shadowfacts.asmr.ui.ManagerViewController
|
|
import net.shadowfacts.cacao.CacaoScreen
|
|
import net.shadowfacts.cacao.Window
|
|
|
|
/**
|
|
* @author shadowfacts
|
|
*/
|
|
class ManagerBlock: Block(Settings.of(Material.METAL)), BlockEntityProvider {
|
|
|
|
@Deprecated("")
|
|
override fun activate(state: BlockState, world: World, pos: BlockPos, player: PlayerEntity, hand: Hand, hitResult: BlockHitResult?): Boolean {
|
|
if (world.isClient) {
|
|
openManagerUI(world.getBlockEntity(pos) as ManagerBlockEntity)
|
|
}
|
|
return true
|
|
}
|
|
|
|
@Environment(EnvType.CLIENT)
|
|
private fun openManagerUI(managerBlockEntity: ManagerBlockEntity) {
|
|
val vc = ManagerViewController(managerBlockEntity)
|
|
val screen = CacaoScreen()
|
|
val window = screen.addWindow(Window(vc))
|
|
MinecraftClient.getInstance().openScreen(screen)
|
|
}
|
|
|
|
override fun createBlockEntity(world: BlockView): BlockEntity {
|
|
return ManagerBlockEntity()
|
|
}
|
|
|
|
} |