package net.mattias.marloevillages.registry;

import net.mattias.marloevillages.MarloeVillages;
import net.minecraft.core.Holder;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.levelgen.structure.pools.LegacySinglePoolElement;
import net.minecraft.world.level.levelgen.structure.pools.StructurePoolElement;
import net.minecraft.world.level.levelgen.structure.pools.StructureTemplatePool;
import net.mattias.marloevillages.util.ModConstants;

import java.util.List;

public class ModStructurePools {
    public static void register() {
        modifyPlainsVillage();
    }

    private static void modifyPlainsVillage() {
        // 1. Get the vanilla plains village pool from the CORRECT registry
        ResourceLocation poolLocation = new ResourceLocation("minecraft:village/plains/houses");
        StructureTemplatePool originalPool = BuiltInRegistries.STRUCTURE_POOL.get(poolLocation); // Fixed: Use STRUCTURE_POOL, not STRUCTURE_POOL_ELEMENT

        if (originalPool == null) {
            MarloeVillages.LOGGER.error("Vanilla plains village pool not found!");
            return;
        }

        // 2. Define custom structure elements with proper builder methods
        List<StructurePoolElement> customElements = List.of(
                // Use LegacySinglePoolElement.builder() to ensure correct method chaining
                LegacySinglePoolElement.builder(
                                new ResourceLocation(ModConstants.MOD_ID, "village/plains/marloe_house_1")
                        )
                        .projection(StructureTemplatePool.Projection.RIGID)
                        .weight(5)
                        .build(),
                LegacySinglePoolElement.builder(
                                new ResourceLocation(ModConstants.MOD_ID, "village/plains/marloe_house_2")
                        )
                        .projection(StructureTemplatePool.Projection.RIGID)
                        .weight(3)
                        .build()
        );

        // 3. Create modified pool with the correct constructor parameters
        Holder<StructureTemplatePool> fallback = originalPool.getFallback(); // Fallback is a Holder, not a ResourceLocation
        StructureTemplatePool modifiedPool = new StructureTemplatePool(
                poolLocation,       // Pool name (same as vanilla to override)
                fallback,           // Keep vanilla fallback pool
                customElements,     // Your custom structures
                StructureTemplatePool.Projection.RIGID // Projection type
        );

        // 4. Register the modified pool to the CORRECT registry
        BuiltInRegistries.STRUCTURE_POOL.register(poolLocation, modifiedPool); // Fixed: Use STRUCTURE_POOL registry
        MarloeVillages.LOGGER.info("Replaced vanilla plains village pool with custom structures!");
    }
}
Cannot resolve symbol 'STRUCTURE_POOL'
Cannot resolve method 'builder' in 'LegacySinglePoolElement'
Cannot resolve method 'builder' in 'LegacySinglePoolElement'
Cannot resolve constructor 'StructureTemplatePool(ResourceLocation, Holder<StructureTemplatePool>, List<StructurePoolElement>, Projection)'
Cannot resolve symbol 'STRUCTURE_POOL'