package net.mcreator.customoregen.event;

import net.neoforged.neoforge.event.level.BlockDropsEvent;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.Block;

import net.mcreator.customoregen.init.CustomOreGenModBlocks;
import net.mcreator.customoregen.procedures.ConfigurableOreDropsProcedure;

@EventBusSubscriber
public class OreBreakEventHandler {

	@SubscribeEvent
	public static void onBlockDrops(BlockDropsEvent event) {
		BlockState state = event.getState();
		Block block = state.getBlock();
		String oreType = getOreType(block);

		if (oreType != null) {
			// Item drops are now handled by CustomOreLootModifier (Global Loot Modifier)
			// to ensure compatibility with machines and avoid duplication.
			
			if (event.getBreaker() != null) {
				ConfigurableOreDropsProcedure.execute(event.getLevel(), event.getPos().getX(), event.getPos().getY(), event.getPos().getZ(), event.getBreaker(), oreType);
			}
		}
	}

	private static String getOreType(Block block) {
		if (block == CustomOreGenModBlocks.SHARDDIAMONDBLOCKORE.get() || block == CustomOreGenModBlocks.DEEPSLATESHARDDIAMONDORE.get()) return "shard_diamond";
		if (block == CustomOreGenModBlocks.CONCENTRATEDCOALORE.get()) return "concentrated_coal";
		if (block == CustomOreGenModBlocks.PUREGOLDENORE.get() || block == CustomOreGenModBlocks.DEEPSLATEPUREGOLDENORE.get()) return "pure_golden";
		if (block == CustomOreGenModBlocks.IRONORE.get() || block == CustomOreGenModBlocks.DEEPSLATEIRONORE.get()) return "impure_iron";
		if (block == CustomOreGenModBlocks.DEEPSLATEDIAMONDORE.get()) return "concentrated_diamond";
		if (block == CustomOreGenModBlocks.LAPISORE.get() || block == CustomOreGenModBlocks.DEEPSLATELAPISORE.get()) return "lapis";
		if (block == CustomOreGenModBlocks.REDSTONEORE.get() || block == CustomOreGenModBlocks.DEEPSLATEREDSTONEORE.get()) return "redstone";
		if (block == CustomOreGenModBlocks.HIGHEMERALDORE.get() || block == CustomOreGenModBlocks.LOWEREMERALDORE.get()) return "emerald";
		if (block == CustomOreGenModBlocks.COPPERHIGHORE.get() || block == CustomOreGenModBlocks.COPPERLOWERORE.get()) return "copper";
		return null;
	}
}
