OSDN Git Service

いろいろ修正
[chemicraft/chemicraft.git] / common / pcc / chemicraft / ChemiCraft.java
1 package pcc.chemicraft;
2
3 import net.minecraft.block.Block;
4 import net.minecraft.block.material.Material;
5 import net.minecraft.creativetab.CreativeTabs;
6 import net.minecraft.item.Item;
7 import net.minecraft.item.ItemStack;
8 import net.minecraftforge.common.Configuration;
9 import net.minecraftforge.common.Property;
10 import pcc.chemicraft.block.BlockChemicalCombinationTable;
11 import pcc.chemicraft.block.BlockChemicalCraftingTable;
12 import pcc.chemicraft.block.BlockElectrolysisTable;
13 import pcc.chemicraft.block.BlockPyrolysisTable;
14 import pcc.chemicraft.block.BlockToolAndWeaponCraftingTable;
15 import pcc.chemicraft.compounds.CompoundDebug;
16 import pcc.chemicraft.compounds.CompoundWater;
17 import pcc.chemicraft.debug.CommandDeleteItem;
18 import pcc.chemicraft.debug.CommandGenDebugRoom;
19 import pcc.chemicraft.debug.CommandSetTile;
20 import pcc.chemicraft.item.ItemAtoms;
21 import pcc.chemicraft.item.ItemAtomsGrenade;
22 import pcc.chemicraft.item.ItemCompounds;
23 import pcc.chemicraft.item.ItemGasCollectingBottle;
24 import pcc.chemicraft.system.CommonProxy;
25 import pcc.chemicraft.system.PacketHandler;
26 import pcc.chemicraft.tileentity.TileEntityChemicalCombinationTable;
27 import pcc.chemicraft.tileentity.TileEntityChemicalCraftingTable;
28 import pcc.chemicraft.tileentity.TileEntityElectrolysisTable;
29 import pcc.chemicraft.tileentity.TileEntityPyrolysisTable;
30 import pcc.chemicraft.tileentity.TileEntityToolAndWeaponCraftingTable;
31 import pcc.chemicraft.util.Auxiliary;
32 import pcc.chemicraft.util.Auxiliary.ArrayAuxiliary;
33 import pcc.chemicraft.util.Auxiliary.NameAuxiliary;
34 import pcc.chemicraft.util.CreativeTabAtoms;
35 import pcc.chemicraft.util.NBTRecipeGrenade;
36 import cpw.mods.fml.common.Mod;
37 import cpw.mods.fml.common.SidedProxy;
38 import cpw.mods.fml.common.event.FMLPostInitializationEvent;
39 import cpw.mods.fml.common.event.FMLPreInitializationEvent;
40 import cpw.mods.fml.common.event.FMLServerStartingEvent;
41 import cpw.mods.fml.common.network.NetworkMod;
42 import cpw.mods.fml.common.network.NetworkRegistry;
43 import cpw.mods.fml.common.registry.GameRegistry;
44 /**
45  * ChemiCraft本体
46  * @author P.C.C.
47  *
48  */
49 @Mod(modid = "chemiCraft", name = "ChemiCraft", version = "beta")
50 @NetworkMod(clientSideRequired = true, serverSideRequired = true, versionBounds = "1.4.6", channels = "chemicraft", packetHandler = PacketHandler.class)
51 public class ChemiCraft {
52
53         public static final String[] ATOMSNAME = {
54                 "Hydrogen", "Helium", "Lithium", "Beryllium", "Boron", "Carbon", "Nitrogen", "Oxygen", "Fluorine", "Neon", "Sodium", "Magnesium", "Aluminium", "Silicon",
55                 "Phosphorus", "Sulfur", "Chlorine", "Argon", "Potassium", "Calcium", "Scandium", "Titanium", "Vanadium", "Chromium", "Manganese", "Iron", "Cobalt", "Nickel", "Copper", "Zinc", "Gallium",
56                 "Germanium", "Arsenic", "Selenium", "Bromine", "Krypton", "Rubidium", "Strontium", "Yttorium", "Zirconium", "Niobium", "Molybdenum", "Technetium", "Ruthenium", "Rhodium", "Palladium",
57                 "Silver", "Cadmium", "Indium", "Tin", "Antimony", "Tellurium", "Iodine", "Xenon", "Caesium", "Barium", "Lanthanum", "Cerium", "Praseodymium", "Neodymium", "Promethium", "Samarium",
58                 "Europium", "Gadolinium", "Terbium", "Dysprosium", "Holmium", "Erbium", "Thulium", "Ytterbium", "Lutetium", "Hafnium", "Tantalum", "Tungsten", "Rhenium", "Osmium", "Iridium", "Platinum",
59                 "Gold", "Mercury", "Thallium", "Lead", "Bismuth", "Polonium", "Astatine", "Radon", "Francium", "Radium", "Actinium", "Thorium", "Protactinium", "Uranium", "Neptunium", "Plutonium",
60                 "Americium", "Curium", "Berkelium", "Californium", "Einsteinium", "Fermium", "Mendelevium", "Nobelium", "Lawrencium", "Rutherfordium", "Dubnium", "Seaborgium", "Bohrium", "Hassium",
61                 "Meitnerium", "Darmstadtium", "Roentgenium", "Copernicium", "Ununtrium", "Ununquadium", "Ununpentium", "Ununhexium", "Ununseptium", "Ununoctium" };
62
63         public static final String[] ATOMSNAMEJP = {
64                 "水素", "ヘリウム", "リチウム", "ベリウム", "ホウ素", "炭素", "窒素", "酸素", "フッ素", "ネオン", "ナトリウム", "マグネシウム", "アルミニウム", "ケイ素", "リン", "硫黄", "塩素", "アルゴン", "カリウム", "カルシウム", "スカンジウム",
65                 "チタン", "バナジウム", "クロム", "マンガン", "鉄", "コバルト", "ニッケル", "銅", "亜鉛", "ガリウム", "ゲルマニウム", "ヒ素", "セレン", "臭素", "クリプトン", "ルビジウム", "ストロンチウム", "イットリウム", "ジルコニウム", "ニオブ", "モリブデン", "テクネチウム", "ルテニウム",
66                 "ロジウム", "パラジウム", "銀", "カドミウム", "インジウム", "スズ", "アンチモン", "テルル", "ヨウ素", "キセノン", "セシウム", "バリウム", "ランタン", "セリウム", "プラセオジム", "ネオジム", "プロメチウム", "サマリウム", "ユウロビウム", "ガドリニウム", "テルビウム", "ジスプロニウム",
67                 "ホルミウム", "エルビウム", "ツリウム", "イッテルビウム", "ルテチウム", "ハフニウム", "タンタル", "タングステン", "レニウム", "オスミウム", "イリジウム", "白金", "金", "水銀", "タリウム", "鉛", "ビスマス", "ポロニウム", "アスタチン", "ラドン", "フランシウム", "ラジウム",
68                 "アクチニウム", "トリウム", "プロトアクチウム", "ウラン", "ネプツニウム", "プルトニウム", "アメリシウム", "キュリウム", "バークリウム", "カルホルニウム", "アインスタイニウム", "フェルミウム", "メンデレビウム", "ノーベリウム", "ローレンシウム", "ラサホージウム", "ドブニウム", "シーボーギウム",
69                 "ボーリウム", "ハッシウム", "マイトネリウム", "ダームスタチウム", "レントゲニウム", "コペルニシウム", "ウンウントリウム", "ウンウンクアジウム", "ウンウンペンチウム", "ウンウンヘキシウム", "ウンウンセプチウム", "ウンウンオクチウム" };
70
71         /**
72          * このmodのインスタンス
73          */
74         @Mod.Instance("chemiCraft")
75         public static ChemiCraft instance;
76
77         /**
78          * ChemiCraftのProxy.
79          */
80         @SidedProxy(clientSide = "pcc.chemicraft.client.ClientProxy", serverSide = "pcc.chemicraft.system.CommonProxy")
81         public static CommonProxy proxy;
82
83         /**
84          * ChemiCraftのCreativeTab.
85          */
86         public static final CreativeTabs creativeTab = new CreativeTabAtoms("ChemiCraft");
87
88         /**
89          * ItemID.
90          */
91         public int atomsID;
92         public int compoundsID;
93         public int gasCollectingBottleID;
94         public int atomGrenadeID;
95
96         /**
97          * BlockID.
98          */
99         public int pyrolysisTableID;
100         public int electrolysisTableID;
101         public int chemicalConbinationTableID;
102         public int toolAndWeaponCraftingTableID;
103         public int chemicalCraftingTableID;
104
105         /**
106          * GUIID.
107          */
108         public int guiPyrolysisTableID;
109         public int guiElectrolysisTableID;
110         public int guiChemicalCombinationTableID;
111         public int guiToolAndWeaponCraftingTableID;
112         public int guiChemicalCraftingTableID;
113
114         /**
115          * Block型変数.
116          */
117         public Block blockPyrolysisTable;
118         public Block blockElectrolysisTable;
119         public Block blockChemicalCombinationTable;
120         public Block blockToolAndWeaponCraftingTable;
121         public Block blockChemicalCraftingTable;
122
123         /**
124          * Item型変数.
125          */
126         public Item itemAtoms;
127         public Item itemCompounds;
128         public Item itemGasCollectingBottle;
129         public Item itemAtomGrenade;
130
131         /**
132          * このmodで使用するTextureのパス.
133          */
134         public final String ITEMATOMSTEXTURE = "/pcc/chemicraft/items/Atoms.png";
135         public final String ITEMCOMPOUNDSTEXTURE = "/pcc/chemicraft/items/Compounds.png";
136         public final String ITEMTEXTURE = "/pcc/chemicraft/items/items.png";
137         public final String BLOCKCHEMICALCRAFTINGTABLETEXTURE = "/pcc/chemicraft/blocks/cctable.png";
138         public final String GUIPYROLYSISTEXTURE = "/pcc/chemicraft/guis/Pyrolysis.png";
139         public final String GUIELECTROLYSISTEXTURE = "/pcc/chemicraft/guis/Electrolysis.png";
140         public final String GUICHEMICALCOMBINATIONTEXTURE = "/pcc/chemicraft/guis/ChemicalCombination.png";
141         public final String GUITOOLANDWEAPONCRAFTINGTEXTURE = "/pcc/chemicraft/guis/ToolAndWeaponCrafting.png";
142         public final String GUICHEMICALCRAFTINGTEXTURE = "/pcc/chemicraft/guis/MaterialCrafting.png";
143
144         /**
145          * このmodに必要な補助クラスのインスタンス.
146          */
147         public Auxiliary auxiliary = new Auxiliary();
148         public NameAuxiliary nameAuxiliary = new NameAuxiliary();
149         public ArrayAuxiliary arrayAuxiliary = new ArrayAuxiliary();
150
151         private ChemiCraftAPI api = ChemiCraftAPI.getInstance();
152         private ChemiCraftData chemicalData = new ChemiCraftData();
153
154         @Mod.PreInit
155         public void chemiPreLoadMethod(final FMLPreInitializationEvent event) {
156                 Configuration cfg = new Configuration(event.getSuggestedConfigurationFile());
157                 cfg.load();
158
159                 Property pyrolysisTableIDProp = cfg.getBlock("PyrolysisTable", 2400);
160                 Property electrolysisTableIDProp = cfg.getBlock("ElectrolysisTable", 2401);
161                 Property chemicalCombinationTableIDProp = cfg.getBlock("ChemicalCombinationID", 2402);
162                 Property toolAndWeaponCraftingTableIDProp = cfg.getBlock("ToolAndWeaponCraftingTableID", 2403);
163                 Property chemicalCraftingTableIDProp = cfg.getBlock("ChemicalCraftingTableID", 2404);
164
165                 Property atomsIDProp = cfg.getItem("AtomsID", 25000);
166                 Property compoundsIDProp = cfg.getItem("CompoundsID", 25001);
167                 Property gasCollectingBottleIDProp = cfg.getItem("gasCollectingBottleID", 25002);
168                 Property atomGrenadeIDProp = cfg.getItem("AtomGrenadeID", 25003);
169
170                 Property guiPyrolysisTableIDProp = cfg.get("GUI", "GUIPyrolysisID", 1000);
171                 Property guiElectrolysisTableIDProp = cfg.get("GUI", "GUIElectrolysisTableIDProp", 1001);
172                 Property guiChemicalCombinationTableIDProp = cfg.get("GUI", "GUIChemicalCombinationTableID", 1002);
173                 Property guiToolAndWeaponCraftingTableIDProp = cfg.get("GUI", "GUIToolAndWeaponCraftingTableID", 1003);
174                 Property guiChemicalCraftingTableIDProp = cfg.get("GUI", "GUIChemicalCraftingTableID", 1004);
175
176
177                 this.pyrolysisTableID = pyrolysisTableIDProp.getInt();
178                 this.electrolysisTableID = electrolysisTableIDProp.getInt();
179                 this.chemicalConbinationTableID = chemicalCombinationTableIDProp.getInt();
180                 this.toolAndWeaponCraftingTableID = toolAndWeaponCraftingTableIDProp.getInt();
181                 this.chemicalCraftingTableID = chemicalCraftingTableIDProp.getInt();
182                 this.atomsID = atomsIDProp.getInt();
183                 this.compoundsID = compoundsIDProp.getInt();
184                 this.gasCollectingBottleID = gasCollectingBottleIDProp.getInt();
185                 this.atomGrenadeID = atomGrenadeIDProp.getInt();
186                 this.guiPyrolysisTableID = guiPyrolysisTableIDProp.getInt();
187                 this.guiElectrolysisTableID = guiElectrolysisTableIDProp.getInt();
188                 this.guiChemicalCombinationTableID = guiChemicalCombinationTableIDProp.getInt();
189                 this.guiToolAndWeaponCraftingTableID = guiToolAndWeaponCraftingTableIDProp.getInt();
190                 this.guiChemicalCraftingTableID = guiChemicalCraftingTableIDProp.getInt();
191
192                 cfg.save();
193         }
194
195         @Mod.ServerStarting
196         public void serverStarting(final FMLServerStartingEvent event) {
197                 event.registerServerCommand(new CommandSetTile());
198                 event.registerServerCommand(new CommandDeleteItem());
199                 event.registerServerCommand(new CommandGenDebugRoom());
200         }
201
202         @Mod.PostInit
203         public void chemiPostLoadMethod(final FMLPostInitializationEvent event) {
204                 this.settingProcessing(event);
205                 this.apiProcessing(event);
206                 this.debug(event);
207         }
208
209         private void settingProcessing(final FMLPostInitializationEvent event) {
210
211                 // Blockを追加します
212                 this.blockPyrolysisTable = new BlockPyrolysisTable(this.pyrolysisTableID, 0, Material.ground).
213                                 setHardness(2.0F).
214                                 setResistance(0.0F).
215                                 setStepSound(Block.soundStoneFootstep).
216                                 setBlockName("PyrolysisTable");
217                 this.blockChemicalCombinationTable = new BlockChemicalCombinationTable(this.chemicalConbinationTableID, 0, Material.ground).
218                                 setHardness(2.0F).
219                                 setResistance(0.0F).
220                                 setStepSound(Block.soundStoneFootstep).
221                                 setBlockName("ChemicalCombinationTable");
222                 this.blockToolAndWeaponCraftingTable = new BlockToolAndWeaponCraftingTable(this.toolAndWeaponCraftingTableID, 0, Material.ground).
223                                 setHardness(2.0F).
224                                 setResistance(0.0F).
225                                 setStepSound(Block.soundStoneFootstep).
226                                 setBlockName("ToolAndWeaponCraftingTable");
227                 this.blockChemicalCraftingTable = new BlockChemicalCraftingTable(this.chemicalCraftingTableID, 0, Material.ground).
228                                 setHardness(2.0F).
229                                 setResistance(0.0F).
230                                 setStepSound(Block.soundStoneFootstep).
231                                 setBlockName("ChemicalCraftingTable");
232                 this.blockElectrolysisTable = new BlockElectrolysisTable(this.electrolysisTableID, 0, Material.ground).
233                                 setHardness(2.0F).
234                                 setResistance(0.0F).
235                                 setStepSound(Block.soundStoneFootstep).
236                                 setBlockName("ElectrolysisTable");
237
238                 // Itemを追加します
239                 this.itemAtoms = new ItemAtoms(this.atomsID).setItemName("atoms");
240                 this.itemCompounds = new ItemCompounds(this.compoundsID).setItemName("compounds");
241                 this.itemGasCollectingBottle = new ItemGasCollectingBottle(this.gasCollectingBottleID).setItemName("gasCollectingBottle").setIconIndex(0);
242                 this.itemAtomGrenade = new ItemAtomsGrenade(this.atomGrenadeID).setItemName("grenade").setIconIndex(1);
243
244                 // BlockをMinecraftに登録します
245                 GameRegistry.registerBlock(this.blockPyrolysisTable, "BlockPyrolysisTable");
246                 GameRegistry.registerBlock(this.blockChemicalCombinationTable, "BlockChemicalCombinationTable");
247                 GameRegistry.registerBlock(this.blockToolAndWeaponCraftingTable, "BlockToolAndWeaponCraftingTable");
248                 GameRegistry.registerBlock(this.blockChemicalCraftingTable, "BlockMaterialCraftingTable");
249                 GameRegistry.registerBlock(this.blockElectrolysisTable, "BlockElectrolysisTable");
250
251                 // Blockの名前を設定します
252                 this.nameAuxiliary.addName(this.blockPyrolysisTable, "PyrolysisTable");
253                 this.nameAuxiliary.addName(this.blockPyrolysisTable, "ja_JP", "熱分解台");
254                 this.nameAuxiliary.addName(this.blockChemicalCombinationTable, "ChemicalCombinationTable");
255                 this.nameAuxiliary.addName(this.blockChemicalCombinationTable, "ja_JP", "化合台");
256                 this.nameAuxiliary.addName(this.blockToolAndWeaponCraftingTable, "ToolAndWeaponCraftingTable");
257                 this.nameAuxiliary.addName(this.blockToolAndWeaponCraftingTable, "ja_JP", "ツール&武器製作台");
258                 this.nameAuxiliary.addName(this.blockChemicalCraftingTable, "ChemicalCraftingTable");
259                 this.nameAuxiliary.addName(this.blockChemicalCraftingTable, "ja_JP", "素材製作台");
260                 this.nameAuxiliary.addName(this.blockElectrolysisTable, "ElectrolysisTable");
261                 this.nameAuxiliary.addName(this.blockElectrolysisTable, "ja_JP", "電気分解台");
262
263                 // Itemの名前を設定します
264                 this.nameAuxiliary.addName(this.itemAtoms, ATOMSNAME);
265                 this.nameAuxiliary.addName(this.itemAtoms, "ja_JP", ATOMSNAMEJP);
266                 this.nameAuxiliary.addName(this.itemGasCollectingBottle, "GasCollectingBottle");
267                 this.nameAuxiliary.addName(this.itemGasCollectingBottle, "ja_JP", "集気瓶");
268                 this.nameAuxiliary.addName(this.itemAtomGrenade, "AtomGrenade");
269                 this.nameAuxiliary.addName(this.itemAtomGrenade, "元素手榴弾");
270
271                 // TileEntityを追加します
272                 GameRegistry.registerTileEntity(TileEntityPyrolysisTable.class, "TileEntityPyrolysisTable");
273                 GameRegistry.registerTileEntity(TileEntityChemicalCombinationTable.class, "TileEntityChemicalCombinationTable");
274                 GameRegistry.registerTileEntity(TileEntityToolAndWeaponCraftingTable.class, "TileEntityToolAndWeaponCraftingTable");
275                 GameRegistry.registerTileEntity(TileEntityChemicalCraftingTable.class, "TileEntityChemicalCraftingTable");
276                 GameRegistry.registerTileEntity(TileEntityElectrolysisTable.class, "TileEntityElectrolysisTable");
277
278                 // GUIを追加します
279                 NetworkRegistry.instance().registerGuiHandler(instance, proxy);
280
281                 // 描画関係の読み込み
282                 proxy.registerRenderInformation();
283
284                 //化学作業台類のレシピを追加します
285                 GameRegistry.addRecipe(new ItemStack(this.blockPyrolysisTable),
286                                 new Object[]{
287                         "XYX", "ZAZ", "ZZZ",
288                         Character.valueOf('X'), new ItemStack(Item.ingotIron),
289                         Character.valueOf('Y'), new ItemStack(Block.workbench),
290                         Character.valueOf('Z'), new ItemStack(Block.stone),
291                         Character.valueOf('A'), new ItemStack(Item.bucketLava),
292                 });
293                 GameRegistry.addRecipe(new ItemStack(this.blockChemicalCombinationTable),
294                                 new Object[]{
295                         "XYX", "ZAZ", "ZZZ",
296                         Character.valueOf('X'), new ItemStack(Item.ingotIron),
297                         Character.valueOf('Y'), new ItemStack(Block.workbench),
298                         Character.valueOf('Z'), new ItemStack(Block.stone),
299                         Character.valueOf('A'), new ItemStack(Block.obsidian),
300                 });
301                 GameRegistry.addRecipe(new ItemStack(this.blockToolAndWeaponCraftingTable),
302                                 new Object[]{
303                         "XYX", "ZAZ", "ZZZ",
304                         Character.valueOf('X'), new ItemStack(Item.ingotIron),
305                         Character.valueOf('Y'), new ItemStack(Block.workbench),
306                         Character.valueOf('Z'), new ItemStack(Block.stone),
307                         Character.valueOf('A'), new ItemStack(Item.pickaxeSteel),
308                 });
309                 GameRegistry.addRecipe(new ItemStack(this.blockChemicalCraftingTable),
310                                 new Object[]{
311                         "XYX", "ZAZ", "ZZZ",
312                         Character.valueOf('X'), new ItemStack(Item.ingotIron),
313                         Character.valueOf('Y'), new ItemStack(Block.workbench),
314                         Character.valueOf('Z'), new ItemStack(Block.stone),
315                         Character.valueOf('A'), new ItemStack(this.itemAtoms, 1, 0),
316                 });
317
318                 // 化合物を追加します
319                 api.addLangCompound("ja_JP", "CarbonMonoxide", "一酸化炭素");
320                 api.addLangCompound("ja_JP", "CarbonDioxide", "二酸化炭素");
321                 api.addLangCompound("ja_JP", "Water", "水");
322
323
324                 //化合物のHandlerを設定します
325                 api.settingCompoundHandler("Water", new CompoundWater());
326
327                 //化合物のレシピを追加します
328                 api.addChemicalCombinationRecipe(new String[]{"H", "O"}, new Integer[]{2, 1}, new ItemStack(this.itemCompounds, 1, api.getCompound("Water")));
329
330                 //手榴弾の追加
331                 api.addMaterialRecipe(new ItemStack[] {
332                                 null,
333                                 new ItemStack(Block.stone),
334                                 null,
335                                 new ItemStack(Block.stone),
336                                 new ItemStack(Item.gunpowder),
337                                 new ItemStack(Block.stone),
338                                 null,
339                                 new ItemStack(Block.stone),
340                                 null
341                 },
342                 new ItemStack(this.itemAtomGrenade, 16, 0),
343                 new NBTRecipeGrenade()
344                                 );
345
346                 api.addDecompositionRecipe(new ItemStack(Item.potion, 1, 0),
347                                 new int[] {ChemiCraftData.HYDROGEN, ChemiCraftData.OXYGEN},
348                                 new int[] {2, 1});
349
350                 api.addDecompositionRecipe(new ItemStack(this.itemCompounds, 1, api.getCompound("Water")),
351                                 new int[] {ChemiCraftData.HYDROGEN, ChemiCraftData.OXYGEN},
352                                 new int[] {2, 1});
353
354                 api.addDecompositionFuel(new ItemStack(Item.coal), 2000*8);
355         }
356
357         private void apiProcessing(final FMLPostInitializationEvent event) {
358                 // API用の処理
359                 this.nameAuxiliary.addName(itemCompounds, api.getInstance().getCompoundsName().toArray());
360                 for (int i = 0; i < api.getCompoundsLang().size(); i++) {
361                         this.nameAuxiliary.addName(itemCompounds, api.getCompoundsLang().get(i), api.getInstance().getCompoundsLangName().toArray());
362                 }
363         }
364
365         private void debug(final FMLPostInitializationEvent event) {
366                 //DebugTickingの追加
367                 this.proxy.registerTickHandler();
368                 this.api.addCompound("Debug");
369                 this.api.settingCompoundHandler("Debug", new CompoundDebug());
370
371                 /*
372                  * TWDebug
373                  */
374                 api.addToolAndWeaponRecipe(new ItemStack[] {
375                                 new ItemStack(Block.stone, 1, 1)
376                 },
377                 new ItemStack(Block.dirt, 1, 0));
378         }
379
380 }