package ru.dbotthepony.kstarbound.client.world

import ru.dbotthepony.kstarbound.world.Chunk
import ru.dbotthepony.kstarbound.world.ChunkPos
import ru.dbotthepony.kstarbound.world.ChunkState
import ru.dbotthepony.kstarbound.world.api.AbstractCell
import ru.dbotthepony.kstarbound.world.api.ImmutableCell

class ClientChunk(world: ClientWorld, pos: ChunkPos) : Chunk<ClientWorld, ClientChunk>(world, pos) {
	override val state: ChunkState
		get() = ChunkState.FULL

	// we don't care about current status since we are always considered to be fully loaded
	override fun setCell(x: Int, y: Int, cell: AbstractCell, chunkState: ChunkState): Boolean {
		return setCell(x, y, cell)
	}

	override fun foregroundChanges(x: Int, y: Int, cell: ImmutableCell) {
		super.foregroundChanges(x, y, cell)

		world.forEachRenderRegion(pos.tile(x, y)) {
			it.foreground.markDirty()
		}
	}

	override fun backgroundChanges(x: Int, y: Int, cell: ImmutableCell) {
		super.backgroundChanges(x, y, cell)

		world.forEachRenderRegion(pos.tile(x, y)) {
			it.background.markDirty()
		}
	}

	override fun liquidChanges(x: Int, y: Int, cell: ImmutableCell) {
		super.liquidChanges(x, y, cell)

		world.forEachRenderRegion(pos.tile(x, y)) {
			it.liquidIsDirty = true
		}
	}
}
