// How to import your own model and texture using Blender:
// Download/clone this repository: https://github.com/lax1dude/eagler-binary-tools
// Try to reduce face count as much as possible. Do this by applying the decimate modifier to your model. Do a planar decimate first, which can help without making too many obvious differences. Then, use a collapse decimate and keep decreasing the ratio till you can't bear to look at how bad your model is getting.
// Apply the triangulate modifier, this is because in eaglercraft's rendering pipeline quads and n-gons aren't real things.
// Here is where you'll either UV-unwrap your model and paint on it, or bake it. Either way, you need to get your shader into one texture file. (albedo/diffuse) (on texture size: every other mdl texture png is 256x256, so try to use that size)
// Use File -> Export -> Wavefront (.obj)
// In the export menu on the right, under Geometry, enable 'UV coordinates', 'Normals', 'Apply Modifiers' and disable everything else.
// Scroll down till you find the Materials category, and disable it.
// Select the eagler-binary-tools folder, and export to it.
// Open a command prompt / terminal in eagler-binary-tools
// To convert to an eaglercraft MDL, Run: java -jar EaglerBinaryTools.jar obj2mdl-1.8 MyModel.obj OutputModel.mdl true
// the 'true' at the end means enable exporting UVs
// Use https://base64.guru/converter/encode/image to convert both your mdl file and png texture file into data uris, and replace the data URIs in this file.
// change some names.


(function LoadSphereModel() {
    //MDL Registry Locations:
    // DefaultSkins.java (optional)
    // SkinPreviewRenderer.java (optional, and we don't yet have mixins)
    // SkinModel.java
    // HighPolySkin.java
    // RenderHighPoly.java (optional)
    
    const ResourceLocationClass = ModAPI.reflect.getClassByName("ResourceLocation").class;
    const ResourceLocationRaw = ModAPI.reflect.getClassByName("ResourceLocation").constructors.find(x=>x.length===1);
    const ResourceLocation = (x)=>ResourceLocationRaw(ModAPI.util.str(x));
    const Sphere$HighPolySkin = ModAPI.reflect.getClassByName("HighPolySkin").constructors[0](
        ModAPI.util.str("SPHERE"),
        5,
        ResourceLocation("eagler:mesh/Sphere.png"),
        ResourceLocation("eagler:mesh/Sphere.mdl"),
        null,
        null,
        ModAPI.array.object(ResourceLocationClass, 0),
        ModAPI.array.float(0),
        0.0,
        ResourceLocation("eagler:skins/01.default_steve.png")
    )

    const SkinModelRefClass = ModAPI.reflect.getClassByName("SkinModel");
    const Sphere$SkinModel = SkinModelRefClass.constructors.find(x=>x.length===4)(ModAPI.util.str("SPHERE"), 8, 8, Sphere$HighPolySkin);
    SkinModelRefClass.staticVariables.skinModels.data.push(Sphere$SkinModel);
    SkinModelRefClass.staticVariables.skinModelsByName.$put(ModAPI.util.str("SPHERE"), Sphere$HighPolySkin);

    const DefaultSkinsRefClass = ModAPI.reflect.getClassByName("DefaultSkins");
    const Sphere$DefaultSkin = DefaultSkinsRefClass.constructors[0](ModAPI.util.str("SPHERE"), 29, 29, ModAPI.util.str("SPHERE"), ResourceLocation("eagler:skins/01.default_steve.png"), Sphere$SkinModel); //name, id, id, name, location, model
    DefaultSkinsRefClass.staticVariables.defaultSkinsMap.data.push(Sphere$DefaultSkin);

    ModAPI.addEventListener("lib:asyncsink", async () => {
        // MODEL DATA HERE
        AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/eagler/mesh/Sphere.mdl", await (await fetch(`data:image/octet-stream;base64,[encoded data, 71268 characters]`)).arrayBuffer());
        // TEXTURE DATA HERE
        AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/eagler/mesh/Sphere.png", await (await fetch(`data:image/png;base64,[encoded data, 24004 characters]`)).arrayBuffer());
    });
})();