package crazypants.enderio.machine;

import com.enderio.core.common.util.NullHelper;
import crazypants.enderio.init.IModObject;
import crazypants.enderio.init.ModObjectRegistry;
import crazypants.enderio.machine.alloy.BlockAlloySmelter;
import crazypants.enderio.machine.capbank.BlockCapBank;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public enum MachineObject implements IModObject.Registerable {

    blockAlloySmelter(BlockAlloySmelter.class),
    blockCapBank(BlockCapBank.class);

    static {
        ModObjectRegistry.INSTANCE.addModObjects(MachineObject.class);
    }


    final @Nonnull String unlocalisedName;

    private @Nullable Block block;
    private @Nullable Item item;

    private final @Nullable Class<?> clazz;
    private final @Nonnull String methodName;
    private final @Nullable Class<? extends TileEntity> teClazz;

    private MachineObject(@Nullable Class<?> clazz) {
        this(clazz, "create", null);
    }

    private MachineObject(@Nullable Class<?> clazz, Class<? extends TileEntity> teClazz) {
        this(clazz, "create", teClazz);
    }

    private MachineObject(@Nullable Class<?> clazz, @Nonnull String methodName, Class<? extends TileEntity> teClazz) {
        this.unlocalisedName = ModObjectRegistry.sanitizeName(NullHelper.notnullJ(name(), "Enum.name()"));
        this.clazz = clazz;
        this.methodName = methodName;
        this.teClazz = teClazz;
    }

    @Override
    public Class<?> getClazz() {
        return clazz;
    }

    @Override
    public String getMethodName() {
        return methodName;
    }

    @Override
    public void setItem(Item obj) {
        this.item = obj;
    }

    @Override
    public void setBlock(Block obj) {
        this.block = obj;
    }

    @Nonnull
    @Override
    public String getUnlocalisedName() {
        return unlocalisedName;
    }

    @Nonnull
    @Override
    public ResourceLocation getRegistryName() {
        return new ResourceLocation(EnderIOMachines.MOD_ID, getUnlocalisedName());
    }

    @Override
    public @Nonnull <B extends Block> B apply(@Nonnull B blockIn) {
        blockIn.setUnlocalizedName(getUnlocalisedName());
        blockIn.setRegistryName(getRegistryName());
        return blockIn;
    }

    @Override
    public @Nonnull <I extends Item> I apply(@Nonnull I itemIn) {
        itemIn.setUnlocalizedName(getUnlocalisedName());
        itemIn.setRegistryName(getRegistryName());
        return itemIn;
    }

    @Nullable
    @Override
    public Block getBlock() {
        return null;
    }

    @Nullable
    @Override
    public Item getItem() {
        return null;
    }

    @Nullable
    @Override
    public Class<? extends TileEntity> getTileClass() {
        return null;
    }

    @Override
    public void preInit(@Nonnull FMLPreInitializationEvent event) {

    }

    @Override
    public void init(@Nonnull FMLInitializationEvent event) {

    }

}

@@ -121,16 +121,58 @@
 Object;%0A
+import crazypants.enderio.init.ModObject;%0A
 import c
@@ -2370,449 +2370,8 @@
  %7D%0A%0A
-    @Override%0A    public @Nonnull %3CB extends Block%3E B apply(@Nonnull B blockIn) %7B%0A        blockIn.setUnlocalizedName(getUnlocalisedName());%0A        blockIn.setRegistryName(getRegistryName());%0A        return blockIn;%0A    %7D%0A%0A    @Override%0A    public @Nonnull %3CI extends Item%3E I apply(@Nonnull I itemIn) %7B%0A        itemIn.setUnlocalizedName(getUnlocalisedName());%0A        itemIn.setRegistryName(getRegistryName());%0A        return itemIn;%0A    %7D%0A%0A
     
@@ -2372,32 +2372,32 @@
 %0A%0A    @Nullable%0A
+
     @Override%0A  
@@ -2431,36 +2431,37 @@
 %0A        return 
-null
+block
 ;%0A    %7D%0A%0A    @Nu
@@ -2516,36 +2516,36 @@
 %0A        return 
-null
+item
 ;%0A    %7D%0A%0A    @Nu
@@ -2636,20 +2636,23 @@
  return 
-null
+teClazz
 ;%0A    %7D%0A
@@ -2730,25 +2730,72 @@
 nt event) %7B%0A
+        ModObjectRegistry.preInit(this, event);
 %0A
-
     %7D%0A%0A    @
@@ -2865,16 +2865,64 @@
 vent) %7B%0A
+        ModObjectRegistry.initElem(this, event);
 %0A    %7D%0A%0A

Fix MachineObject