package gvclib.item.gun;

import gvclib.item.ItemGunBase;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import net.minecraftforge.fml.loading.FMLLoader;
import objmodel.AdvancedModelLoader;

import java.io.*;

public class GunBase_LoadStatus {

    public static void load(ItemGunBase gun, BufferedReader br, String domain){
        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"));
                        }*/

                        if (FMLLoader.getDist().isClient()) {
                            /*for(int xxxx = 0; xxxx < 100; ++xxxx){
                                System.out.println(String.format("model_road"));
                            }*/
                            if (type[0].equals("ObjModel")) {
                                //System.out.println(String.format("modelroad+") + text);
                                /*gun.obj_model = AdvancedModelLoader
                                        .loadModel(new ResourceLocation("gvcr2:textures/gun/model/" + type[1]));
                                gun.obj_model_name = "gvcr2:textures/gun/model/" + type[1];*/
                                gun.obj_model_resource = "handmadeguns2:addgun/" +domain + "/addmodel/" + type[1];
                            //    gun.obj_model = AdvancedModelLoader
                            //            .loadModel(new ResourceLocation("handmadeguns2:addgun/" +domain + "/addmodel/" + type[1]));
                            }
                            if (type[0].equals("ObjTexture")) {
                                gun.obj_tex = "handmadeguns2:addgun/" +domain + "/addmodel/" + type[1];
                            }
                        }
                        if (type[0].equals("BulletPower")) {
                            gun.powor = Integer.parseInt(type[1]);
                        }
                        if (type[0].equals("BulletSpeed")) {
                            gun.speed = Float.parseFloat(type[1]);
                            if(gun.speed > 4.0F){
                                gun.speed = 4.0F;
                            }
                        }
                        //gun.durability(7);
                        if (type[0].equals("BlletSpread")) {
                            gun.bure = Float.parseFloat(type[1]);
                        }
                        if (type[0].equals("BlletSpread_ADS")) {
                            gun.bureads = Float.parseFloat(type[1]);
                        }
                        if (type[0].equals("Recoil")) {
                            gun.recoil = Double.parseDouble(type[1]);
                        }
                        if (type[0].equals("Recoil_ADS")) {
                            gun.recoilads = Float.parseFloat(type[1]);
                        }
                        if (type[0].equals("BulletGravity")) {
                            gun.gra = Float.parseFloat(type[1]);
                        }
                        if (type[0].equals("ReloadTime")) {
                            gun.reloadtime = Integer.parseInt(type[1]);
                        }
                        if (type[0].equals("Motion")) {
                            gun.movespeed = Float.parseFloat(type[1]);
                        }
                        if (type[0].equals("Zoom")) {
                            gun.scopezoom = Float.parseFloat(type[1]);
                        }
                        if (type[0].equals("ZoomRender")) {
                            gun.zoomrender = Boolean.parseBoolean(type[1]);
                        }
                        String scopedomain = "handmadeguns2:addgun/" +domain + "/addoverlay/";
                        if (type[0].equals("ScopeTexture")) {
                            gun.adstexture = scopedomain +  type[1];
                        }
                        if (type[0].equals("ShotGun_Pellet")) {
                            gun.pellet = Integer.parseInt(type[1]);
                        }
                        if (type[0].equals("Cycle")) {
                            gun.cycle = Integer.parseInt(type[1]);
                        }
                        if (type[0].equals("Explosion")) {
                            gun.exlevel = Float.parseFloat(type[1]);
                        }
                        if (type[0].equals("GunSound")) {
                            gun.fire_sound = type[1];
                        }
                        if (type[0].equals("GunSoundReload")) {
                            gun.reload_sound = type[1];
                        }
                        /*if (type[0].equals("GunSoundCooking")) {
                            gun.soundco = type[1];
                        }*/

