OSDN Git Service

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