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

import net.minecraft.client.gui.GuiGraphics
import net.minecraft.world.entity.ai.attributes.AttributeModifier
import net.minecraftforge.common.ForgeMod
import ru.dbotthepony.mc.otm.android.AndroidSwitchableFeature
import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability
import ru.dbotthepony.mc.otm.client.render.ResearchIcons
import ru.dbotthepony.mc.otm.config.AndroidConfig
import ru.dbotthepony.mc.otm.core.math.RGBAColor
import ru.dbotthepony.mc.otm.registry.AndroidFeatures
import java.util.*

class SwimBoostersFeature(android: MatteryPlayerCapability) : AndroidSwitchableFeature(AndroidFeatures.SWIM_BOOSTERS, android) {
	override fun applyModifiers() {
		if (!ForgeMod.SWIM_SPEED.isPresent || !isActive)
			return

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

		attr.removeModifier(MODIFIER_ID)
		attr.addPermanentModifier(AttributeModifier(MODIFIER_ID, type.displayName.toString(), (level + 1) * AndroidConfig.SWIM_BOOSTERS, AttributeModifier.Operation.ADDITION))
	}

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

		ply.getAttribute(ForgeMod.SWIM_SPEED.get())?.removeModifier(MODIFIER_ID)
	}

	override fun renderIcon(graphics: GuiGraphics, 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 = UUID.fromString("4a3ffa46-47a8-a03f-857d-f5c2b2c8f2f6")
	}
}
