OSDN Git Service

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