package nivia.modules.exploits;

import net.minecraft.network.play.client.C03PacketPlayer;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import nivia.events.EventTarget;
import nivia.events.events.EventTick;
import nivia.modules.Module;
import nivia.utils.Helper;

import java.util.Objects;

public class Firion extends Module {

	public Firion() {
		super("Firion", 0, 0xd3290f, Category.EXPLOITS, "Gets rid of fire and bad potion effects.",
				new String[] { "zoot", "antipotion", "firepotion", "milk", "firon" }, true);
	}

	@EventTarget
	public void onTick(EventTick event) {
		if (Helper.blockUtils().isOnLiquid())
			return;
		if (mc.thePlayer.isPotionActive(Potion.blindness.getId()))
			mc.thePlayer.removePotionEffect(Potion.blindness.getId());

		if (mc.thePlayer.isPotionActive(Potion.confusion.getId()))
			mc.thePlayer.removePotionEffect(Potion.confusion.getId());

		if (mc.thePlayer.isPotionActive(Potion.digSlowdown.getId()))
			mc.thePlayer.removePotionEffect(Potion.digSlowdown.getId());
		if (mc.thePlayer.isBurning() && mc.thePlayer.isCollidedVertically) {
			for (int x = 0; x < 12; x++) {
				mc.getNetHandler().addToSendQueue(new C03PacketPlayer(true));
			}
		}
		final Potion[] potionTypes;
		for (int length = (potionTypes = Potion.potionTypes).length, i = 0; i < length; i++) {
			final Potion potion = potionTypes[i];
			if (Objects.nonNull(potion) && potion.isBadEffect() && mc.thePlayer.isPotionActive(potion)) {
				final PotionEffect effect = mc.thePlayer.getActivePotionEffect(potion);
				for (int x = 0; x < effect.getDuration() / 20; x++) {
					mc.getNetHandler().addToSendQueue(new C03PacketPlayer());
				}
			}
		}
	}
}
