package ru.dbotthepony.kstarbound.world.entities

import ru.dbotthepony.kstarbound.network.syncher.legacyCodec
import ru.dbotthepony.kstarbound.network.syncher.nativeCodec
import ru.dbotthepony.kstarbound.network.syncher.readPointer
import ru.dbotthepony.kstarbound.network.syncher.writePointer
import java.io.DataInputStream
import java.io.DataOutputStream

data class AnchorState(val entityID: Int, val positionIndex: Int) {
	constructor(stream: DataInputStream, isLegacy: Boolean) : this(stream.readInt(), stream.readPointer().toInt())

	fun write(stream: DataOutputStream, isLegacy: Boolean) {
		stream.writeInt(entityID)
		stream.writePointer(positionIndex)
	}

	companion object {
		val CODEC = nativeCodec(::AnchorState, AnchorState::write)
		val LEGACY_CODEC = legacyCodec(::AnchorState, AnchorState::write)
	}
}
