package net.mcreator.gts.procedures;

import net.minecraft.world.phys.Vec3;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Entity;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.CommandSource;

import net.mcreator.gts.entity.AraEntity;
import net.mcreator.gts.GtsMod;

public class PlayerStruggleAraActionProcedure {
	public static void execute(LevelAccessor world, Entity entity, Entity sourceentity) {
		if (entity == null || sourceentity == null)
			return;
		if (entity instanceof Mob _mobSetNoAi) {
			_mobSetNoAi.setNoAi(true);
		}
		entity.setDeltaMovement(new Vec3(0, 0, 0));
		if (entity instanceof AraEntity _datEntSetS)
			_datEntSetS.getEntityData().set(AraEntity.DATA_AnimationDecision, ((entity instanceof AraEntity _datEntS ? _datEntS.getEntityData().get(AraEntity.DATA_AnimationDecision) : "").equals("Ara.LowNom1")
					|| (entity instanceof AraEntity _datEntS ? _datEntS.getEntityData().get(AraEntity.DATA_AnimationDecision) : "").equals("Ara.LowAtk2") ? "Ara.PreyEscape2" : "Ara.PreyEscape"));
		entity.getPersistentData().putBoolean("ThrowingTarget", true);
		sourceentity.stopRiding();
		entity.getPersistentData().putBoolean("CanBeFriend", false);
		{
			Entity _ent = sourceentity;
			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), "/stopsound @a[distance=..10] * gts:toki.lick");
			}
		}
		if (world instanceof ServerLevel _level)
			_level.sendParticles(ParticleTypes.ANGRY_VILLAGER, (entity.getX()),
					(entity.getY() + (entity instanceof LivingEntity _livingEntity11 && _livingEntity11.getAttributes().hasAttribute(Attributes.SCALE) ? _livingEntity11.getAttribute(Attributes.SCALE).getBaseValue() : 0) * 2), (entity.getZ()),
					(int) ((entity instanceof LivingEntity _livingEntity16 && _livingEntity16.getAttributes().hasAttribute(Attributes.SCALE) ? _livingEntity16.getAttribute(Attributes.SCALE).getBaseValue() : 0) * 10),
					((entity instanceof LivingEntity _livingEntity13 && _livingEntity13.getAttributes().hasAttribute(Attributes.SCALE) ? _livingEntity13.getAttribute(Attributes.SCALE).getBaseValue() : 0) / 2),
					((entity instanceof LivingEntity _livingEntity14 && _livingEntity14.getAttributes().hasAttribute(Attributes.SCALE) ? _livingEntity14.getAttribute(Attributes.SCALE).getBaseValue() : 0) / 2),
					((entity instanceof LivingEntity _livingEntity15 && _livingEntity15.getAttributes().hasAttribute(Attributes.SCALE) ? _livingEntity15.getAttribute(Attributes.SCALE).getBaseValue() : 0) / 2), 0);
		GtsMod.queueServerWork(35, () -> {
			if (entity.isAlive()) {
				if (entity instanceof AraEntity _datEntSetS)
					_datEntSetS.getEntityData().set(AraEntity.DATA_AnimationDecision, "empty");
				entity.setDeltaMovement(new Vec3(0, 0, 0));
				if (entity instanceof Mob _mobSetNoAi) {
					_mobSetNoAi.setNoAi(false);
				}
				entity.getPersistentData().putBoolean("AttackCheck", false);
			}
		});
	}
}
