Spaces:
Sleeping
Sleeping
Download native/main.cpp from cpuai/minecraft-file-converter: direct link, hf CLI and curl.
- Browser
- Download file 2.59 kB
-
https://huggingface.co/spaces/cpuai/minecraft-file-converter/resolve/main/native/main.cpp
- Command line
-
hf download hf://spaces/cpuai/minecraft-file-converter/native/main.cpp
-
curl -L -o main.cpp https://huggingface.co/spaces/cpuai/minecraft-file-converter/resolve/main/native/main.cpp
2.59 kB
| // SPDX-License-Identifier: GPL-3.0-or-later | |
| // 独立进程适配器:固定方向、全部原版维度,输出可解析的进度事件。 | |
| using namespace je2be; | |
| namespace fs=std::filesystem; | |
| std::mutex outputMutex; | |
| void emit(std::string phase, Rational<u64> const &p, u64 chunks=0) { | |
| std::lock_guard<std::mutex> lock(outputMutex); | |
| std::cout << nlohmann::json{{"phase",phase},{"done",p.fNum},{"total",p.fDen},{"chunks",chunks}}.dump() << std::endl; | |
| } | |
| struct JavaProgress:java::Progress { | |
| bool reportConvert(Rational<u64> const &p,u64 n) override {emit("convert",p,n);return true;} | |
| bool reportEntityPostProcess(Rational<u64> const &p) override {emit("entities",p);return true;} | |
| bool reportCompaction(Rational<u64> const &p) override {emit("compact",p);return true;} | |
| }; | |
| struct BedrockProgress:bedrock::Progress { | |
| bool reportConvert(Rational<u64> const &p,u64 n) override {emit("convert",p,n);return true;} | |
| bool reportTerraform(Rational<u64> const &p,u64 n) override {emit("terrain",p,n);return true;} | |
| }; | |
| int main(int argc,char **argv) { | |
| if(argc==2 && std::string(argv[1])=="--version") { | |
| std::cout << R"({"engine":"je2be-core","commit":"8dfc4de1ba5c7f72e804abea8663380c0dbd5680","java_target":"1.21.10","bedrock_target":"1.21.120"})" << std::endl; return 0; | |
| } | |
| if(argc!=5) {std::cerr<<"usage: worldbridge-native java|bedrock INPUT OUTPUT TEMP\n";return 2;} | |
| try { | |
| fs::path input(argv[2]),output(argv[3]),temp(argv[4]); | |
| if(!fs::is_directory(input)||fs::exists(output)) return 2; | |
| fs::create_directories(temp); | |
| Status status; | |
| if(std::string(argv[1])=="java") { | |
| java::Options options; options.fTempDirectory=temp; options.fDbTempDirectory=temp; | |
| JavaProgress progress;status=java::Converter::Run(input,output,options,2,&progress); | |
| } else if(std::string(argv[1])=="bedrock") { | |
| bedrock::Options options;options.fTempDirectory=temp; | |
| BedrockProgress progress;status=bedrock::Converter::Run(input,output,options,2,&progress); | |
| } else return 2; | |
| if(auto error=status.error();error) { | |
| nlohmann::json trace=nlohmann::json::array(); | |
| for(auto const &p:error->fTrace) trace.push_back(p.fFile+":"+std::to_string(p.fLine)); | |
| std::cout<<nlohmann::json{{"error",error->fWhat},{"trace",trace}}.dump()<<std::endl;return 1; | |
| } | |
| std::cout<<R"({"phase":"complete","done":1,"total":1})"<<std::endl;return 0; | |
| } catch(std::exception const &e) {std::cerr<<e.what()<<std::endl;return 1;} | |
| } | |