package gvclib.item.gun;

import gvclib.item.ItemAttachment;
import gvclib.item.ItemGunBase;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.fml.loading.FMLLoader;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;

public class AttachmentBase_LoadStatus {

    public static void load(ItemAttachment gun, BufferedReader br, String domain, int id){
        try {
            {
                String str;
                while ((str = br.readLine()) != null) { // 1行ずつ読み込む
                    // System.out.println(str);
                    String[] type = str.split(",");

                    int guntype = 0;

                    if (type.length != 0) {// 1

                        /*for(int xxxx = 0; xxxx < 100; ++xxxx){
                            System.out.println(String.format("gun_road"));
                        }*/

                        gun.id = id;


                        if (FMLLoader.getDist().isClient()) {
                            /*for(int xxxx = 0; xxxx < 100; ++xxxx){
                                System.out.println(String.format("model_road"));
                            }*/
                            if (type[0].equals("ObjModel")) {
                            //    gun.obj_model = AdvancedModelLoader
                           //             .loadModel(new ResourceLocation("handmadeguns2:addgun/" +domain + "/addmodel/" + type[1]));
                                gun.obj_model_string = "handmadeguns2:addgun/" +domain + "/addmodel/" + type[1];
                            }
                            if (type[0].equals("ObjTexture")) {
                                gun.obj_tex = "handmadeguns2:addgun/" +domain + "/addmodel/" + type[1];
                            }
                        }
                        if (type[0].equals("Zoom")) {
                            gun.zoom = Float.parseFloat(type[1]);
                        }
                        if (type[0].equals("ScopeTexture")) {
                            gun.ads_tex = "handmadeguns2:addgun/" +domain + "/addoverlay/" + type[1];
                        }
                        if (type[0].equals("ZoomRender")) {
                            gun.zoomrender = Boolean.parseBoolean(type[1]);
                        }
                        if (type[0].equals("ZoomRenderHUD")) {
                            gun.zoomrendertex = Boolean.parseBoolean(type[1]);
                        }
                        if (type[0].equals("Eye_Relief")) {
                            gun.eye_relief = Float.parseFloat(type[1]);
                        }
                        if (type[0].equals("CenterPoint")) {
                            gun.x = Float.parseFloat(type[1]);
                            gun.y = Float.parseFloat(type[2]);
                            gun.z = Float.parseFloat(type[3]);
                        }
                        if (type[0].equals("RoteAngle")) {
                            gun.xr = Float.parseFloat(type[1]);
                            gun.yr = Float.parseFloat(type[2]);
                            gun.zr = Float.parseFloat(type[3]);
                        }

                    }
                }
                br.close(); // ファイルを閉じる
            }
        } catch (FileNotFoundException ex) {
            ex.printStackTrace();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }

}

