package org.cyclops.cyclopscore.config.extendedconfig;

import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.ModelBakery;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.renderer.block.statemap.StateMapperBase;
import net.minecraft.item.Item;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fluids.BlockFluidClassic;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.cyclops.cyclopscore.helper.MinecraftHelpers;
import org.cyclops.cyclopscore.init.ModBase;

/**
 * Config for BlockFluids.
 * @author immortaleeb
 * @see ExtendedConfig
 */
public abstract class BlockFluidConfig extends BlockConfig {

    @SideOnly(Side.CLIENT)
    private ModelResourceLocation fluidLocation;

    /**
     * Make a new instance.
     *
     * @param mod     The mod instance.
     * @param enabled If this should is enabled.
     * @param namedId The unique name ID for the configurable.
     * @param comment The comment to add in the config file for this configurable.
     * @param element The class of this configurable.
     */
    public BlockFluidConfig(ModBase mod, boolean enabled, String namedId, String comment, Class<? extends BlockFluidClassic> element) {
        super(mod, enabled, namedId, comment, element);
        if (MinecraftHelpers.isClientSide()) {
            fluidLocation = new ModelResourceLocation(mod.getModId() + ":" + getNamedId(), "fluid");
        }
    }

    @Override
    public BlockFluidClassic getBlockInstance() {
        return (BlockFluidClassic) super.getBlockInstance();
    }

    @Override
    @SideOnly(Side.CLIENT)
    public void onRegistered() {
        super.onRegistered();

        // Handle registration for fluid rendering
        BlockFluidClassic blockInstance = getBlockInstance();
        Item fluid = Item.getItemFromBlock(blockInstance);

        ModelBakery.registerItemVariants(fluid, fluidLocation);

        ModelLoader.setCustomStateMapper(blockInstance, new StateMapperBase() {

            @Override
            protected ModelResourceLocation getModelResourceLocation(IBlockState state) {
                return fluidLocation;
            }
        });
    }
}

@@ -367,77 +367,251 @@
 ent.
-model.ModelLoader;%0Aimport net.minecraftforge.fluids.BlockFluidClassic
+event.ModelRegistryEvent;%0Aimport net.minecraftforge.client.model.ModelLoader;%0Aimport net.minecraftforge.common.MinecraftForge;%0Aimport net.minecraftforge.fluids.BlockFluidClassic;%0Aimport net.minecraftforge.fml.common.eventhandler.SubscribeEvent
 ;%0Aim
@@ -1718,22 +1718,132 @@
       %7D%0A
+        if (MinecraftHelpers.isClientSide()) %7B%0A            MinecraftForge.EVENT_BUS.register(this);%0A        %7D%0A
     %7D%0A
-
 %0A    @Ov
@@ -1963,38 +1963,24 @@
 e();%0A    %7D%0A%0A
-    @Override%0A
     @SideOnl
@@ -1990,24 +1990,44 @@
 ide.CLIENT)%0A
+    @SubscribeEvent%0A
     public v
@@ -2036,53 +2036,53 @@
 d on
+Model
 Regist
-ered() %7B%0A        super.onRegistered();%0A
+ryLoad(ModelRegistryEvent event) %7B
 %0A   

Fix fluid registration interacting with ModelLoader outside of event