package net.mcreator.cawezsmantletostratus.procedures;

import net.minecraft.world.item.ItemStack;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.util.RandomSource;
import net.minecraft.util.Mth;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.CommandSource;

import net.mcreator.cawezsmantletostratus.network.CawezsMantleToStratusModVariables;
import net.mcreator.cawezsmantletostratus.init.CawezsMantleToStratusModItems;

public class EssenceInventoryProcedure {
	public static void execute(Entity entity, ItemStack itemstack) {
		if (entity == null)
			return;
		double hp_count = 0;
		if (itemstack.getItem() == CawezsMantleToStratusModItems.ESSENCE_OVERGROWTH.get()) {
			{
				CawezsMantleToStratusModVariables.PlayerVariables _vars = entity.getData(CawezsMantleToStratusModVariables.PLAYER_VARIABLES);
				_vars.HP_0 = true;
				_vars.syncPlayerVariables(entity);
			}
		} else if (itemstack.getItem() == CawezsMantleToStratusModItems.ESSENCE_STORM.get()) {
			{
				CawezsMantleToStratusModVariables.PlayerVariables _vars = entity.getData(CawezsMantleToStratusModVariables.PLAYER_VARIABLES);
				_vars.HP_1 = true;
				_vars.syncPlayerVariables(entity);
			}
		} else if (itemstack.getItem() == CawezsMantleToStratusModItems.ESSENCE_GLOOM.get()) {
			{
				CawezsMantleToStratusModVariables.PlayerVariables _vars = entity.getData(CawezsMantleToStratusModVariables.PLAYER_VARIABLES);
				_vars.HP_2 = true;
				_vars.syncPlayerVariables(entity);
			}
		} else if (itemstack.getItem() == CawezsMantleToStratusModItems.ESSENCE_AERIS.get()) {
			{
				CawezsMantleToStratusModVariables.PlayerVariables _vars = entity.getData(CawezsMantleToStratusModVariables.PLAYER_VARIABLES);
				_vars.HP_3 = true;
				_vars.syncPlayerVariables(entity);
			}
		} else if (itemstack.getItem() == CawezsMantleToStratusModItems.ESSENCE_GRIMSTONE.get()) {
			{
				CawezsMantleToStratusModVariables.PlayerVariables _vars = entity.getData(CawezsMantleToStratusModVariables.PLAYER_VARIABLES);
				_vars.HP_4 = true;
				_vars.syncPlayerVariables(entity);
			}
		} else if (itemstack.getItem() == CawezsMantleToStratusModItems.ESSENCE_ICHOR.get()) {
			{
				CawezsMantleToStratusModVariables.PlayerVariables _vars = entity.getData(CawezsMantleToStratusModVariables.PLAYER_VARIABLES);
				_vars.HP_5 = true;
				_vars.syncPlayerVariables(entity);
			}
		}
		if (entity.getData(CawezsMantleToStratusModVariables.PLAYER_VARIABLES).HP_0) {
			hp_count = hp_count + 1;
		}
		if (entity.getData(CawezsMantleToStratusModVariables.PLAYER_VARIABLES).HP_1) {
			hp_count = hp_count + 1;
		}
		if (entity.getData(CawezsMantleToStratusModVariables.PLAYER_VARIABLES).HP_2) {
			hp_count = hp_count + 1;
		}
		if (entity.getData(CawezsMantleToStratusModVariables.PLAYER_VARIABLES).HP_3) {
			hp_count = hp_count + 1;
		}
		if (entity.getData(CawezsMantleToStratusModVariables.PLAYER_VARIABLES).HP_4) {
			hp_count = hp_count + 1;
		}
		if (entity.getData(CawezsMantleToStratusModVariables.PLAYER_VARIABLES).HP_5) {
			hp_count = hp_count + 1;
		}
		if (Mth.nextInt(RandomSource.create(), 1, 200) == 2) {
			{
				CawezsMantleToStratusModVariables.PlayerVariables _vars = entity.getData(CawezsMantleToStratusModVariables.PLAYER_VARIABLES);
				_vars.HP_0 = false;
				_vars.syncPlayerVariables(entity);
			}
			{
				CawezsMantleToStratusModVariables.PlayerVariables _vars = entity.getData(CawezsMantleToStratusModVariables.PLAYER_VARIABLES);
				_vars.HP_1 = false;
				_vars.syncPlayerVariables(entity);
			}
			{
				CawezsMantleToStratusModVariables.PlayerVariables _vars = entity.getData(CawezsMantleToStratusModVariables.PLAYER_VARIABLES);
				_vars.HP_2 = false;
				_vars.syncPlayerVariables(entity);
			}
			{
				CawezsMantleToStratusModVariables.PlayerVariables _vars = entity.getData(CawezsMantleToStratusModVariables.PLAYER_VARIABLES);
				_vars.HP_3 = false;
				_vars.syncPlayerVariables(entity);
			}
			{
				CawezsMantleToStratusModVariables.PlayerVariables _vars = entity.getData(CawezsMantleToStratusModVariables.PLAYER_VARIABLES);
				_vars.HP_4 = false;
				_vars.syncPlayerVariables(entity);
			}
			{
				CawezsMantleToStratusModVariables.PlayerVariables _vars = entity.getData(CawezsMantleToStratusModVariables.PLAYER_VARIABLES);
				_vars.HP_5 = false;
				_vars.syncPlayerVariables(entity);
			}
		}
		if (1 == hp_count) {
			{
				Entity _ent = entity;
				if (!_ent.level().isClientSide() && _ent.getServer() != null) {
					_ent.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, _ent.position(), _ent.getRotationVector(), _ent.level() instanceof ServerLevel ? (ServerLevel) _ent.level() : null, 4,
							_ent.getName().getString(), _ent.getDisplayName(), _ent.level().getServer(), _ent), "/effect give @s minecraft:health_boost 1 0");
				}
			}
		} else if (2 == hp_count) {
			{
				Entity _ent = entity;
				if (!_ent.level().isClientSide() && _ent.getServer() != null) {
					_ent.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, _ent.position(), _ent.getRotationVector(), _ent.level() instanceof ServerLevel ? (ServerLevel) _ent.level() : null, 4,
							_ent.getName().getString(), _ent.getDisplayName(), _ent.level().getServer(), _ent), "/effect give @s minecraft:health_boost 1 1");
				}
			}
		} else if (3 == hp_count) {
			{
				Entity _ent = entity;
				if (!_ent.level().isClientSide() && _ent.getServer() != null) {
					_ent.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, _ent.position(), _ent.getRotationVector(), _ent.level() instanceof ServerLevel ? (ServerLevel) _ent.level() : null, 4,
							_ent.getName().getString(), _ent.getDisplayName(), _ent.level().getServer(), _ent), "/effect give @s minecraft:health_boost 1 2");
				}
			}
		} else if (4 == hp_count) {
			{
				Entity _ent = entity;
				if (!_ent.level().isClientSide() && _ent.getServer() != null) {
					_ent.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, _ent.position(), _ent.getRotationVector(), _ent.level() instanceof ServerLevel ? (ServerLevel) _ent.level() : null, 4,
							_ent.getName().getString(), _ent.getDisplayName(), _ent.level().getServer(), _ent), "/effect give @s minecraft:health_boost 1 3");
				}
			}
		} else if (5 == hp_count) {
			{
				Entity _ent = entity;
				if (!_ent.level().isClientSide() && _ent.getServer() != null) {
					_ent.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, _ent.position(), _ent.getRotationVector(), _ent.level() instanceof ServerLevel ? (ServerLevel) _ent.level() : null, 4,
							_ent.getName().getString(), _ent.getDisplayName(), _ent.level().getServer(), _ent), "/effect give @s minecraft:health_boost 1 4");
				}
			}
		} else if (6 == hp_count) {
			if (entity instanceof LivingEntity _entity && !_entity.level().isClientSide())
				_entity.addEffect(new MobEffectInstance(MobEffects.LUCK, 60, 5, false, false));
			{
				Entity _ent = entity;
				if (!_ent.level().isClientSide() && _ent.getServer() != null) {
					_ent.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, _ent.position(), _ent.getRotationVector(), _ent.level() instanceof ServerLevel ? (ServerLevel) _ent.level() : null, 4,
							_ent.getName().getString(), _ent.getDisplayName(), _ent.level().getServer(), _ent), "/effect give @s minecraft:health_boost 1 4");
				}
			}
		}
	}
}
