package hmggirlfront.potion;

import net.minecraft.entity.EntityLivingBase;
import net.minecraft.init.MobEffects;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.DamageSource;
import net.minecraft.util.text.TextComponentString;

import javax.annotation.Nonnull;

import hmggirlfront.mod_GirlFront;

public class Collapse_Potion extends Potion{
    public Collapse_Potion(){
        super(false, 0xFFFFFF);
        setPotionName("effect.collapse_potion");/*Potionの内部名を指定*/
        this.setRegistryName(mod_GirlFront.MOD_ID, "collapse_potion");
    }

    @Override
    public void performEffect(@Nonnull EntityLivingBase entityLivingBaseIn, int p_76394_2_){
        //entityLivingBaseIn.sendMessage(new TextComponentString("You Are Performed"));
    	entityLivingBaseIn.attackEntityFrom(DamageSource.WITHER, 1.0F);
    	if (entityLivingBaseIn.getHealth() < entityLivingBaseIn.getMaxHealth() / 4)
        {
    		entityLivingBaseIn.addPotionEffect(
					new PotionEffect(MobEffects.SLOWNESS, 600, 4, true, true));
    		entityLivingBaseIn.addPotionEffect(
					new PotionEffect(mod_GirlFront.collapse_potion, 600, 2, true, true));
        }
    	else if (entityLivingBaseIn.getHealth() < entityLivingBaseIn.getMaxHealth() / 2)
        {
    		entityLivingBaseIn.addPotionEffect(
					new PotionEffect(MobEffects.SLOWNESS, 600, 2, true, true));
    		entityLivingBaseIn.addPotionEffect(
					new PotionEffect(mod_GirlFront.collapse_potion, 600, 1, true, true));
        }else {
        	entityLivingBaseIn.addPotionEffect(
					new PotionEffect(MobEffects.SLOWNESS, 600, 0, true, true));
        }
    }

    @Override
    public boolean isInstant(){
        return true;
    }

    @Override
    public boolean isReady(int duration, int amplifier){
    	if(duration > 1) {
    		int j = 20 >> amplifier;
            if (j > 0)
            {
                return duration % j == 0;
            }
            else
            {
                return true;
            }
    	}else if(duration > 0) {
    		int j = 400 >> amplifier;
            if (j > 0)
            {
                return duration % j == 0;
            }
            else
            {
                return true;
            }
    	}
    	else {
    		int j = 600 >> amplifier;
            if (j > 0)
            {
                return duration % j == 0;
            }
            else
            {
                return true;
            }
    	}
    }

    /*
    ポーションのアイコンを表示する際に実装する。
    @Override
    public int getStatusIconIndex(){
        //Minecraft.getMinecraft().getTextureManager().bindTexture(new ResourceLocation("textures/gui/container/inventory.png"));//ポーションのアイコンのテクスチャの場所を指定する。
        return super.getStatusIconIndex();
    }

    @Override
    public boolean hasStatusIcon(){
        return true;
    }
    */
}