OSDN Git Service

e6b9a4c08bbfbc41eca61de2859aa348c8ea9478
[chemicraft/chemicraft.git] / common / pcc / chemicraft / base / ChemiCraftBase.java
1 package pcc.chemicraft.base;
2
3 import java.util.List;
4
5 import net.minecraft.block.Block;
6 import net.minecraft.creativetab.CreativeTabs;
7 import net.minecraft.item.Item;
8 import net.minecraft.item.ItemStack;
9 import net.minecraftforge.common.Configuration;
10 import net.minecraftforge.common.Property;
11 import net.minecraftforge.oredict.OreDictionary;
12 import pcc.chemicraft.ChemiCraft;
13 import pcc.chemicraft.ChemiCraftConfiguration;
14 import pcc.chemicraft.ChemiCraftRegister;
15 import pcc.chemicraft.base.creativetab.CreativeTabAtomOres;
16 import pcc.chemicraft.base.gen.WorldGenAtomsOre;
17 import pcc.chemicraft.base.system.CommonProxy;
18 import pcc.chemicraft.base.system.PacketHandler;
19 import pcc.chemicraft.core.ChemiCraftAPI;
20 import cpw.mods.fml.common.Loader;
21 import cpw.mods.fml.common.Mod;
22 import cpw.mods.fml.common.ModContainer;
23 import cpw.mods.fml.common.LoaderState.ModState;
24 import cpw.mods.fml.common.Mod.Instance;
25 import cpw.mods.fml.common.Mod.PostInit;
26 import cpw.mods.fml.common.Mod.PreInit;
27 import cpw.mods.fml.common.SidedProxy;
28 import cpw.mods.fml.common.event.FMLInitializationEvent;
29 import cpw.mods.fml.common.event.FMLPostInitializationEvent;
30 import cpw.mods.fml.common.event.FMLPreInitializationEvent;
31 import cpw.mods.fml.common.network.NetworkMod;
32 import cpw.mods.fml.common.registry.GameRegistry;
33
34 @Mod(modid = "ChemiCraftBase", name = "ChemiCraftBase", version = "beta")
35 @NetworkMod(clientSideRequired = true, serverSideRequired = true, versionBounds = "1.4.6", channels = "chemicraftbase", packetHandler = PacketHandler.class)
36 public class ChemiCraftBase extends ChemiCraft
37 {
38
39         /**
40          * this is ChemiCraft instance.
41          */
42         @Instance("ChemiCraftBase")
43         public static ChemiCraftBase instance;
44
45         /**
46          * proxy of ChemiCraft.
47          */
48         @SidedProxy(clientSide = "pcc.chemicraft.base.client.ClientProxy", serverSide = "pcc.chemicraft.base.system.CommonProxy")
49         public static CommonProxy proxy;
50
51         /**
52          * API Instance.
53          */
54         public ChemiCraftAPI api = ChemiCraftAPI.instance();
55         public ChemiCraftBaseAPI apiBase = ChemiCraftBaseAPI.instance();
56
57         /**
58          * CreativeTab of ChemiCraft.
59          */
60         public static final CreativeTabs creativeTabAtomsOre = new CreativeTabAtomOres("AtomsOre");
61
62         /**
63          * the ItemID.
64          */
65         public int atomGrenadeID;
66         public int blackSmokeID;
67         public int dustID;
68         public int radiationGunID;
69         public int radiationBalletID;
70
71         /**
72          * the BlockID.
73          */
74         public int[] atomOresID = new int[4];
75
76         /**
77          * Variables of Block type.
78          */
79         public Block[] blockAtomOres = new Block[atomOresID.length];
80
81         /**
82          * Variables of Item type.
83          */
84         public Item itemAtomGrenade;
85         public Item itemBlackSmoke;
86         public Item itemDust;
87         public Item itemRadiationGun;
88         public Item itemRadiationBallet;
89
90         /**
91          * the Register Instances.
92          */
93         public ChemiCraftRegister registerCompounds;
94         public ChemiCraftRegister registerCompoundsHandler;
95         public ChemiCraftRegister registerItem;
96         public ChemiCraftRegister registerChemicalRecipe;
97         public ChemiCraftRegister registerBlock;
98         public ChemiCraftRegister registerRecipe;
99         public ChemiCraftRegister registerEntitys;
100
101         public ChemiCraftBase()
102         {
103                 this.registerCompounds = new ChemiCraftRegisterCompounds(this);
104                 this.registerCompoundsHandler = new ChemiCraftRegisterCompoundsHandler(this);
105                 this.registerItem = new ChemiCraftRegisterItem(this);
106                 this.registerChemicalRecipe = new ChemiCraftRegisterChemicalRecipe(this);
107                 this.registerBlock = new ChemiCraftRegisterBlock(this);
108                 this.registerRecipe = new ChemiCraftRegisterBaseRecipe(this);
109                 this.registerEntitys = new ChemiCraftRegisterEntitys(this);
110         }
111
112         @PostInit
113         public void chemiPostLoadMethod(final FMLPostInitializationEvent event) {
114                 this.thread = new Thread(this);
115                 this.event = event;
116                 this.thread.start();
117
118                 try {
119                         this.thread.join();
120                 } catch (InterruptedException e) {
121                         e.printStackTrace();
122                 }
123
124                 proxy.registerRenderInformation();
125                 Thread.yield();
126         }
127
128         @Override
129         public void run()
130         {
131                 while (true) {
132                         if (proxy != null && instance != null) {
133                                 this.settingProcessing((FMLPostInitializationEvent) event);
134                                 this.apiProcessing((FMLPostInitializationEvent) event);
135                                 break;
136                         }
137                 }
138
139                 Thread loadCheckThread = new Thread() {
140                         @Override
141                         public void run() {
142                                 while (true) {
143                                         List<ModContainer> mod = Loader.instance().getModList();
144                                         ModContainer finalMod = mod.get(mod.size()-1);
145                                         ModState finalModState = Loader.instance().getModState(finalMod);
146                                         if (finalModState == ModState.AVAILABLE) {
147                                                 apiProcessing((FMLPostInitializationEvent) event);
148                                                 break;
149                                         }
150                                 }
151                         }
152                 };
153                 loadCheckThread.start();
154
155         }
156
157         /**
158          * PreInit:
159          * Configをロードします。
160          * @param event アノテーション呼び出しにより呼び出す必要なし
161          */
162         @PreInit
163         public void chemiPreLoadMethod(final FMLPreInitializationEvent event) {
164                 Configuration cfg = new Configuration(event.getSuggestedConfigurationFile());
165                 cfg.load();
166
167                 Property baseBlockID = cfg.get("BlockID", "Base of Block ID", 2500);
168                 Property baseItemID = cfg.get("ItemID", "Base of Item ID", 25500);
169
170                 ChemiCraftConfiguration ccfgBlock = new ChemiCraftConfiguration(baseBlockID.getInt());
171                 ChemiCraftConfiguration ccfgItem = new ChemiCraftConfiguration(baseItemID.getInt());
172
173                 for (int i = 0; i < atomOresID.length; i++) {
174                         this.atomOresID[i] = ccfgBlock.additionID();
175                 }
176
177                 this.atomGrenadeID = ccfgItem.additionID();
178                 this.dustID = ccfgItem.additionID();
179                 this.radiationGunID = ccfgItem.additionID();
180                 this.radiationBalletID = ccfgItem.additionID();
181                 this.blackSmokeID = ccfgItem.additionID();
182
183                 cfg.save();
184         }
185
186         protected void settingProcessing(FMLPostInitializationEvent event)
187         {
188                 this.registerCompounds.start();
189                 this.registerCompoundsHandler.start();
190                 this.registerItem.start();
191                 this.registerBlock.start();
192                 this.registerChemicalRecipe.start();
193                 this.registerRecipe.start();
194                 this.registerEntitys.start();
195         }
196
197         private void apiProcessing(final FMLPostInitializationEvent event) {
198                 // API用の処理
199                 for (int i = 0; i < apiBase.getAtomOresName().sizeKeysList(); i++)
200                 {
201                         for (int j = 0; j < apiBase.getAtomOresName().sizeElementsList(apiBase.getAtomOresName().getKeyList(i)); j++)
202                         {
203                                 this.nameAuxiliary.addName(new ItemStack(blockAtomOres[i / 16], 0, i - i / 16 * 16), apiBase.getAtomOresLanguage().get(apiBase.getAtomOresName().getKeyList(i), j), apiBase.getAtomOresName().get(apiBase.getAtomOresName().getKeyList(i), j));
204                                 OreDictionary.registerOre("ore" + apiBase.getAtomOresName().getKeyList(i), new ItemStack(blockAtomOres[i / 16], 1, i - i / 16 * 16));
205                                 GameRegistry.registerWorldGenerator(apiBase.getAtomOres().get(i));
206                         }
207                 }
208
209         }
210
211 }