package gvclib;


import gvclib.client.event.RenderGunEvent;
import gvclib.client.event.RenderGunZoom;
import gvclib.client.event.RenderGun_ThirdEvent;
import gvclib.client.event.RenderHUD;
import gvclib.client.render.bullet.RenderB_Bullet;
import gvclib.entity.bullet.EntityB_Bullet;
import gvclib.event.GVCSoundEvent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MobCategory;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.EntityRenderersEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.fml.loading.FMLLoader;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegisterEvent;
import net.minecraftforge.registries.RegistryObject;

@Mod(mod_GVCLib.MOD_ID)
public class mod_GVCLib {

    public static CommonSideProxyGVClib proxy;
    public static mod_GVCLib INSTANCE;
    public static final String MOD_ID = "gvclib";


    public static RegistryObject<EntityType<EntityB_Bullet>> ENTITYB_BULLET;

    public static int gunlayer_mob;
    public static String[] gunlayer_mob_name = new String[2048];


    public mod_GVCLib() {
        IEventBus eventBus = FMLJavaModLoadingContext.get().getModEventBus();
        eventBus.addListener(this::setup);
        if (FMLLoader.getDist().isClient()) {
            proxy = new ClientProxyGVClib();
        }else{
            proxy = new CommonSideProxyGVClib();
        }
        GVCSoundEvent.register(eventBus);

        if (FMLLoader.getDist().isClient()) {
            MinecraftForge.EVENT_BUS.register(new RenderGunEvent());
            MinecraftForge.EVENT_BUS.register(new RenderGun_ThirdEvent());
            MinecraftForge.EVENT_BUS.register(new RenderGunZoom());
            MinecraftForge.EVENT_BUS.register(new RenderHUD());
        }
    }

    private void setup(final FMLCommonSetupEvent event) {

    }
    @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
    public static class RegistryEvents {
        @SubscribeEvent
        public static void registerEntityTypes(RegisterEvent event) {
            ENTITYB_BULLET = RegistryObject.create(new ResourceLocation(MOD_ID,"entityb_bullet"), ForgeRegistries.ENTITY_TYPES);
            //ENTITY_GRENADE = RegistryObject.create(new ResourceLocation(MOD_ID,"entitygrenade"), ForgeRegistries.ENTITY_TYPES);
            event.register(ForgeRegistries.Keys.ENTITY_TYPES,
                    helper -> {
                        helper.register(
                                new ResourceLocation("gvclib", "entityb_bullet"),
                                EntityType.Builder.<EntityB_Bullet>of(EntityB_Bullet::new, MobCategory.MISC)
                                        .setCustomClientFactory(EntityB_Bullet::new)
                                        .sized(0.15F, 0.15F)
                                        .setShouldReceiveVelocityUpdates(false)
                                        .setTrackingRange(60)
                                        .setUpdateInterval(60)
                                        .build("gvclib:entityb_bullet"));

                    /*helper.register(
                            new ResourceLocation("classicguns", "entitygrenade"),
                            EntityType.Builder.<EntityGrenade>of(EntityGrenade::new,MobCategory.MISC)
                                    .setCustomClientFactory(EntityGrenade::new)
                                    .sized(0.15F, 0.15F)
                                    .setShouldReceiveVelocityUpdates(false)
                                    .setTrackingRange(61)
                                    .setUpdateInterval(61)
                                    .build("classicguns:entitygrenade"));*/
                    }
            );
        }
    }


    @Mod.EventBusSubscriber(modid= mod_GVCLib.MOD_ID, value= Dist.CLIENT, bus=Mod.EventBusSubscriber.Bus.MOD)
    public static class ClientEvents {
        @SubscribeEvent
        public static void onRegisterRenderer(final EntityRenderersEvent.RegisterRenderers event) {
            event.registerEntityRenderer(ENTITYB_BULLET.get(), RenderB_Bullet::new);
        }
    }
}
