package net.mcreator.azertymod.procedures;

import net.minecraft.world.World;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.item.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.Entity;

import net.mcreator.azertymod.AzertymodVariables;
import net.mcreator.azertymod.AzertymodElements;

@AzertymodElements.ModElement.Tag
public class CoalGeneratorRightClickedProcedure extends AzertymodElements.ModElement {
	public CoalGeneratorRightClickedProcedure(AzertymodElements instance) {
		super(instance, 41);
	}

	public static void executeProcedure(java.util.HashMap<String, Object> dependencies) {
		if (dependencies.get("entity") == null) {
			System.err.println("Failed to load dependency entity for procedure CoalGeneratorRightClicked!");
			return;
		}
		if (dependencies.get("world") == null) {
			System.err.println("Failed to load dependency world for procedure CoalGeneratorRightClicked!");
			return;
		}
		Entity entity = (Entity) dependencies.get("entity");
		World world = (World) dependencies.get("world");
		double energy_gived = 0;
		if (((entity instanceof PlayerEntity) ? ((PlayerEntity) entity).inventory.hasItemStack(new ItemStack(Items.COAL, (int) (1))) : false)) {
			if (entity instanceof PlayerEntity)
				((PlayerEntity) entity).inventory.clearMatchingItems(p -> new ItemStack(Items.COAL, (int) (1)).getItem() == p.getItem(), (int) 1);
			energy_gived = (double) 2;
		} else if (((entity instanceof PlayerEntity)
				? ((PlayerEntity) entity).inventory.hasItemStack(new ItemStack(Items.CHARCOAL, (int) (1)))
				: false)) {
			if (entity instanceof PlayerEntity)
				((PlayerEntity) entity).inventory.clearMatchingItems(p -> new ItemStack(Items.CHARCOAL, (int) (1)).getItem() == p.getItem(), (int) 1);
			energy_gived = (double) 1;
		}
		if (((AzertymodVariables.MapVariables.get(world).Energy) < (AzertymodVariables.MapVariables.get(world).Max_energy))) {
			AzertymodVariables.MapVariables.get(world).Energy = (double) ((AzertymodVariables.MapVariables.get(world).Energy) + (energy_gived));
			AzertymodVariables.MapVariables.get(world).syncData(world);
		}
		if (entity instanceof PlayerEntity && !world.isRemote) {
			((PlayerEntity) entity).sendStatusMessage(new StringTextComponent(
					"un de charbon(+2 energie) ou un de charcoal(+1 energie) a \u00E9t\u00E9 retir\u00E9 de votre inventaire."), (false));
		}
	}
}
