# Pastebin xAYT4N96 class MyBlock: Block(Material(MapColor.PURPLE)) { init { blockHardness = 1.0f unlocalizedName = "my-block" setCreativeTab(CreativeTab) setRegistryName("my-block") } val validDirections = arrayOf(EnumFacing.EAST, EnumFacing.WEST, EnumFacing.NORTH, EnumFacing.SOUTH, EnumFacing.UP, EnumFacing.DOWN) val myTileEntity: MyBlockTE by lazy { MyBlockTE() } override fun isSideSolid(base_state: IBlockState?, world: IBlockAccess?, pos: BlockPos?, side: EnumFacing?): Boolean = true override fun canHarvestBlock(world: IBlockAccess?, pos: BlockPos?, player: EntityPlayer?): Boolean = true override fun getHarvestTool(state: IBlockState?): String? = null override fun canBeReplacedByLeaves(state: IBlockState?, world: IBlockAccess?, pos: BlockPos?): Boolean = false override fun getValidRotations(world: World?, pos: BlockPos?): Array = validDirections override fun onBlockActivated(worldIn: World?, pos: BlockPos?, state: IBlockState?, playerIn: EntityPlayer?, hand: EnumHand?, heldItem: ItemStack?, side: EnumFacing?, hitX: Float, hitY: Float, hitZ: Float): Boolean { if (!worldIn!!.isRemote) { return false } myTileEntity.saySomethingRandom(playerIn!!) return true } override fun createTileEntity(world: World?, state: IBlockState?): TileEntity { return myTileEntity } } class MyBlockTE: TileEntity() { var nbtData: NBTTagCompound = NBTTagCompound() var messages: MutableList by nbtData fun saySomethingRandom(player: EntityPlayer) { if(messages.isEmpty()) { messages = mutableListOf("That tickles!", "Teehee~", "Stop it!", "Boo!") } val text = TextComponentString(messages.random()) text.style = text.style.setColor(TextFormatting.RED) player.sendMessage(text) } override fun readFromNBT(compound: NBTTagCompound?) { ButtsMod.log.info("Reading MyBlockTE from NBT!") nbtData = compound?.getCompoundTag("kotlin-state")!! super.readFromNBT(compound) } override fun writeToNBT(compound: NBTTagCompound?): NBTTagCompound { ButtsMod.log.info("Writing MyBlockTE to NBT!") compound!!.setTag("kotlin-state", nbtData) return super.writeToNBT(compound) } }