OSDN Git Service

修正・変更
[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.ChemiCraftAPI;
21 import pcc.chemicraft.core.ChemiCraftCore;
22 import cpw.mods.fml.common.Loader;
23 import cpw.mods.fml.common.LoaderState.ModState;
24 import cpw.mods.fml.common.Mod;
25 import cpw.mods.fml.common.Mod.Instance;
26 import cpw.mods.fml.common.Mod.PostInit;
27 import cpw.mods.fml.common.Mod.PreInit;
28 import cpw.mods.fml.common.ModContainer;
29 import cpw.mods.fml.common.SidedProxy;
30 import cpw.mods.fml.common.event.FMLPostInitializationEvent;
31 import cpw.mods.fml.common.event.FMLPreInitializationEvent;
32 import cpw.mods.fml.common.network.NetworkMod;
33 import cpw.mods.fml.common.registry.LanguageRegistry;
34
35 @Mod(modid = "ChemiCraftBase", name = "ChemiCraftBase", version = "beta1")
36 @NetworkMod(clientSideRequired = true, serverSideRequired = true, versionBounds = "1.4.7", channels = "chemicraftbase", packetHandler = PacketHandler.class)
37 public class ChemiCraftBase extends ChemiCraft {
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         public int oreSerarcherID;
71
72         /**
73          * the BlockID.
74          */
75         public int[] atomOresID = new int[4];
76
77         /**
78          * Variables of Block type.
79          */
80         public Block[] blockAtomOres = new Block[atomOresID.length];
81
82         /**
83          * Variables of Item type.
84          */
85         public Item itemAtomGrenade;
86         public Item itemBlackSmoke;
87         public Item itemDust;
88         public Item itemRadiationGun;
89         public Item itemRadiationBallet;
90         public Item itemOreSearcher;
91
92         /**
93          * the Register Instances.
94          */
95         public ChemiCraftRegister registerCompounds;
96         public ChemiCraftRegister registerCompoundsHandler;
97         public ChemiCraftRegister registerItem;
98         public ChemiCraftRegister registerChemicalRecipe;
99         public ChemiCraftRegister registerBlock;
100         public ChemiCraftRegister registerRecipe;
101         public ChemiCraftRegister registerEntitys;
102
103         /**
104          * the Textures
105          */
106         public static final String ORE = ChemiCraft.TEXTURE + "AtomsOre_";
107
108         public ChemiCraftBase() {
109                 this.registerCompounds = new ChemiCraftRegisterCompounds(this);
110                 this.registerCompoundsHandler = new ChemiCraftRegisterCompoundsHandler(this);
111                 this.registerItem = new ChemiCraftRegisterItem(this);
112                 this.registerChemicalRecipe = new ChemiCraftRegisterChemicalRecipe(this);
113                 this.registerBlock = new ChemiCraftRegisterBlock(this);
114                 this.registerRecipe = new ChemiCraftRegisterBaseRecipe(this);
115                 this.registerEntitys = new ChemiCraftRegisterEntitys(this);
116         }
117
118         @PostInit
119         public void chemiPostLoadMethod(final FMLPostInitializationEvent event) {
120                 this.thread = new Thread(this);
121                 this.event = event;
122                 this.thread.start();
123
124                 try {
125                         this.thread.join();
126                 } catch (InterruptedException e) {
127                         e.printStackTrace();
128                 }
129
130                 proxy.registerRenderInformation();
131                 Thread.yield();
132         }
133
134         @Override
135         public void run() {
136                 while (true) {
137                         if (proxy != null && instance != null) {
138                                 this.settingProcessing((FMLPostInitializationEvent) event);
139                                 this.apiProcessing((FMLPostInitializationEvent) event);
140                                 break;
141                         }
142                 }
143
144                 Thread loadCheckThread = new Thread() {
145                         @Override
146                         public void run() {
147                                 while (true) {
148                                         List<ModContainer> mod = Loader.instance().getModList();
149                                         ModContainer finalMod = mod.get(mod.size()-1);
150                                         ModState finalModState = Loader.instance().getModState(finalMod);
151                                         if (finalModState == ModState.POSTINITIALIZED) {
152                                                 ChemiCraftCore.logger.write("ChemiCraftBase>APIProcessing", EnumLoggingType.INFO);
153                                                 apiProcessing((FMLPostInitializationEvent) event);
154                                                 break;
155                                         }
156                                 }
157                         }
158                 };
159                 loadCheckThread.start();
160
161         }
162
163         /**
164          * PreInit:<br>
165          * Configをロードします。
166          * @param event アノテーション呼び出しにより呼び出す必要なし
167          */
168         @PreInit
169         public void chemiPreLoadMethod(final FMLPreInitializationEvent event) {
170                 Configuration cfg = new Configuration(event.getSuggestedConfigurationFile());
171                 cfg.load();
172
173                 Property baseBlockID = cfg.get("BlockID", "Base of Block ID", 2500);
174                 Property baseItemID = cfg.get("ItemID", "Base of Item ID", 25500);
175
176                 ChemiCraftConfiguration ccfgBlock = new ChemiCraftConfiguration(baseBlockID.getInt());
177                 ChemiCraftConfiguration ccfgItem = new ChemiCraftConfiguration(baseItemID.getInt());
178
179                 for (int i = 0; i < atomOresID.length; i++) {
180                         this.atomOresID[i] = ccfgBlock.additionID();
181                 }
182
183                 this.atomGrenadeID = ccfgItem.additionID();
184                 this.dustID = ccfgItem.additionID();
185                 this.radiationGunID = ccfgItem.additionID();
186                 this.radiationBalletID = ccfgItem.additionID();
187                 this.blackSmokeID = ccfgItem.additionID();
188                 this.oreSerarcherID = ccfgItem.additionID();
189
190                 cfg.save();
191         }
192
193         protected void settingProcessing(FMLPostInitializationEvent event) {
194                 this.registerCompounds.start();
195                 this.registerCompoundsHandler.start();
196                 this.registerItem.start();
197                 this.registerBlock.start();
198                 this.registerChemicalRecipe.start();
199                 this.registerRecipe.start();
200                 this.registerEntitys.start();
201         }
202
203         private void apiProcessing(final FMLPostInitializationEvent event) {
204                 // API用の処理
205                 Iterator<String> langoresItr = this.apiBase.getAtomOresName().iterator();
206                 while (langoresItr.hasNext()){
207                         String lang = langoresItr.next();
208                         ArrayList<String> names = this.apiBase.getAtomOresName().get(lang);
209                         for (int i = 0; i < names.size(); i++) {
210                                 ChemiCraftCore.logger.write("AtomOresAddName:" + "Name-" + names.get(i) + "/Damage-" + (i - i / 16 * 16) + "/Lang-" + lang,
211                                                 EnumLoggingType.INFO);
212
213                                 LanguageRegistry.instance().addNameForObject(
214                                                 new ItemStack(this.blockAtomOres[i / 16], 1, i - i / 16 * 16),
215                                                 lang,
216                                                 names.get(i));
217                         }
218                 }
219         }
220
221 }