OSDN Git Service

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