package studio.halbear.hem.procedures;

import studio.halbear.hem.block.BlueleafDirtBlockBlock;
import studio.halbear.hem.block.AntsBlock;
import studio.halbear.hem.block.AntHillBlock;
import studio.halbear.hem.HemMod;

import net.minecraft.world.IWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.ResourceLocation;
import net.minecraft.tags.BlockTags;
import net.minecraft.state.Property;
import net.minecraft.block.Blocks;
import net.minecraft.block.BlockState;

import java.util.Random;
import java.util.Map;

public class AntHillSpawnOnStructureInstanceGeneratedProcedure {

	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 AntHillSpawnOnStructureInstanceGenerated!");
			return;
		}
		if (dependencies.get("x") == null) {
			if (!dependencies.containsKey("x"))
				HemMod.LOGGER.warn("Failed to load dependency x for procedure AntHillSpawnOnStructureInstanceGenerated!");
			return;
		}
		if (dependencies.get("y") == null) {
			if (!dependencies.containsKey("y"))
				HemMod.LOGGER.warn("Failed to load dependency y for procedure AntHillSpawnOnStructureInstanceGenerated!");
			return;
		}
		if (dependencies.get("z") == null) {
			if (!dependencies.containsKey("z"))
				HemMod.LOGGER.warn("Failed to load dependency z for procedure AntHillSpawnOnStructureInstanceGenerated!");
			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");
		double Random = 0;
		world.setBlockState(new BlockPos(x, y + 1, z), AntHillBlock.block.getDefaultState(), 3);
		{
			BlockPos _bp = new BlockPos(x, y, z);
			BlockState _bs = BlueleafDirtBlockBlock.block.getDefaultState();
			BlockState _bso = world.getBlockState(_bp);
			for (Map.Entry<Property<?>, Comparable<?>> entry : _bso.getValues().entrySet()) {
				Property _property = _bs.getBlock().getStateContainer().getProperty(entry.getKey().getName());
				if (_property != null && _bs.get(_property) != null)
					try {
						_bs = _bs.with(_property, (Comparable) entry.getValue());
					} catch (Exception e) {
					}
			}
			world.setBlockState(_bp, _bs, 3);
		}
		if (Math.random() > 0.5 && BlockTags.getCollection().getTagByID(new ResourceLocation("forge:solid_block"))
				.contains((world.getBlockState(new BlockPos(x + 1, y, z))).getBlock())) {
			{
				BlockPos _bp = new BlockPos(x + 1, y, z);
				BlockState _bs = BlueleafDirtBlockBlock.block.getDefaultState();
				BlockState _bso = world.getBlockState(_bp);
				for (Map.Entry<Property<?>, Comparable<?>> entry : _bso.getValues().entrySet()) {
					Property _property = _bs.getBlock().getStateContainer().getProperty(entry.getKey().getName());
					if (_property != null && _bs.get(_property) != null)
						try {
							_bs = _bs.with(_property, (Comparable) entry.getValue());
						} catch (Exception e) {
						}
				}
				world.setBlockState(_bp, _bs, 3);
			}
			if (Math.random() > 0.5 && (world.getBlockState(new BlockPos(x + 1, y + 1, z))).getBlock() == Blocks.AIR) {
				{
					BlockPos _bp = new BlockPos(x + 1, y + 1, z);
					BlockState _bs = AntsBlock.block.getDefaultState();
					BlockState _bso = world.getBlockState(_bp);
					for (Map.Entry<Property<?>, Comparable<?>> entry : _bso.getValues().entrySet()) {
						Property _property = _bs.getBlock().getStateContainer().getProperty(entry.getKey().getName());
						if (_property != null && _bs.get(_property) != null)
							try {
								_bs = _bs.with(_property, (Comparable) entry.getValue());
							} catch (Exception e) {
							}
					}
					world.setBlockState(_bp, _bs, 3);
				}
			}
		}
		if (Math.random() > 0.5 && BlockTags.getCollection().getTagByID(new ResourceLocation("forge:solid_block"))
				.contains((world.getBlockState(new BlockPos(x - 1, y, z))).getBlock())) {
			{
				BlockPos _bp = new BlockPos(x - 1, y, z);
				BlockState _bs = BlueleafDirtBlockBlock.block.getDefaultState();
				BlockState _bso = world.getBlockState(_bp);
				for (Map.Entry<Property<?>, Comparable<?>> entry : _bso.getValues().entrySet()) {
					Property _property = _bs.getBlock().getStateContainer().getProperty(entry.getKey().getName());
					if (_property != null && _bs.get(_property) != null)
						try {
							_bs = _bs.with(_property, (Comparable) entry.getValue());
						} catch (Exception e) {
						}
				}
				world.setBlockState(_bp, _bs, 3);
			}
			if (Math.random() > 0.5 && (world.getBlockState(new BlockPos(x - 1, y + 1, z))).getBlock() == Blocks.AIR) {
				{
					BlockPos _bp = new BlockPos(x - 1, y + 1, z);
					BlockState _bs = AntsBlock.block.getDefaultState();
					BlockState _bso = world.getBlockState(_bp);
					for (Map.Entry<Property<?>, Comparable<?>> entry : _bso.getValues().entrySet()) {
						Property _property = _bs.getBlock().getStateContainer().getProperty(entry.getKey().getName());
						if (_property != null && _bs.get(_property) != null)
							try {
								_bs = _bs.with(_property, (Comparable) entry.getValue());
							} catch (Exception e) {
							}
					}
					world.setBlockState(_bp, _bs, 3);
				}
			}
		}
		if (Math.random() > 0.5 && BlockTags.getCollection().getTagByID(new ResourceLocation("forge:solid_block"))
				.contains((world.getBlockState(new BlockPos(x + 1, y, z - 1))).getBlock())) {
			{
				BlockPos _bp = new BlockPos(x + 1, y, z - 1);
				BlockState _bs = BlueleafDirtBlockBlock.block.getDefaultState();
				BlockState _bso = world.getBlockState(_bp);
				for (Map.Entry<Property<?>, Comparable<?>> entry : _bso.getValues().entrySet()) {
					Property _property = _bs.getBlock().getStateContainer().getProperty(entry.getKey().getName());
					if (_property != null && _bs.get(_property) != null)
						try {
							_bs = _bs.with(_property, (Comparable) entry.getValue());
						} catch (Exception e) {
						}
				}
				world.setBlockState(_bp, _bs, 3);
			}
			if (Math.random() > 0.5 && (world.getBlockState(new BlockPos(x + 1, y + 1, z - 1))).getBlock() == Blocks.AIR) {
				{
					BlockPos _bp = new BlockPos(x + 1, y + 1, z - 1);
					BlockState _bs = AntsBlock.block.getDefaultState();
					BlockState _bso = world.getBlockState(_bp);
					for (Map.Entry<Property<?>, Comparable<?>> entry : _bso.getValues().entrySet()) {
						Property _property = _bs.getBlock().getStateContainer().getProperty(entry.getKey().getName());
						if (_property != null && _bs.get(_property) != null)
							try {
								_bs = _bs.with(_property, (Comparable) entry.getValue());
							} catch (Exception e) {
							}
					}
					world.setBlockState(_bp, _bs, 3);
				}
			}
		}
		if (Math.random() > 0.5 && BlockTags.getCollection().getTagByID(new ResourceLocation("forge:solid_block"))
				.contains((world.getBlockState(new BlockPos(x + 1, y, z + 1))).getBlock())) {
			{
				BlockPos _bp = new BlockPos(x + 1, y, z + 1);
				BlockState _bs = BlueleafDirtBlockBlock.block.getDefaultState();
				BlockState _bso = world.getBlockState(_bp);
				for (Map.Entry<Property<?>, Comparable<?>> entry : _bso.getValues().entrySet()) {
					Property _property = _bs.getBlock().getStateContainer().getProperty(entry.getKey().getName());
					if (_property != null && _bs.get(_property) != null)
						try {
							_bs = _bs.with(_property, (Comparable) entry.getValue());
						} catch (Exception e) {
						}
				}
				world.setBlockState(_bp, _bs, 3);
			}
			if (Math.random() > 0.5 && (world.getBlockState(new BlockPos(x + 1, y + 1, z + 1))).getBlock() == Blocks.AIR) {
				{
					BlockPos _bp = new BlockPos(x + 1, y + 1, z + 1);
					BlockState _bs = AntsBlock.block.getDefaultState();
					BlockState _bso = world.getBlockState(_bp);
					for (Map.Entry<Property<?>, Comparable<?>> entry : _bso.getValues().entrySet()) {
						Property _property = _bs.getBlock().getStateContainer().getProperty(entry.getKey().getName());
						if (_property != null && _bs.get(_property) != null)
							try {
								_bs = _bs.with(_property, (Comparable) entry.getValue());
							} catch (Exception e) {
							}
					}
					world.setBlockState(_bp, _bs, 3);
				}
			}
		}
		if (Math.random() > 0.5 && BlockTags.getCollection().getTagByID(new ResourceLocation("forge:solid_block"))
				.contains((world.getBlockState(new BlockPos(x - 1, y, z + 1))).getBlock())) {
			{
				BlockPos _bp = new BlockPos(x - 1, y, z + 1);
				BlockState _bs = BlueleafDirtBlockBlock.block.getDefaultState();
				BlockState _bso = world.getBlockState(_bp);
				for (Map.Entry<Property<?>, Comparable<?>> entry : _bso.getValues().entrySet()) {
					Property _property = _bs.getBlock().getStateContainer().getProperty(entry.getKey().getName());
					if (_property != null && _bs.get(_property) != null)
						try {
							_bs = _bs.with(_property, (Comparable) entry.getValue());
						} catch (Exception e) {
						}
				}
				world.setBlockState(_bp, _bs, 3);
			}
			if (Math.random() > 0.5 && (world.getBlockState(new BlockPos(x - 1, y + 1, z + 1))).getBlock() == Blocks.AIR) {
				{
					BlockPos _bp = new BlockPos(x - 1, y + 1, z + 1);
					BlockState _bs = AntsBlock.block.getDefaultState();
					BlockState _bso = world.getBlockState(_bp);
					for (Map.Entry<Property<?>, Comparable<?>> entry : _bso.getValues().entrySet()) {
						Property _property = _bs.getBlock().getStateContainer().getProperty(entry.getKey().getName());
						if (_property != null && _bs.get(_property) != null)
							try {
								_bs = _bs.with(_property, (Comparable) entry.getValue());
							} catch (Exception e) {
							}
					}
					world.setBlockState(_bp, _bs, 3);
				}
			}
		}
		if (Math.random() > 0.5 && BlockTags.getCollection().getTagByID(new ResourceLocation("forge:solid_block"))
				.contains((world.getBlockState(new BlockPos(x, y, z + 1))).getBlock())) {
			{
				BlockPos _bp = new BlockPos(x, y, z + 1);
				BlockState _bs = BlueleafDirtBlockBlock.block.getDefaultState();
				BlockState _bso = world.getBlockState(_bp);
				for (Map.Entry<Property<?>, Comparable<?>> entry : _bso.getValues().entrySet()) {
					Property _property = _bs.getBlock().getStateContainer().getProperty(entry.getKey().getName());
					if (_property != null && _bs.get(_property) != null)
						try {
							_bs = _bs.with(_property, (Comparable) entry.getValue());
						} catch (Exception e) {
						}
				}
				world.setBlockState(_bp, _bs, 3);
			}
			if (Math.random() > 0.5 && (world.getBlockState(new BlockPos(x, y + 1, z + 1))).getBlock() == Blocks.AIR) {
				{
					BlockPos _bp = new BlockPos(x, y + 1, z + 1);
					BlockState _bs = AntsBlock.block.getDefaultState();
					BlockState _bso = world.getBlockState(_bp);
					for (Map.Entry<Property<?>, Comparable<?>> entry : _bso.getValues().entrySet()) {
						Property _property = _bs.getBlock().getStateContainer().getProperty(entry.getKey().getName());
						if (_property != null && _bs.get(_property) != null)
							try {
								_bs = _bs.with(_property, (Comparable) entry.getValue());
							} catch (Exception e) {
							}
					}
					world.setBlockState(_bp, _bs, 3);
				}
			}
		}
		if (Math.random() > 0.5 && BlockTags.getCollection().getTagByID(new ResourceLocation("forge:solid_block"))
				.contains((world.getBlockState(new BlockPos(x, y, z - 1))).getBlock())) {
			{
				BlockPos _bp = new BlockPos(x, y, z - 1);
				BlockState _bs = BlueleafDirtBlockBlock.block.getDefaultState();
				BlockState _bso = world.getBlockState(_bp);
				for (Map.Entry<Property<?>, Comparable<?>> entry : _bso.getValues().entrySet()) {
					Property _property = _bs.getBlock().getStateContainer().getProperty(entry.getKey().getName());
					if (_property != null && _bs.get(_property) != null)
						try {
							_bs = _bs.with(_property, (Comparable) entry.getValue());
						} catch (Exception e) {
						}
				}
				world.setBlockState(_bp, _bs, 3);
			}
			if (Math.random() > 0.5 && (world.getBlockState(new BlockPos(x, y + 1, z - 1))).getBlock() == Blocks.AIR) {
				{
					BlockPos _bp = new BlockPos(x, y + 1, z - 1);
					BlockState _bs = AntsBlock.block.getDefaultState();
					BlockState _bso = world.getBlockState(_bp);
					for (Map.Entry<Property<?>, Comparable<?>> entry : _bso.getValues().entrySet()) {
						Property _property = _bs.getBlock().getStateContainer().getProperty(entry.getKey().getName());
						if (_property != null && _bs.get(_property) != null)
							try {
								_bs = _bs.with(_property, (Comparable) entry.getValue());
							} catch (Exception e) {
							}
					}
					world.setBlockState(_bp, _bs, 3);
				}
			}
		}
	}
}
