package team.creative.ambientsounds;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.mojang.brigadier.Command;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;

import net.minecraft.client.Minecraft;
import net.minecraft.commands.SharedSuggestionProvider;
import net.minecraft.server.packs.resources.ReloadableResourceManager;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.server.packs.resources.SimplePreparableReloadListener;
import net.minecraft.util.profiling.ProfilerFiller;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.IExtensionPoint;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.network.NetworkConstants;
import team.creative.creativecore.client.CreativeCoreClient;
import team.creative.creativecore.client.command.ClientCommandRegistry;

@Mod(value = AmbientSounds.MODID)
public class AmbientSounds {
    
    public static final Logger LOGGER = LogManager.getLogger(AmbientSounds.MODID);
    
    public static final String MODID = "ambientsounds";
    
    public static final AmbientSoundsConfig CONFIG = new AmbientSoundsConfig();
    
    public AmbientSounds() {
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);
    }
    
    public static AmbientTickHandler tickHandler;
    
    public static void reload() {
        if (tickHandler.engine != null)
            tickHandler.engine.stopEngine();
        if (tickHandler.enviroment != null)
            tickHandler.enviroment.reload();
        tickHandler.setEngine(AmbientEngine.loadAmbientEngine(tickHandler.soundEngine));
    }
    
    private void doClientStuff(final FMLClientSetupEvent event) {
        ModLoadingContext.get()
                .registerExtensionPoint(IExtensionPoint.DisplayTest.class, () -> new IExtensionPoint.DisplayTest(() -> NetworkConstants.IGNORESERVERONLY, (a, b) -> true));
        
        tickHandler = new AmbientTickHandler();
        MinecraftForge.EVENT_BUS.register(tickHandler);
        
        Minecraft minecraft = Minecraft.getInstance();
        ReloadableResourceManager reloadableResourceManager = (ReloadableResourceManager) minecraft.getResourceManager();
        
        reloadableResourceManager.registerReloadListener(new SimplePreparableReloadListener() {
            
            @Override
            protected void apply(Object p_10793_, ResourceManager p_10794_, ProfilerFiller p_10795_) {
                AmbientSounds.reload();
            }
            
            @Override
            protected Object prepare(ResourceManager p_10796_, ProfilerFiller p_10797_) {
                return null;
            }
        });
        event.enqueueWork(() -> {
            ClientCommandRegistry.register(LiteralArgumentBuilder.<SharedSuggestionProvider>literal("ambient-debug").executes(x -> {
                tickHandler.showDebugInfo = !tickHandler.showDebugInfo;
                return Command.SINGLE_SUCCESS;
            }));
            ClientCommandRegistry.register(LiteralArgumentBuilder.<SharedSuggestionProvider>literal("ambient-reload").executes(x -> {
                AmbientSounds.reload();
                return Command.SINGLE_SUCCESS;
            }));
        });
        
        CreativeCoreClient.registerClientConfig(MODID);
    }
    
}

@@ -287,32 +287,26 @@
 nds.
-SharedSuggestionProvider
+CommandSourceStack
 ;%0Aim
@@ -559,24 +559,92 @@
 ilerFiller;%0A
+import net.minecraftforge.client.event.RegisterClientCommandsEvent;%0A
 import net.m
@@ -1068,80 +1068,8 @@
 ent;
-%0Aimport team.creative.creativecore.client.command.ClientCommandRegistry;
 %0A%0A@M
@@ -1487,16 +1487,78 @@
 Stuff);%0A
+        MinecraftForge.EVENT_BUS.addListener(this::commands);%0A
     %7D%0A  
@@ -2981,67 +2981,168 @@
     
-event.enqueueWork(() -%3E %7B
+%0A        CreativeCoreClient.registerClientConfig(MODID);%0A    %7D
 %0A    
-  
+%0A
     
-  ClientCommandRegistry
+private void commands(RegisterClientCommandsEvent event) %7B%0A        event.getDispatcher()
 .reg
@@ -3175,32 +3175,26 @@
 er.%3C
-SharedSuggestionProvider
+CommandSourceStack
 %3Elit
@@ -3235,36 +3235,32 @@
 %3E %7B%0A            
- 
-   
 tickHandler.show
@@ -3303,36 +3303,32 @@
 fo;%0A            
-    
 return Command.S
@@ -3342,36 +3342,32 @@
 UCCESS;%0A        
-   
- 
 %7D));%0A           
@@ -3367,33 +3367,29 @@
     
-    ClientCommandRegistry
+event.getDispatcher()
 .reg
@@ -3422,32 +3422,26 @@
 er.%3C
-SharedSuggestionProvider
+CommandSourceStack
 %3Elit
@@ -3471,36 +3471,32 @@
 executes(x -%3E %7B%0A
-    
             Ambi
@@ -3519,36 +3519,32 @@
 ();%0A            
-    
 return Command.S
@@ -3570,91 +3570,10 @@
     
- 
-   %7D));%0A        %7D);%0A        %0A        CreativeCoreClient.registerClientConfig(MODID
+%7D)
 );%0A 

Use forge client commands instead of creativecore ones