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

import net.minecraft.world.entity.ai.attributes.AttributeModifier
import net.minecraft.world.entity.ai.attributes.Attributes
import ru.dbotthepony.mc.otm.OverdriveThatMatters
import ru.dbotthepony.mc.otm.android.AndroidFeature
import ru.dbotthepony.mc.otm.capability.MatteryPlayer
import ru.dbotthepony.mc.otm.core.ResourceLocation
import ru.dbotthepony.mc.otm.registry.game.AndroidFeatures

class ExtendedReachFeature(android: MatteryPlayer) : AndroidFeature(AndroidFeatures.EXTENDED_REACH, android) {
	override fun applyModifiers() {
		val reach = ply.getAttribute(Attributes.BLOCK_INTERACTION_RANGE) ?: return

		reach.removeModifier(MODIFIER_ID)
		reach.addPermanentModifier(AttributeModifier(MODIFIER_ID, level + 1.0, AttributeModifier.Operation.ADD_VALUE))
	}

	override fun removeModifiers() {
		ply.getAttribute(Attributes.BLOCK_INTERACTION_RANGE)?.removeModifier(MODIFIER_ID)
	}

	companion object {
		private val MODIFIER_ID = ResourceLocation(OverdriveThatMatters.MOD_ID, "android_extended_reach")
	}
}