                        if (type[0].equals("Magazine")) {
                            int ii = Integer.parseInt(type[1]);
                            if (ii == 0) {
                                //gun.magazine = event.getRegistry().getValue(new ResourceLocation(type[2], type[3]));
                                gun.magazine = Registry.ITEM.get(new ResourceLocation(type[2],type[3]));

                            }
                        }


                        if (type[0].equals("ModelEquipped")) {
                            gun.model_x = Float.parseFloat(type[1]);
                            gun.model_y = Float.parseFloat(type[2]);
                            gun.model_z = Float.parseFloat(type[3]);
                        }
                        if (type[0].equals("SprintingRotation")) {
                            gun.Sprintrotationx = Float.parseFloat(type[1]);
                            gun.Sprintrotationy = Float.parseFloat(type[2]);
                            gun.Sprintrotationz = Float.parseFloat(type[3]);
                        }
                        if (type[0].equals("ModelHigh")) {
                            gun.model_y_ads = Float.parseFloat(type[1]);
                        }
                        if (type[0].equals("ModelWidthX")) {
                            gun.model_x_ads = Float.parseFloat(type[1]);
                        }
                        if (type[0].equals("ModelWidthZ")) {
                            gun.model_z_ads = Float.parseFloat(type[1]);
                        }
                        if (type[0].equals("MuzzleJump")) {
                            gun.model_muzz_jump_x = Float.parseFloat(type[1]);
                        }
                        if (type[0].equals("Mat2_CockZ")) {
                            gun.model_cock_z = Float.parseFloat(type[1]);
                        }
                        if (type[0].equals("Mat22Point")) {
                            gun.mat22_x = Float.parseFloat(type[1]);
                            gun.mat22_y = Float.parseFloat(type[2]);
                            gun.mat22_z = Float.parseFloat(type[3]);
                        }

                        if (type[0].equals("SightSetPoint")) {
                            gun.am_sight_x = gun.am_sightbase_x = Float.parseFloat(type[1]);
                            gun.am_sight_y = gun.am_sightbase_y = Float.parseFloat(type[2]);
                            gun.am_sight_z = gun.am_sightbase_z = Float.parseFloat(type[3]);
                        }
                        if (type[0].equals("LightSetPoint")) {
                            gun.am_light_x = Float.parseFloat(type[1]);
                            gun.am_light_y = Float.parseFloat(type[2]);
                            gun.am_light_z = Float.parseFloat(type[3]);
                        }
                        if (type[0].equals("LightSetAngle")) {
                            gun.am_light_xr = Float.parseFloat(type[1]);
                            gun.am_light_yr = Float.parseFloat(type[2]);
                            gun.am_light_zr = Float.parseFloat(type[3]);
                        }
                        if (type[0].equals("MuzzleSetPoint")) {
                            gun.am_supu_x = Float.parseFloat(type[1]);
                            gun.am_supu_y = Float.parseFloat(type[2]);
                            gun.am_supu_z = Float.parseFloat(type[3]);
                        }
                        if (type[0].equals("MuzzleSetAngle")) {
                            gun.am_supu_xr = Float.parseFloat(type[1]);
                            gun.am_supu_yr = Float.parseFloat(type[2]);
                            gun.am_supu_zr = Float.parseFloat(type[3]);
                        }
                        if (type[0].equals("GripSetPoint")) {
                            gun.am_grip_x = Float.parseFloat(type[1]);
                            gun.am_grip_y = Float.parseFloat(type[2]);
                            gun.am_grip_z = Float.parseFloat(type[3]);
                        }
                        if (type[0].equals("GripSetAngle")) {
                            gun.am_grip_xr = Float.parseFloat(type[1]);
                            gun.am_grip_yr = Float.parseFloat(type[2]);
                            gun.am_grip_zr = Float.parseFloat(type[3]);
                        }
                    }
                }
                br.close(); // ファイルを閉じる
            }
        } catch (FileNotFoundException ex) {
            ex.printStackTrace();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }

}
