/*
 * SPDX-FileCopyrightText: 2026 KOKA99CAB
 * SPDX-License-Identifier: LGPL-3.0-or-later
 */

package net.koka99cab.portals.registry;

import net.koka99cab.portals.PortalsMod;
import net.koka99cab.portals.block.OrePortalBlock;
import net.koka99cab.portals.portal.PortalFramePredicates;
import net.koka99cab.portals.world.ModDimensions;
import net.minecraft.core.Registry;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.Identifier;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.material.PushReaction;

public final class ModBlocks {
	public static final OrePortalBlock ORE_PORTAL = register("ore_portal", new OrePortalBlock(
			portalProperties("ore_portal"),
			ModDimensions.ORE_CAVES,
			Blocks.STONE,
			ParticleTypes.END_ROD
	));
	public static final OrePortalBlock OVERWORLD2_PORTAL = register("overworld2_portal", new OrePortalBlock(
			portalProperties("overworld2_portal"),
			ModDimensions.OVERWORLD2,
			Blocks.DIRT,
			state -> state.is(Blocks.DIRT) || state.is(Blocks.GRASS_BLOCK),
			ParticleTypes.HAPPY_VILLAGER
	));
	public static final OrePortalBlock SHEEP_LAND_PORTAL = register("sheep_land_portal", new OrePortalBlock(
			portalProperties("sheep_land_portal"),
			ModDimensions.SHEEP_LAND,
			Blocks.WHITE_WOOL,
			ParticleTypes.FIREWORK
	));
	public static final OrePortalBlock SKELETON_WASTE_PORTAL = register("skeleton_waste_portal", new OrePortalBlock(
			portalProperties("skeleton_waste_portal"),
			ModDimensions.SKELETON_WASTE,
			Blocks.BONE_BLOCK,
			ParticleTypes.SOUL_FIRE_FLAME
	));
	public static final OrePortalBlock PAINTED_CANYONS_PORTAL = register("painted_canyons_portal", new OrePortalBlock(
			portalProperties("painted_canyons_portal"),
			ModDimensions.PAINTED_CANYONS,
			Blocks.TERRACOTTA,
			PortalFramePredicates.TERRACOTTA,
			ParticleTypes.FLAME
	));

	private ModBlocks() {
	}

	public static void init() {
		PortalsMod.LOGGER.debug("Registered mod blocks");
	}

	private static <T extends Block> T register(String path, T block) {
		Identifier id = PortalsMod.id(path);
		return Registry.register(BuiltInRegistries.BLOCK, id, block);
	}

	private static BlockBehaviour.Properties portalProperties(String path) {
		return BlockBehaviour.Properties.of()
				.noCollision()
				.noOcclusion()
				.noLootTable()
				.lightLevel(state -> 8)
				.strength(-1.0F)
				.sound(SoundType.GLASS)
				.pushReaction(PushReaction.BLOCK)
				.setId(ResourceKey.create(Registries.BLOCK, PortalsMod.id(path)));
	}
}
