package com.infinityraider.infinitylib.proxy.base;

import com.infinityraider.infinitylib.InfinityLib;
import com.infinityraider.infinitylib.InfinityMod;
import com.infinityraider.infinitylib.config.ConfigurationHandler;
import com.infinityraider.infinitylib.entity.EntityRenderFactoryEmpty;
import com.infinityraider.infinitylib.entity.IInfinityEntityType;
import com.infinityraider.infinitylib.sound.SidedSoundDelegate;
import com.infinityraider.infinitylib.sound.SoundDelegateClient;
import com.infinityraider.infinitylib.utility.ReflectionHelper;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.RegistryKey;
import net.minecraft.world.World;
import net.minecraftforge.fml.LogicalSide;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraftforge.fml.server.ServerLifecycleHooks;

public interface IClientProxyBase<C extends ConfigurationHandler.SidedModConfig> extends IProxyBase<C> {

    @Override
    /** Called on the client to register renderers */
    default void registerRenderers(InfinityMod<?,?> mod) {
        this.registerEntityRenderers(mod.getModEntityRegistry());
    }

    default void registerEntityRenderers(Object entityRegistry) {
        ReflectionHelper.forEachValueIn(entityRegistry, IInfinityEntityType.class, object -> {
            if (object.getRenderFactory() == null) {
                InfinityLib.instance.getLogger().info("", "No entity rendering factory was found for entity " + object.getInternalName());
                RenderingRegistry.registerEntityRenderingHandler(object.cast(), EntityRenderFactoryEmpty.getInstance());
            } else {
                RenderingRegistry.registerEntityRenderingHandler(object.cast(), object.getRenderFactory());
            }
        });
    }

    @Override
    default PlayerEntity getClientPlayer() {
        return Minecraft.getInstance().player;
    }

    @Override
    default World getClientWorld() {
        return Minecraft.getInstance().world;
    }

    @Override
    default World getWorldFromDimension(RegistryKey<World> dimension) {
        LogicalSide effectiveSide = this.getEffectiveSide();
        if(effectiveSide == LogicalSide.SERVER) {
            return ServerLifecycleHooks.getCurrentServer().getWorld(dimension);
        } else {
            return getClientWorld();
        }
    }

    @Override
    default LogicalSide getPhysicalSide() {
        return LogicalSide.CLIENT;
    }

    @Override
    default void queueTask(Runnable task) {
        if(getEffectiveSide() == LogicalSide.CLIENT) {
            Minecraft.getInstance().execute(task);
        } else {
            this.getMinecraftServer().execute(task);
        }
    }

    @Override
    default SidedSoundDelegate getSoundDelegate() {
        return new SoundDelegateClient(Minecraft.getInstance().getSoundHandler());
    }
}

@@ -1241,24 +1241,65 @@
 Registry) %7B%0A
+        if(entityRegistry != null) %7B%0A    
         Refl
@@ -1381,16 +1381,20 @@
 ct -%3E %7B%0A
+    
         
@@ -1454,16 +1454,20 @@
         
+    
 Infinity
@@ -1589,32 +1589,36 @@
                 
+ 
+   
 RenderingRegistr
@@ -1710,32 +1710,36 @@
 ));%0A            
+    
 %7D else %7B%0A       
@@ -1739,32 +1739,36 @@
                 
+   
+ 
 RenderingRegistr
@@ -1851,26 +1851,34 @@
             
-%7D%0A
+    %7D%0A    
         %7D);%0A
@@ -1877,16 +1877,26 @@
     %7D);%0A
+        %7D%0A
     %7D%0A%0A 

Fix NPE