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

import net.minecraft.world.entity.ai.attributes.AttributeModifier
import net.neoforged.neoforge.common.NeoForgeMod
import ru.dbotthepony.mc.otm.android.AndroidSwitchableFeature
import ru.dbotthepony.mc.otm.capability.MatteryPlayer
import ru.dbotthepony.mc.otm.client.render.MGUIGraphics
import ru.dbotthepony.mc.otm.client.render.ResearchIcons
import ru.dbotthepony.mc.otm.config.AndroidConfig
import ru.dbotthepony.kommons.math.RGBAColor
import ru.dbotthepony.mc.otm.OverdriveThatMatters
import ru.dbotthepony.mc.otm.core.ResourceLocation
import ru.dbotthepony.mc.otm.registry.game.AndroidFeatures

class SwimBoostersFeature(android: MatteryPlayer) : AndroidSwitchableFeature(AndroidFeatures.SWIM_BOOSTERS, android) {
	override fun applyModifiers() {
		if (!isActive)
			return

		val attr = ply.getAttribute(NeoForgeMod.SWIM_SPEED) ?: return

		attr.removeModifier(MODIFIER_ID)
		attr.addPermanentModifier(AttributeModifier(MODIFIER_ID, (level + 1) * AndroidConfig.SWIM_BOOSTERS, AttributeModifier.Operation.ADD_VALUE))
	}

	override fun removeModifiers() {
		ply.getAttribute(NeoForgeMod.SWIM_SPEED)?.removeModifier(MODIFIER_ID)
	}

	override fun renderIcon(graphics: MGUIGraphics, x: Float, y: Float, width: Float, height: Float, color: RGBAColor) {
		ResearchIcons.ICON_LIMB_OVERCLOCKING.render(graphics, x, y, width, height, color = color)
	}

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