package ru.dbotthepony.mc.otm.android.feature

import net.minecraft.world.entity.ai.attributes.AttributeModifier
import net.minecraftforge.common.ForgeMod
import ru.dbotthepony.mc.otm.android.AndroidFeature
import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability
import ru.dbotthepony.mc.otm.registry.AndroidFeatures
import java.util.*

class ExtendedReachFeature(android: MatteryPlayerCapability) : AndroidFeature(AndroidFeatures.EXTENDED_REACH, android) {
	override fun applyModifiers() {
		if (!ForgeMod.BLOCK_REACH.isPresent)
			return

		val reach = ply.getAttribute(ForgeMod.BLOCK_REACH.get()) ?: return

		reach.removePermanentModifier(MODIFIER_ID)
		reach.addPermanentModifier(AttributeModifier(MODIFIER_ID, type.displayName.toString(), level + 1.0, AttributeModifier.Operation.ADDITION))
	}

	override fun removeModifiers() {
		if (!ForgeMod.BLOCK_REACH.isPresent)
			return

		ply.getAttribute(ForgeMod.BLOCK_REACH.get())?.removePermanentModifier(MODIFIER_ID)
	}

	companion object {
		private val MODIFIER_ID = UUID.fromString("4a3fae46-47a8-a03f-857d-f5c2b2c8f2f2")
	}
}
