# Pastebin kenF85yZ class MyBlock : Block(Material(MapColor.PURPLE)), ITileEntityProvider { 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) 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 } (worldIn.getTileEntity(pos) as MyBlockTE).saySomethingRandom(playerIn!!) return true } override fun createNewTileEntity(worldIn: World?, meta: Int): TileEntity = MyBlockTE() } class MyBlockTE : TileEntity() { var state: NBTTagCompound? = NBTTagCompound() var messages: MutableList by state fun saySomethingRandom(player: EntityPlayer) { val text = TextComponentString(messages.random()) text.style = text.style.setColor(TextFormatting.RED) player.sendMessage(text) } override fun readFromNBT(compound: NBTTagCompound?) { super.readFromNBT(compound) if (compound!!.hasKey("kotlin-state")) { synchronized(state!!) { state?.merge(compound.getCompoundTag("kotlin-state")) ButtsMod.log.info("[readFromNBT] State is: $state") } } if (messages.isEmpty()) { messages = mutableListOf("That tickles!", "Teehee~", "Stop it!", "Boo!") ButtsMod.log.info("[PRE-ChunkDirty] State is: $state") world.markChunkDirty(pos, this) ButtsMod.log.info("[POST-ChunkDirty] State is: $state") } } override fun writeToNBT(compound: NBTTagCompound?): NBTTagCompound { synchronized(state!!) { ButtsMod.log.info("[writeToNBT] State is: $state") compound!!.setTag("kotlin-state", state) } return super.writeToNBT(compound) } }