package studio.halbear.hem.procedures;

import studio.halbear.hem.particle.LavenderParticlesParticle;
import studio.halbear.hem.HemMod;

import net.minecraft.world.server.ServerWorld;
import net.minecraft.world.IWorld;
import net.minecraft.entity.Entity;

import java.util.Map;

public class BlueleafLavenderMobplayerCollidesWithPlantProcedure {

	public static void executeProcedure(Map<String, Object> dependencies) {
		if (dependencies.get("world") == null) {
			if (!dependencies.containsKey("world"))
				HemMod.LOGGER.warn("Failed to load dependency world for procedure BlueleafLavenderMobplayerCollidesWithPlant!");
			return;
		}
		if (dependencies.get("x") == null) {
			if (!dependencies.containsKey("x"))
				HemMod.LOGGER.warn("Failed to load dependency x for procedure BlueleafLavenderMobplayerCollidesWithPlant!");
			return;
		}
		if (dependencies.get("y") == null) {
			if (!dependencies.containsKey("y"))
				HemMod.LOGGER.warn("Failed to load dependency y for procedure BlueleafLavenderMobplayerCollidesWithPlant!");
			return;
		}
		if (dependencies.get("z") == null) {
			if (!dependencies.containsKey("z"))
				HemMod.LOGGER.warn("Failed to load dependency z for procedure BlueleafLavenderMobplayerCollidesWithPlant!");
			return;
		}
		if (dependencies.get("entity") == null) {
			if (!dependencies.containsKey("entity"))
				HemMod.LOGGER.warn("Failed to load dependency entity for procedure BlueleafLavenderMobplayerCollidesWithPlant!");
			return;
		}
		IWorld world = (IWorld) dependencies.get("world");
		double x = dependencies.get("x") instanceof Integer ? (int) dependencies.get("x") : (double) dependencies.get("x");
		double y = dependencies.get("y") instanceof Integer ? (int) dependencies.get("y") : (double) dependencies.get("y");
		double z = dependencies.get("z") instanceof Integer ? (int) dependencies.get("z") : (double) dependencies.get("z");
		Entity entity = (Entity) dependencies.get("entity");
		double zv = 0;
		double xv = 0;
		xv = (entity.getMotion().getX());
		zv = (entity.getMotion().getZ());
		if (entity.getMotion().getX() < 0) {
			xv = (xv * (-1));
		}
		if (entity.getMotion().getZ() < 0) {
			zv = (zv * (-1));
		}
		if (entity.isSprinting()) {
			xv = 0.15;
			zv = 0.15;
		}
		if (xv > 0.05 || zv > 0.05) {
			if (world instanceof ServerWorld) {
				((ServerWorld) world).spawnParticle(LavenderParticlesParticle.particle, x, (y + 1), z, (int) Math.round(20 * (xv + zv)), 1, 0.5, 1,
						0.1);
			}
		}
		if (entity.getMotion().getY() > 0.05) {
			if (world instanceof ServerWorld) {
				((ServerWorld) world).spawnParticle(LavenderParticlesParticle.particle, x, (y + 1), z, (int) 20, 1, 0.5, 1, 0.3);
			}
		}
	}
}
