package ru.dbotthepony.mc.otm.entity

import net.minecraft.network.syncher.EntityDataAccessor
import net.minecraft.network.syncher.SynchedEntityData
import net.minecraft.world.entity.Entity
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty

class SynchedEntityDataDelegate<T>(private val type: EntityDataAccessor<T>, private val data: SynchedEntityData) : ReadWriteProperty<Entity, T> {
	override fun getValue(thisRef: Entity, property: KProperty<*>): T {
		return data.get(type)
	}

	override fun setValue(thisRef: Entity, property: KProperty<*>, value: T) {
		data.set(type, value)
	}
}

fun <T> SynchedEntityData.delegate(type: EntityDataAccessor<T>) = SynchedEntityDataDelegate(type, this)
