import groovy.json.JsonSlurper

def getCurrentNeoFormVersion() {
    try {
        //def url = "https://maven.neoforged.net/api/maven/versions/releases/net/neoforged/neoform"
        //def connection = new URL(url).openConnection()
        def neoformInfo = new JsonSlurper().parse('{"isSnapshot":false,"versions":["23w31a","23w31a-20230819.124900","23w31a-20230821.183055","23w35a-20230904.052148","23w40a-20231004.201141","23w41a-20231011.152916","23w41a-20231012.060129","23w42a-20231019.115212","23w43a-20231025.230911","23w43b-20231027.135351","23w43b-20231030.123645","23w44a-20231101.212121","23w44a-20231106.084427","23w45a-20231108.200637","23w46a-20231116.200556","23w51b-20231218.231938","24w03a-20240117.195924","24w03b-20240118.152320","24w04a-20240124.191741","24w05a-20240131.192805","24w05b-20240201.180014","24w06a-20240207.194656","24w07a-20240214.192032","24w09a-20240228.211338","24w09a-20240301.223831","24w09a-20240301.230237","24w10a-20240306.184744","24w11a-20240314.182754","24w12a-20240320.193028","24w13a-20240327.214511","24w13a-20240328.090800","24w14a-20240403.231702","24w14a-20240404.210202","24w14potato-20240402.092655","24w18a-20240503.140846","24w18a-20240505.002829","24w19b-20240510.192321","24w19b-20240510.193815","24w20a-20240515.145429","24w21b-20240522.183735","24w33a-20240815.224454","24w33a-20240815.230140","24w34a-20240821.154014","24w35a-20240828.142833","24w36a-20240904.161315","24w37a-20240911.160200","24w38a-20240918.141527","24w39a-20240925.144208","24w40a-20241002.160403","24w40a-20241003.090628","24w44a-20241030.150733","24w45a-20241106.164605","24w45a-20241108.004252","24w46a-20241113.151339","25w02a-20250108.170748","25w03a-20250115.171843","25w04a-20250122.170856","25w05a-20250129.194425","25w06a-20250205.211553","25w07a-20250213.224422","25w08a-20250219.192734","25w08a-20250225.043121","25w09a-20250306.053033","25w10a-20250306.063306","25w14craftmine-20250401.222524","25w15a-20250409.133102","25w16a-20250415.160549","25w17a-20250422.141904","25w18a-20250429.152506","25w19a-20250506.211641","25w20a-20250513.154825","25w21a-20250520.151337","1.20.2-pre1-20230905.210113","1.20.2-pre2-20230907.214658","1.20.2-pre3-20230912.140230","1.20.2-pre4-20230913.163358","1.20.2-pre4-20230915.113655","1.20.2-rc1-20230916.093259","1.20.2-rc1-20230917.092859","1.20.2-rc2-20230918.142702","1.20.2-rc2-20230920.055723","1.20.2-20230921.152923","1.20.2-20231016.095323","1.20.2-20231019.002635","1.20.2-20241215.201144","1.20.3-pre1-20231120.191647","1.20.3-pre2-20231122.210419","1.20.3-pre3-20231127.162425","1.20.3-pre4-20231128.162426","1.20.3-rc1-20231130.162433","1.20.3-20231205.165107","1.20.3-20241215.201103","1.20.4-rc1-20231206.173914","1.20.4-20231207.154220","1.20.4-20240627.114801","1.20.5-pre1-20240410.221336","1.20.5-pre2-20240415.193619","1.20.5-pre3-20240416.143558","1.20.5-pre3-20240416.195750","1.20.5-pre4-20240417.132209","1.20.5-rc1-20240418.140438","1.20.5-rc2-20240419.190916","1.20.5-rc3-20240422.190215","1.20.5-20240423.152201","1.20.5-20241215.200814","1.20.6-rc1-20240426.131110","1.20.6-20240429.153634","1.20.6-20240627.102356","1.21-pre1-20240529.150918","1.21-pre2-20240531.135455","1.21-pre3-20240605.103358","1.21-pre4-20240607.124751","1.21-rc1-20240610.133618","1.21.1-rc1-20240807.154857","1.21.1-rc1-20240808.070105","1.21.1-20240808.144430","1.21.2-pre1-20241008.174159","1.21.2-pre2-20241010.184220","1.21.2-pre3-20241011.133721","1.21.2-pre4-20241015.133858","1.21.2-pre5-20241016.141407","1.21.2-rc1-20241017.134216","1.21.2-rc2-20241021.191555","1.21.2-20241022.151510","1.21.3-20241023.131943","1.21.4-pre1-20241120.190508","1.21.4-pre2-20241125.183520","1.21.4-pre3-20241126.155511","1.21.4-pre3-20241126.155528","1.21.4-rc1-20241128.151559","1.21.4-rc1-20241128.151641","1.21.4-rc2-20241129.121625","1.21.4-rc3-20241129.173716","1.21.4-20241203.161809","1.21.5-pre1-20250311.214426","1.21.5-pre2-20250312.185155","1.21.5-pre3-20250318.212332","1.21.5-rc1-20250320.202415","1.21.5-rc2-20250324.142238","1.21.5-20250325.162830","1.21.6-pre1-20250528.104215","1.21.6-pre2-20250602.144525","1.21.6-pre3-20250604.141722","1.21.6-pre4-20250610.130131","1.21.6-pre4-20250611.141253","1.21.6-rc1-20250612.132412","1.21.6-rc1-20250616.124039","1.21.6-20250617.151856","1.21.7-rc1-20250625.154307","1.21.7-rc2-20250626.145635","1.21.7-20250630.141722","1.21-20240613.152323"]}'.toCharArray()).versions
        for (String ver : neoformInfo) {
            if (ver.split("-").length < 2) continue;
            def mcVer = ver.split("-").toList().subList(0, ver.split("-").length - 1).join("-")
            if (mcVer.equals(getCurrentVersionConfig().common.minecraftVersion)) {
                return ver
            }
        }
    } catch (Exception e) {
        e.printStackTrace()
    }
    println("❌️ 无法获取NeoForm版本")
    throw new GradleException("无法获取NeoForm版本")

}

ext.getCurrentNeoFormVersion = this.&getCurrentNeoFormVersion