package net.pietru.omni_power.mixins;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import finalforeach.cosmicreach.GameAssetLoader;
import finalforeach.cosmicreach.blocks.BlockStateGenerator;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.List;

import static net.pietru.omni_power.OmniPower.MOD_ID;

@Mixin(BlockStateGenerator.class)
public class BlockStateGeneratorMixin {
    @Shadow
    private static void loadGeneratorsFromFile(FileHandle asset){}

    @Inject(method = "<clinit>()V", at = @At("TAIL"))
    private static void on_init_tail(CallbackInfo ci) {
        List<String> paths = List.of(Gdx.files.internal(MOD_ID + "/assets.txt").readString().split("\n"));
        for (String path : paths){
            if (path.contains("block_state_generators")) {
                System.out.println("Loading " + path);
                loadGeneratorsFromFile(GameAssetLoader.loadAsset(path));
            }
        }

        System.out.println("Registered OmniPower BlockStateGens");
    }
}
