package ru.dbotthepony.kstarbound.network.packets.clientbound

import ru.dbotthepony.kstarbound.client.ClientConnection
import ru.dbotthepony.kstarbound.io.readNullable
import ru.dbotthepony.kstarbound.io.writeNullable
import ru.dbotthepony.kstarbound.network.IClientPacket
import java.io.DataInputStream
import java.io.DataOutputStream

class UpdateDungeonBreathablePacket(val id: Int, val breathable: Boolean?) : IClientPacket {
	constructor(stream: DataInputStream, isLegacy: Boolean) : this(stream.readUnsignedShort(), stream.readNullable { readBoolean() })

	override fun write(stream: DataOutputStream, isLegacy: Boolean) {
		stream.writeShort(id)
		stream.writeNullable(breathable) { writeBoolean(it) }
	}

	override fun play(connection: ClientConnection) {
		connection.enqueue {
			world?.setDungeonBreathable(this@UpdateDungeonBreathablePacket.id, breathable)
		}
	}
}
