OSDN Git Service

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