package com.ferreusveritas.dynamictrees.event;

import com.ferreusveritas.dynamictrees.ModBlocks;
import com.ferreusveritas.dynamictrees.models.BonsaiCompositeModel;
import com.ferreusveritas.dynamictrees.models.RootyCompositeModel;

import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraftforge.client.event.ModelBakeEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class ModelBakeEventListener {
	
	@SideOnly(Side.CLIENT)
	@SubscribeEvent
	public void onRootyDirtModelBakeEvent(ModelBakeEvent event) {
		Object rootsObject =  event.getModelRegistry().getObject(new ModelResourceLocation(ModBlocks.blockRootyDirt.getRegistryName(), "normal"));
		if (rootsObject instanceof IBakedModel) {
		      IBakedModel rootsModel = (IBakedModel) rootsObject;
		      RootyCompositeModel rootyModel = new RootyCompositeModel(rootsModel);
		      event.getModelRegistry().putObject(new ModelResourceLocation(ModBlocks.blockRootyDirt.getRegistryName(), "normal"), rootyModel);
		}
	}
	
	@SideOnly(Side.CLIENT)
	@SubscribeEvent
	public void onRootyDirtSpeciesModelBakeEvent(ModelBakeEvent event) {
		Object rootsObject =  event.getModelRegistry().getObject(new ModelResourceLocation(ModBlocks.blockRootyDirtSpecies.getRegistryName(), "normal"));
		if (rootsObject instanceof IBakedModel) {
		      IBakedModel rootsModel = (IBakedModel) rootsObject;
		      RootyCompositeModel rootyModel = new RootyCompositeModel(rootsModel);
		      event.getModelRegistry().putObject(new ModelResourceLocation(ModBlocks.blockRootyDirtSpecies.getRegistryName(), "normal"), rootyModel);
		}
	}
	
	@SideOnly(Side.CLIENT)
	@SubscribeEvent
	public void onRootySandModelBakeEvent(ModelBakeEvent event) {
		Object rootsObject =  event.getModelRegistry().getObject(new ModelResourceLocation(ModBlocks.blockRootySand.getRegistryName(), "normal"));
		if (rootsObject instanceof IBakedModel) {
		      IBakedModel rootsModel = (IBakedModel) rootsObject;
		      RootyCompositeModel rootyModel = new RootyCompositeModel(rootsModel);
		      event.getModelRegistry().putObject(new ModelResourceLocation(ModBlocks.blockRootySand.getRegistryName(), "normal"), rootyModel);
		}
	}

	@SideOnly(Side.CLIENT)
	@SubscribeEvent
	public void onBonsaiModelBakeEvent(ModelBakeEvent event) {
				
		Object flowerPotObject =  event.getModelRegistry().getObject(new ModelResourceLocation(ModBlocks.blockBonsaiPot.getRegistryName(), "normal"));
		if (flowerPotObject instanceof IBakedModel) {
		      IBakedModel flowerPotModel = (IBakedModel) flowerPotObject;
		      BonsaiCompositeModel bonsaiPotModel = new BonsaiCompositeModel(flowerPotModel);
		      event.getModelRegistry().putObject(new ModelResourceLocation(ModBlocks.blockBonsaiPot.getRegistryName(), "normal"), bonsaiPotModel);
		}
	}
	
}

@@ -227,16 +227,50 @@
 Model;%0A%0A
+import net.minecraft.block.Block;%0A
 import n
@@ -765,1173 +765,166 @@
 %7B%0A%09%09
-Object rootsObject =  event.getModelRegistry().getObject(new ModelResourceLocation(ModBlocks.blockRootyDirt.getRegistryName(), %22normal%22));%0A%09%09if (rootsObject instanceof IBakedModel) %7B%0A%09%09      IBakedModel rootsModel = (IBakedModel) rootsObject;%0A%09%09      RootyCompositeModel rootyModel = new RootyCompositeModel(rootsModel);%0A%09%09      event.getModelRegistry().putObject(new ModelResourceLocation(ModBlocks.blockRootyDirt.getRegistryName(), %22normal%22), rootyModel);%0A%09%09%7D%0A%09%7D%0A%09%0A%09@SideOnly(Side.CLIENT)%0A%09@SubscribeEvent%0A%09public void onRootyDirtSpeciesModelBakeEvent(ModelBakeEvent event) %7B%0A%09%09Object rootsObject =  event.getModelRegistry().getObject(new ModelResourceLocation(ModBlocks.blockRootyDirtSpecies.getRegistryName(), %22normal%22));%0A%09%09if (rootsObject instanceof IBakedModel) %7B%0A%09%09      IBakedModel rootsModel = (IBakedModel) rootsObject;%0A%09%09      RootyCompositeModel rootyModel = new RootyCompositeModel(rootsModel);%0A%09%09      event.getModelRegistry().putObject(new ModelResourceLocation(Mod
+Block%5B%5D rootyBlocks = new Block%5B%5D %7B ModBlocks.blockRootyDirt, ModBlocks.blockRootyDirtSpecies, ModBlocks.blockRootySand%7D;%0A%0A%09%09for(
 Block
-s.
+ 
 block
-RootyDirtSpecies.getRegistryName(), %22normal%22), rootyModel);%0A%09%09%7D%0A%09%7D%0A%09%0A%09@SideOnly(Side.CLIENT)%0A%09@SubscribeEvent%0A%09public void onRootySandModelBakeEvent(ModelBakeEvent event
+: rootyBlocks
 ) %7B%0A
+%09
 %09%09Ob
@@ -1008,32 +1008,13 @@
 ion(
-ModBlocks.blockRootySand
+block
 .get
@@ -1037,24 +1037,25 @@
 %22normal%22));%0A
+%09
 %09%09if (rootsO
@@ -1080,38 +1080,34 @@
 BakedModel) %7B%0A%09%09
-      
+%09%09
 IBakedModel root
@@ -1144,22 +1144,18 @@
 ject;%0A%09%09
-      
+%09%09
 RootyCom
@@ -1210,38 +1210,34 @@
 (rootsModel);%0A%09%09
-      
+%09%09
 event.getModelRe
@@ -1285,32 +1285,13 @@
 ion(
-ModBlocks.blockRootySand
+block
 .get
@@ -1336,117 +1336,15 @@
 ;%0A%09%09
-%7D%0A
 %09%7D%0A
-%0A%09@SideOnly(Side.CLIENT)%0A%09@SubscribeEvent%0A%09public void onBonsaiModelBakeEvent(ModelBakeEvent event) %7B%0A%09%09
+%09%09%7D%0A
 %09%09%0A%09

Consolidate ModelBakeEvent Code