summaryrefslogtreecommitdiff
path: root/src/main/java/darkknight/jewelrycraft/JewelrycraftMod.java
blob: 182cbb6b523390b38edf201edf1ed87f08338a72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*
 * Mod made by DarkKnight during the Modjam 3 It's an awesome mod I love
 * me! :D
 */
package darkknight.jewelrycraft;

import java.io.File;
import java.io.IOException;

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

import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLInterModComms;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import darkknight.jewelrycraft.achievements.AchievementsList;
import darkknight.jewelrycraft.block.BlockList;
import darkknight.jewelrycraft.commands.JewelrycraftCommands;
import darkknight.jewelrycraft.config.ConfigHandler;
import darkknight.jewelrycraft.curses.CurseList;
import darkknight.jewelrycraft.entities.EntityList;
import darkknight.jewelrycraft.events.EventList;
import darkknight.jewelrycraft.item.ItemList;
import darkknight.jewelrycraft.network.PacketHandler;
import darkknight.jewelrycraft.potions.PotionList;
import darkknight.jewelrycraft.proxy.CommonProxy;
import darkknight.jewelrycraft.recipes.CraftingRecipes;
import darkknight.jewelrycraft.thirdparty.ThirdPartyManager;
import darkknight.jewelrycraft.util.JewelrycraftUtil;
import darkknight.jewelrycraft.util.Variables;
import darkknight.jewelrycraft.worldGen.ChestGeneration;
import darkknight.jewelrycraft.worldGen.village.VillageHandler;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.oredict.OreDictionary.OreRegisterEvent;

@Mod(modid = Variables.MODID, name = Variables.MODNAME, version = Variables.VERSION, guiFactory = Variables.CONFIG_GUI, acceptedMinecraftVersions = "[1.7.10,1.8)")
public class JewelrycraftMod {
	private static final class CreativeTabJewleryCraft
			extends CreativeTabs {
		private CreativeTabJewleryCraft(String lable) {
			super(lable);
		}

		@Override
		public Item getTabIconItem() {
			return Item.getItemFromBlock(
					BlockList.jewelCraftingTable);
		}
	}

	@Instance(Variables.MODID)
	public static JewelrycraftMod instance;

	@SidedProxy(clientSide = Variables.CLIENT_PROXY, serverSide = Variables.SERVER_PROXY)
	public static CommonProxy proxy;

	public static Logger logger;

	public static File dir;

	public static CreativeTabs	jewelrycraft	= new CreativeTabJewleryCraft(
			Variables.MODID);
	public static CreativeTabs	liquids		= new CreativeTabLiquids(
			"Liquids").setBackgroundImageName(
					"item_search.png");

	public static SimpleNetworkWrapper netWrapper;

	public static boolean fancyRender = false;

	/**
	 * Pre initialization of mod stuff.
	 *
	 * @param e
	 *                FMLPreInitializationEvent
	 * @throws IOException
	 *                 Signals that an I/O exception has occurred.
	 */
	@EventHandler
	public void preInit(FMLPreInitializationEvent e)
			throws IOException {
		dir = e.getModConfigurationDirectory();
		logger = e.getModLog();
		ConfigHandler.INSTANCE.loadConfig(e);
		ThirdPartyManager.instance().index();
		logger.log(Level.INFO, "Registering Blocks");
		BlockList.preInit(e);
		logger.log(Level.INFO, "Registering Items");
		ItemList.preInit(e);
		logger.log(Level.INFO, "Registering Crafting Recipes");
		CraftingRecipes.preInit(e);
		logger.log(Level.INFO, "Registering Curses");
		CurseList.preInit(e);
		logger.log(Level.INFO, "Registering Packets");
		PacketHandler.preInit(e);
		logger.log(Level.INFO, "Registering Entities");
		EntityList.preInit(e);
		logger.log(Level.INFO, "Registering Village Stuff");
		VillageHandler.preInit(e);
		logger.log(Level.INFO, "Registering Events");
		EventList.preInit(e);
		logger.log(Level.INFO, "Registering Potions");
		PotionList.preInit(e);
		logger.log(Level.INFO, "Loading Third Party Mods");
		ThirdPartyManager.instance().preInit();
		logger.log(Level.INFO, "Adding Dungeons loot");
		ChestGeneration.preInit(e);

		MinecraftForge.EVENT_BUS.register(this);
	}

	@EventHandler
	public void init(FMLInitializationEvent e) {
		logger.log(Level.INFO, "Registering Events");
		EventList.init(e);
		logger.log(Level.INFO, "Registering Potions");
		PotionList.init(e);
		logger.log(Level.INFO, "Loading Third Party Mods");
		ThirdPartyManager.instance().init();
		FMLInterModComms.sendMessage("Waila", "register",
				"darkknight.jewelrycraft.thirdparty.WailaHandler.registration");
	}

	@EventHandler
	public void postInit(FMLPostInitializationEvent e) {
		logger.log(Level.INFO, "Loading Third Party Mods");
		ThirdPartyManager.instance().postInit();
		logger.log(Level.INFO, "Registering Events");
		EventList.postInit(e);
		logger.log(Level.INFO, "Registering Potions");
		PotionList.postInit(e);
		logger.log(Level.INFO, "Registering Achievements");
		AchievementsList.addAchievements();
	}

	@EventHandler
	public void serverLoad(FMLServerStartingEvent event) {
		event.registerServerCommand(new JewelrycraftCommands());
	}

	@EventHandler
	public void imcCallback(FMLInterModComms.IMCEvent event) {
		for (final FMLInterModComms.IMCMessage imcMessage : event
				.getMessages()) {
			logger.info("The mod " + imcMessage.getSender()
					+ " has sent the following message: "
					+ imcMessage.getStringValue());
		}
	}

	@SubscribeEvent
	public void oredictRegistered(OreRegisterEvent orev) {
		if (orev.Name.startsWith("ingot")
				|| orev.Name.startsWith("alloy")) {
			if (!JewelrycraftUtil.metal.contains(orev.Ore)) {
				JewelrycraftUtil.metal.add(orev.Ore);
			}
		}

		if (orev.Name.startsWith("ore")) {
			if (!JewelrycraftUtil.ores.contains(orev.Ore)) {
				JewelrycraftUtil.metal.add(orev.Ore);
			}

			ItemStack ingot = FurnaceRecipes.smelting()
					.getSmeltingResult(orev.Ore);

			if (ingot != null) {
				JewelrycraftUtil.oreToIngot.put(orev.Ore,
						ingot);
			}
		}
	}
}