
/*
 *	MCreator note: This file will be REGENERATED on each build.
 */
package net.mcreator.puzzle_code.init;

import net.neoforged.neoforge.registries.DeferredRegister;
import net.neoforged.neoforge.registries.DeferredHolder;
import net.neoforged.neoforge.event.entity.living.MobEffectEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.bus.api.SubscribeEvent;

import net.minecraft.world.entity.Entity;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.core.registries.Registries;

import net.mcreator.puzzle_code.procedures.YellowSwicherPotionPotionExpiresProcedure;
import net.mcreator.puzzle_code.potion.YellowSwitcherEffectMobEffect;
import net.mcreator.puzzle_code.PuzzleCodeMod;

@EventBusSubscriber
public class PuzzleCodeModMobEffects {
	public static final DeferredRegister<MobEffect> REGISTRY = DeferredRegister.create(Registries.MOB_EFFECT, PuzzleCodeMod.MODID);
	public static final DeferredHolder<MobEffect, MobEffect> YELLOW_SWITCHER_EFFECT = REGISTRY.register("yellow_switcher_effect", () -> new YellowSwitcherEffectMobEffect());

	@SubscribeEvent
	public static void onEffectRemoved(MobEffectEvent.Remove event) {
		MobEffectInstance effectInstance = event.getEffectInstance();
		if (effectInstance != null) {
			expireEffects(event.getEntity(), effectInstance);
		}
	}

	@SubscribeEvent
	public static void onEffectExpired(MobEffectEvent.Expired event) {
		MobEffectInstance effectInstance = event.getEffectInstance();
		if (effectInstance != null) {
			expireEffects(event.getEntity(), effectInstance);
		}
	}

	private static void expireEffects(Entity entity, MobEffectInstance effectInstance) {
		if (effectInstance.getEffect().is(YELLOW_SWITCHER_EFFECT)) {
			YellowSwicherPotionPotionExpiresProcedure.execute(entity.level(), entity);
		}
	}
}
