OSDN Git Service

3f9044f3fbf57c363260ad0dc4f0eb3f5cdacfee
[chemicraft/chemicraft.git] / common / pcc / chemicraft / core / ChemiCraftCore.java
1 package pcc.chemicraft.core;
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.client.Minecraft;
9 import net.minecraft.creativetab.CreativeTabs;
10 import net.minecraft.entity.Entity;
11 import net.minecraft.entity.player.EntityPlayer;
12 import net.minecraft.item.Item;
13 import net.minecraft.item.ItemStack;
14 import net.minecraft.server.MinecraftServer;
15 import net.minecraft.util.EntityDamageSource;
16 import net.minecraftforge.client.MinecraftForgeClient;
17 import net.minecraftforge.common.Configuration;
18 import net.minecraftforge.common.MinecraftForge;
19 import net.minecraftforge.common.Property;
20 import pcc.chemicraft.ChemiCraft;
21 import pcc.chemicraft.ChemiCraftConfiguration;
22 import pcc.chemicraft.ChemiCraftLogging;
23 import pcc.chemicraft.ChemiCraftRegister;
24 import pcc.chemicraft.EnumLoggingType;
25 import pcc.chemicraft.core.creativetab.CreativeTabChemiCraft;
26 import pcc.chemicraft.core.debug.CommandDeleteItem;
27 import pcc.chemicraft.core.debug.CommandGenDebugRoom;
28 import pcc.chemicraft.core.debug.CommandSetTile;
29 import pcc.chemicraft.core.system.CommonProxy;
30 import pcc.chemicraft.core.system.PacketHandler;
31 import cpw.mods.fml.common.Loader;
32 import cpw.mods.fml.common.LoaderState.ModState;
33 import cpw.mods.fml.common.Mod;
34 import cpw.mods.fml.common.Mod.Init;
35 import cpw.mods.fml.common.Mod.Instance;
36 import cpw.mods.fml.common.Mod.PreInit;
37 import cpw.mods.fml.common.Mod.ServerStarting;
38 import cpw.mods.fml.common.ModContainer;
39 import cpw.mods.fml.common.SidedProxy;
40 import cpw.mods.fml.common.event.FMLInitializationEvent;
41 import cpw.mods.fml.common.event.FMLPreInitializationEvent;
42 import cpw.mods.fml.common.event.FMLServerStartingEvent;
43 import cpw.mods.fml.common.network.NetworkMod;
44 import cpw.mods.fml.common.network.NetworkRegistry;
45 import cpw.mods.fml.common.registry.LanguageRegistry;
46
47 /**
48  * ChemiCraft本体
49  * @author P.C.C.
50  */
51 @Mod(modid = "ChemiCraft", name = "ChemiCraft", version = "Beta1")
52 @NetworkMod(clientSideRequired = true, serverSideRequired = true, versionBounds = "1.4.7", channels = "chemicraftcore", packetHandler = PacketHandler.class)
53 public class ChemiCraftCore extends ChemiCraft{
54
55         /**
56          * 元素名配列
57          */
58         public static final String[] ATOMSNAME = {
59                 "Hydrogen", "Helium", "Lithium", "Beryllium", "Boron", "Carbon", "Nitrogen", "Oxygen", "Fluorine", "Neon", "Sodium", "Magnesium", "Aluminium", "Silicon",
60                 "Phosphorus", "Sulfur", "Chlorine", "Argon", "Potassium", "Calcium", "Scandium", "Titanium", "Vanadium", "Chromium", "Manganese", "Iron", "Cobalt", "Nickel", "Copper", "Zinc", "Gallium",
61                 "Germanium", "Arsenic", "Selenium", "Bromine", "Krypton", "Rubidium", "Strontium", "Yttorium", "Zirconium", "Niobium", "Molybdenum", "Technetium", "Ruthenium", "Rhodium", "Palladium",
62                 "Silver", "Cadmium", "Indium", "Tin", "Antimony", "Tellurium", "Iodine", "Xenon", "Caesium", "Barium", "Lanthanum", "Cerium", "Praseodymium", "Neodymium", "Promethium", "Samarium",
63                 "Europium", "Gadolinium", "Terbium", "Dysprosium", "Holmium", "Erbium", "Thulium", "Ytterbium", "Lutetium", "Hafnium", "Tantalum", "Tungsten", "Rhenium", "Osmium", "Iridium", "Platinum",
64                 "Gold", "Mercury", "Thallium", "Lead", "Bismuth", "Polonium", "Astatine", "Radon", "Francium", "Radium", "Actinium", "Thorium", "Protactinium", "Uranium", "Neptunium", "Plutonium",
65                 "Americium", "Curium", "Berkelium", "Californium", "Einsteinium", "Fermium", "Mendelevium", "Nobelium", "Lawrencium", "Rutherfordium", "Dubnium", "Seaborgium", "Bohrium", "Hassium",
66                 "Meitnerium", "Darmstadtium", "Roentgenium", "Copernicium", "Ununtrium", "Ununquadium", "Ununpentium", "Ununhexium", "Ununseptium", "Ununoctium" };
67
68         /**
69          * 元素名日本語版配列
70          */
71         public static final String[] ATOMSNAMEJP = {
72                 "水素", "ヘリウム", "リチウム", "ベリウム", "ホウ素", "炭素", "窒素", "酸素", "フッ素", "ネオン", "ナトリウム", "マグネシウム", "アルミニウム", "ケイ素", "リン", "硫黄", "塩素", "アルゴン", "カリウム", "カルシウム", "スカンジウム",
73                 "チタン", "バナジウム", "クロム", "マンガン", "鉄", "コバルト", "ニッケル", "銅", "亜鉛", "ガリウム", "ゲルマニウム", "ヒ素", "セレン", "臭素", "クリプトン", "ルビジウム", "ストロンチウム", "イットリウム", "ジルコニウム", "ニオブ", "モリブデン", "テクネチウム", "ルテニウム",
74                 "ロジウム", "パラジウム", "銀", "カドミウム", "インジウム", "スズ", "アンチモン", "テルル", "ヨウ素", "キセノン", "セシウム", "バリウム", "ランタン", "セリウム", "プラセオジム", "ネオジム", "プロメチウム", "サマリウム", "ユウロビウム", "ガドリニウム", "テルビウム", "ジスプロニウム",
75                 "ホルミウム", "エルビウム", "ツリウム", "イッテルビウム", "ルテチウム", "ハフニウム", "タンタル", "タングステン", "レニウム", "オスミウム", "イリジウム", "白金", "金", "水銀", "タリウム", "鉛", "ビスマス", "ポロニウム", "アスタチン", "ラドン", "フランシウム", "ラジウム",
76                 "アクチニウム", "トリウム", "プロトアクチウム", "ウラン", "ネプツニウム", "プルトニウム", "アメリシウム", "キュリウム", "バークリウム", "カルホルニウム", "アインスタイニウム", "フェルミウム", "メンデレビウム", "ノーベリウム", "ローレンシウム", "ラサホージウム", "ドブニウム", "シーボーギウム",
77                 "ボーリウム", "ハッシウム", "マイトネリウム", "ダームスタチウム", "レントゲニウム", "コペルニシウム", "ウンウントリウム", "ウンウンクアジウム", "ウンウンペンチウム", "ウンウンヘキシウム", "ウンウンセプチウム", "ウンウンオクチウム" };
78
79         /**
80          * this is ChemiCraft instance.
81          */
82         @Instance("ChemiCraft")
83         public static ChemiCraftCore instance;
84
85         /**
86          * proxy of ChemiCraft.
87          */
88         @SidedProxy(clientSide = "pcc.chemicraft.core.client.ClientProxy", serverSide = "pcc.chemicraft.core.system.CommonProxy")
89         public static CommonProxy proxy;
90
91         /**
92          * CreativeTab of ChemiCraft.
93          */
94         public static final CreativeTabs creativeTabChemiCraft = new CreativeTabChemiCraft("ChemiCraft");
95
96         /**
97          * API Instance.
98          */
99         public ChemiCraftAPI api = ChemiCraftAPI.instance();
100
101         /**
102          * the ItemID.
103          */
104         public int atomsID;
105         public int compoundsID;
106         public int gasCollectingBottleID;
107         public int chemicalCellsID;
108         public int pearID;
109
110         /**
111          * the BlockID.
112          */
113         public int pyrolysisTableID;
114         public int electrolysisTableID;
115         public int chemicalConbinationTableID;
116         public int toolAndWeaponCraftingTableID;
117         public int chemicalCraftingTableID;
118
119         /**
120          * the GUIID.
121          */
122         public int guiPyrolysisTableID;
123         public int guiElectrolysisTableID;
124         public int guiChemicalCombinationTableID;
125         public int guiToolAndWeaponCraftingTableID;
126         public int guiChemicalCraftingTableID;
127
128         /**
129          * Variables of Block type.
130          */
131         public Block blockPyrolysisTable;
132         public Block blockElectrolysisTable;
133         public Block blockChemicalCombinationTable;
134         public Block blockToolAndWeaponCraftingTable;
135         public Block blockChemicalCraftingTable;
136
137         /**
138          * Variables of Item type.
139          */
140         public Item itemAtoms;
141         public Item itemCompounds;
142         public Item itemGasCollectingBottle;
143         public Item itemChemicalCells;
144         public Item itemPear;
145
146         /**
147          * the Register Instances.
148          */
149         public ChemiCraftRegister registerItem;
150         public ChemiCraftRegister registerBlock;
151         public ChemiCraftRegister registerTileEntity;
152         public ChemiCraftRegister registerRecipe;
153
154         /**
155          * Logging用のインスタンス
156          */
157         public static final ChemiCraftLogging logger = new ChemiCraftLogging(System.getProperty("user.dir"));
158
159         public ChemiCraftCore() {
160                 this.api.getCompoundsName().createHash("en_US");
161                 this.registerItem = new ChemiCraftRegisterItem(this);
162                 this.registerBlock = new ChemiCraftRegisterBlock(this);
163                 this.registerTileEntity = new ChemiCraftRegisterTileEntity(this);
164                 this.registerRecipe = new ChemiCraftRegisterCoreRecipe(this);
165                 this.logger.startLogging();
166                 //this.sinVisualizer  = new SinVisualizer();
167         }
168
169         /**
170          * PreInit:
171          * Configをロードします。
172          * @param event アノテーション呼び出しにより呼び出す必要なし
173          */
174         @PreInit
175         public void chemiPreLoadMethod(final FMLPreInitializationEvent event) {
176                 Configuration cfg = new Configuration(event.getSuggestedConfigurationFile());
177                 cfg.load();
178
179                 Property coreBlockID = cfg.get("BlockID", "Base of Block ID", 2400);
180                 Property coreItemID = cfg.get("ItemID", "Base of Item ID", 25000);
181
182                 ChemiCraftConfiguration ccfgBlock = new ChemiCraftConfiguration(coreBlockID.getInt());
183                 ChemiCraftConfiguration ccfgItem = new ChemiCraftConfiguration(coreItemID.getInt());
184
185                 this.pyrolysisTableID = ccfgBlock.additionID();
186                 this.electrolysisTableID = ccfgBlock.additionID();
187                 this.chemicalConbinationTableID = ccfgBlock.additionID();
188                 this.toolAndWeaponCraftingTableID = ccfgBlock.additionID();
189                 this.chemicalCraftingTableID = ccfgBlock.additionID();
190
191                 this.atomsID = ccfgItem.additionID();
192                 this.compoundsID = ccfgItem.additionID();
193                 this.gasCollectingBottleID = ccfgItem.additionID();
194                 this.chemicalCellsID = ccfgItem.additionID();
195                 this.pearID = ccfgItem.additionID();
196
197                 Property guiPyrolysisTableIDProp = cfg.get("GUI", "GUIPyrolysisID", 1000);
198                 Property guiElectrolysisTableIDProp = cfg.get("GUI", "GUIElectrolysisTableIDProp", 1001);
199                 Property guiChemicalCombinationTableIDProp = cfg.get("GUI", "GUIChemicalCombinationTableID", 1002);
200                 Property guiToolAndWeaponCraftingTableIDProp = cfg.get("GUI", "GUIToolAndWeaponCraftingTableID", 1003);
201                 Property guiChemicalCraftingTableIDProp = cfg.get("GUI", "GUIChemicalCraftingTableID", 1004);
202
203                 this.guiPyrolysisTableID = guiPyrolysisTableIDProp.getInt();
204                 this.guiElectrolysisTableID = guiElectrolysisTableIDProp.getInt();
205                 this.guiChemicalCombinationTableID = guiChemicalCombinationTableIDProp.getInt();
206                 this.guiToolAndWeaponCraftingTableID = guiToolAndWeaponCraftingTableIDProp.getInt();
207                 this.guiChemicalCraftingTableID = guiChemicalCraftingTableIDProp.getInt();
208
209                 cfg.save();
210         }
211
212
213
214         @ServerStarting
215         public void serverStarting(final FMLServerStartingEvent event) {
216                 event.registerServerCommand(new CommandSetTile());
217                 event.registerServerCommand(new CommandDeleteItem());
218                 event.registerServerCommand(new CommandGenDebugRoom());
219         }
220
221
222
223         @Init
224         public void chemiPostLoadMethod(final FMLInitializationEvent event) {
225                 this.thread = new Thread(this);
226                 this.event = event;
227                 this.thread.start();
228
229                 try {
230                         this.thread.join();
231                 } catch (InterruptedException e) {
232                         e.printStackTrace();
233                 }
234
235                 proxy.registerRenderInformation();
236                 Thread.yield();
237         }
238
239
240
241         @Override
242         public void run() {
243                 while (true) {
244                         if (proxy != null && instance != null) {
245                                 this.settingProcessing((FMLInitializationEvent) event);
246                                 this.debug((FMLInitializationEvent) event);
247                                 break;
248                         }
249                 }
250
251                 Thread loadCheckThread = new Thread() {
252                         @Override
253                         public void run() {
254                                 while (true) {
255                                         List<ModContainer> mod = Loader.instance().getModList();
256                                         ModContainer finalMod = mod.get(mod.size()-1);
257                                         ModState finalModState = Loader.instance().getModState(finalMod);
258                                         if (finalModState == ModState.POSTINITIALIZED) {
259                                                 ChemiCraftCore.logger.write("ChemiCraftCore>APIProcessing", EnumLoggingType.INFO);
260                                                 apiProcessing((FMLInitializationEvent) event);
261                                                 break;
262                                         }
263                                 }
264                         }
265                 };
266                 loadCheckThread.start();
267
268         }
269
270
271
272         protected void settingProcessing(final FMLInitializationEvent event) {
273
274                 this.registerItem.start();
275                 this.registerBlock.start();
276                 this.registerRecipe.start();
277                 this.registerTileEntity.start();
278
279                 // GUIを追加します
280                 NetworkRegistry.instance().registerGuiHandler(instance, proxy);
281
282                 this.api.addPyrolysisDecompositionFuel(new ItemStack(Item.coal), 2000*8);
283         }
284
285
286
287         private void apiProcessing(final FMLInitializationEvent event) {
288                 Iterator<String> langcompoundsItr = this.api.getCompoundsName().keySet().iterator();
289                 while (langcompoundsItr.hasNext()) {
290                         String lang = langcompoundsItr.next();
291                         ArrayList<String> names = this.api.getCompoundsName().get(lang);
292                         for (int i = 0; i < names.size(); i++) {
293                                 ChemiCraftCore.logger.write("CompoundAddName:" + "Name-" + names.get(i) + "/Damage-" + i + "/Lang-" + lang,
294                                                 EnumLoggingType.INFO);
295
296                                 LanguageRegistry.instance().addNameForObject(
297                                                 new ItemStack(this.itemCompounds, 1, i),
298                                                 lang,
299                                                 names.get(i));
300                         }
301                 }
302
303         }
304
305
306
307         public static EntityDamageSource getRadiationDamageSource(Entity par1Entity){
308                 return new EntityDamageSource("radiation", par1Entity){
309                         @Override
310                         public String getDeathMessage(EntityPlayer par1EntityPlayer) {
311                                 return par1EntityPlayer.username + " is dead by radiation.";
312                         }
313                 };
314         }
315
316
317
318         private void debug(final FMLInitializationEvent event) {
319                 //this.proxy.registerTickHandler();
320         }
321
322 }