OSDN Git Service

finalBuild(1.5.1移行)
[chemicraft/ChemiCraftNext.git] / common / pcc / chemicraft / core / ChemiCraftAPI.java
1 package pcc.chemicraft.core;
2
3 import java.util.ArrayList;
4 import java.util.Arrays;
5 import java.util.HashMap;
6 import java.util.Iterator;
7 import java.util.TreeMap;
8
9 import net.minecraft.item.ItemStack;
10 import pcc.chemicraft.ChemiCraftData;
11 import pcc.chemicraft.EnumLoggingType;
12 import pcc.chemicraft.core.nbt.ChemicalNBTRecipe;
13 import pcc.chemicraft.core.system.ChemiCraftCraftingManager;
14 import pcc.chemicraft.util.Formula;
15 import pcc.chemicraft.util.ICompoundHandler;
16 import pcc.chemicraft.util.ListHash;
17 import pcc.chemicraft.util.MaterialRecipe;
18
19
20 /**
21  * ChemiCraftのAPIを提供するクラスです<br>
22  * ChemiCraftのAPIを作成する場合はこのクラスを使用します<br>
23  * @author mozipi
24  *
25  */
26 public class ChemiCraftAPI {
27
28         /**
29          * APIのインスタンス
30          */
31         private static ChemiCraftAPI instance = new ChemiCraftAPI();
32
33
34         /**
35          * APIのインスタンスを返します
36          * @return APIのインスタンス
37          */
38         public static ChemiCraftAPI instance(){
39                 return instance;
40         }
41
42
43         /**
44          * 化合台の原子の数のリスト
45          */
46         private static ArrayList<Integer[]> chemicalCombinationAmounts = new ArrayList<Integer[]>();
47
48
49         /**
50          * 化合台の原子の種類のリスト
51          */
52         private static ArrayList<String[]> chemicalCombinationAtoms = new ArrayList<String[]>();
53
54
55         /**
56          * 化合台の結果のリスト
57          */
58         private static ArrayList<ItemStack> chemicalCombinationResult = new ArrayList<ItemStack>();
59
60
61         /**
62          * ChemiCraftの化学作業台類のレシピのマネージャー
63          */
64         private static ChemiCraftCraftingManager chemiCraftCraftingManager = new ChemiCraftCraftingManager();
65
66
67         /**
68          * List of item name of handler to compounds.
69          */
70         private static ArrayList<String> compoundHandlerItemNames = new ArrayList<String>();
71
72
73         /**
74          * 化合物の英語名からダメージ値へのマップ
75          */
76         private static TreeMap<String, Integer> compoundsDamageToString = new TreeMap<String, Integer>();
77
78
79         /**
80          * 化合物のテクスチャマップ
81          */
82         private static TreeMap<Integer, String> compoundsTexture = new TreeMap<Integer, String>();
83
84
85         /**
86          * List of compounds handlers.
87          */
88         private static ArrayList<ICompoundHandler> compoundHandlers = new ArrayList<ICompoundHandler>();
89
90
91         /**
92          * 化合物の文字列をダメージ値に変換します。
93          */
94         private static HashMap<String, Integer> compoundHash = new HashMap<String, Integer>();
95
96
97         /**
98          * List of compounds names.
99          */
100         private static ListHash<String, String> compoundsNameListHash = new ListHash<String, String>();
101
102
103         /**
104          * 電気分解燃料のリスト。
105          */
106         private static HashMap<ItemStack, Integer> electrolysisFuelList = new HashMap<ItemStack, Integer>();
107
108
109         /**
110          * 電気分解レシピのリスト
111          */
112         private static HashMap<ItemStack, ItemStack[]> electrolysisRecipeList = new HashMap<ItemStack, ItemStack[]>();
113
114
115         /**
116          * 素材製作台のレシピクラス
117          */
118         private static ArrayList<MaterialRecipe> materialRecipe = new ArrayList<MaterialRecipe>();
119
120
121         /**
122          * 熱分解燃料のリスト。
123          */
124         private static HashMap<ItemStack, Integer> pyrolysisFuelList = new HashMap<ItemStack, Integer>();
125
126
127         /**
128          * 熱分解レシピのリスト
129          */
130         private static HashMap<ItemStack, ItemStack[]> pyrolysisRecipeList = new HashMap<ItemStack, ItemStack[]>();
131
132
133         /**
134          * ツール&武器作成台の素材一覧のリスト
135          */
136         private static ArrayList<ItemStack[]> toolAndWeaponMaterials = new ArrayList<ItemStack[]>();
137
138
139         /**
140          * ツール&武器作成台の結果のリスト
141          */
142         private static ArrayList<ItemStack> toolAndWeaponResult = new ArrayList<ItemStack>();
143
144
145         /**
146          * ツール&武器作成台の不定形であるか
147          */
148         private static ArrayList<Boolean> toolAndWeaponSharpless = new ArrayList<Boolean>();
149
150
151
152         /**
153          * 化合レシピを追加します。materialの要素数は0<= n <= 16にしてください。
154          * @param material 素材
155          * @param result 結果
156          */
157         public static void addChemicalCombinationRecipe(ItemStack result, Formula formula){
158                 ChemiCraftCore.logger.write("addChemicalCombinationRecipe:" + "Result-" + result.getItemName() + "/Material-" + Arrays.toString(formula.getAtoms())
159                                 , EnumLoggingType.INFO);
160                 chemicalCombinationAtoms.add(formula.getAtoms());
161                 chemicalCombinationAmounts.add(formula.getAmonts());
162                 chemicalCombinationResult.add(result);
163         }
164
165
166
167         private static int compoundTexturePointer = 0;
168         /**
169          * 化合物を追加します
170          * @param name 化合物の名前
171          */
172         public static void addCompound(String name){
173                 ChemiCraftCore.logger.write("addCompound:" + name
174                                 , EnumLoggingType.INFO);
175
176                 compoundsDamageToString.put(name, compoundTexturePointer);
177                 compoundsTexture.put(compoundTexturePointer, "ChemiCraft:CompoundEmpty");
178                 compoundTexturePointer++;
179                 compoundsNameListHash.add("en_US", name);
180                 compoundHash.put(name, compoundHash.size());
181         }
182
183
184         /**
185          * 既に登録された化合物に対して別の言語をを追加します
186          * @param lang 別言語名
187          * @param englishName 英語名
188          * @param langName 別言語への名前
189          */
190         public static void addCompound(String lang, String englishName, String langName){
191                 ChemiCraftCore.logger.write("addCompound(MultiLang):" + "lang-" + lang + "/name-" + englishName + "/langToName-" + langName
192                                 , EnumLoggingType.INFO);
193                 addCompound(englishName);
194                 addCompoundLanguage(lang, langName);
195         }
196
197
198
199         /**
200          * 単体で使用すると異常が発生するため、API以外での使用を固く非推奨する
201          * @param lang 言語名
202          * @param langName 言語への名前
203          */
204         @Deprecated
205         private static void addCompoundLanguage(String lang, String langName){
206                 compoundsNameListHash.add(
207                                 lang,
208                                 langName);
209         }
210
211
212
213         /**
214          * 電気分解台のレシピを追加します
215          * @param material 素材
216          * @param formula 化学式(結果)
217          */
218         public static void addElectrolysisDecompositionRecipe(ItemStack material, Formula formula) {
219                 ChemiCraftCore.logger.write("addElectrolysisRecipe:" + "Material-" + material.getItemName() + "/Result-" + Arrays.toString(formula.getAtoms()),
220                                 EnumLoggingType.INFO);
221
222                 ItemStack[] itemstacks =
223                                 new ItemStack[formula.getAtoms().length];
224                 for (int i = 0; i < itemstacks.length; i++) {
225                         itemstacks[i] =
226                                         new ItemStack(
227                                                         ChemiCraftCore.instance.itemAtoms,
228                                                         formula.getAmonts()[i],
229                                                         ChemiCraftData.toAtoms(formula.getAtoms()[i]));
230                 }
231                 electrolysisRecipeList.put(
232                                 material,
233                                 itemstacks);
234         }
235
236
237
238         /**
239          * 電気分解台のレシピを追加します
240          * @param material 素材 (すべて結果は同じになります)
241          * @param formula 化学式(結果)
242          */
243         public static void addElectrolysisDecompositionRecipe(ArrayList<ItemStack> material, Formula formula) {
244                 for (ItemStack item : material) {
245                         if (item != null) {
246                                 addElectrolysisDecompositionRecipe(item, formula);
247                         }
248                 }
249         }
250
251
252
253         /**
254          * 熱分解台のレシピを追加します
255          * @param material 素材
256          * @param formula 化学式(結果)
257          */
258         public static void addPyrolysisDecompositionRecipe(ItemStack material, Formula formula) {
259                 ChemiCraftCore.logger.write("addPyrolysisRecipe:" + "Material-" + material.getItemName() + "/Result-" + Arrays.toString(formula.getAtoms()),
260                                 EnumLoggingType.INFO);
261
262                 ItemStack[] itemstacks =
263                                 new ItemStack[formula.getAtoms().length];
264                 for (int i = 0; i < itemstacks.length; i++) {
265                         itemstacks[i] =
266                                         new ItemStack(
267                                                         ChemiCraftCore.instance.itemAtoms,
268                                                         formula.getAmonts()[i],
269                                                         ChemiCraftData.toAtoms(formula.getAtoms()[i]));
270                 }
271                 pyrolysisRecipeList.put(
272                                 material,
273                                 itemstacks);
274         }
275
276
277
278         /**
279          * 熱分解台のレシピを追加します
280          * @param material 素材 (すべて結果は同じになります)
281          * @param formula 化学式(結果)
282          */
283         public static void addPyrolysisDecompositionRecipe(ArrayList<ItemStack> material, Formula formula) {
284                 for (ItemStack item : material) {
285                         if (item != null) {
286                                 addPyrolysisDecompositionRecipe(item, formula);
287                                 return;
288                         }
289                 }
290         }
291
292
293
294         /**
295          * 化合,熱分解,電気分解ができるレシピを追加します
296          * @param materialAndResult 素材(分解)と結果(化合)
297          * @param formula 化学式(分解なら結果に。化合なら素材に)
298          */
299         public static void addReversible(ItemStack materialAndResult, Formula formula){
300                 addChemicalCombinationRecipe(materialAndResult, formula);
301                 addPyrolysisDecompositionRecipe(materialAndResult, formula);
302                 addElectrolysisDecompositionRecipe(materialAndResult, formula);
303         }
304
305
306
307         /**
308          * 化合,電気分解ができるレシピを追加します
309          * @param materialAndResult 素材(分解)と結果(化合)
310          * @param formula 化学式(分解なら結果に。化合なら素材に)
311          */
312         public static void addReversibleOfElectrolysis(ItemStack result, Formula formula){
313                 addChemicalCombinationRecipe(result, formula);
314                 addElectrolysisDecompositionRecipe(result, formula);
315         }
316
317
318
319         /**
320          * 化合,熱分解ができるレシピを追加します
321          * @param materialAndResult 素材(分解)と結果(化合)
322          * @param formula 化学式(分解なら結果に。化合なら素材に)
323          */
324         public static void addReversibleOfPyrolysis(ItemStack result, Formula formula){
325                 addChemicalCombinationRecipe(result, formula);
326                 addPyrolysisDecompositionRecipe(result, formula);
327         }
328
329
330
331         /**
332          * 電気分解台の燃料を追加します
333          * @param itemstack 燃料のItemStack
334          * @param burnTime 燃焼時間(tick * rate)
335          */
336         public static void addElectrolysisDecompositionFuel(ItemStack itemstack, int burnTime) {
337                 ChemiCraftCore.logger.write("addElectrolysisFuel:" + "Fuel-" + itemstack.getItemName() + "/BurnTime-" + burnTime,
338                                 EnumLoggingType.INFO);
339
340                 electrolysisFuelList.put(
341                                 itemstack,
342                                 burnTime);
343         }
344
345
346
347         /**
348          * 熱分解台の燃料を追加します
349          * @param itemstack 燃料のItemStack
350          * @param burnTime 燃焼時間(tick * rate)
351          */
352         public static void addPyrolysisDecompositionFuel(ItemStack itemstack, int burnTime) {
353                 ChemiCraftCore.logger.write("addPyrolysisFuel:" + "Fuel-" + itemstack.getItemName() + "/BurnTime-" + burnTime,
354                                 EnumLoggingType.INFO);
355
356                 pyrolysisFuelList.put(
357                                 itemstack,
358                                 burnTime);
359         }
360
361
362
363         /**
364          * 素材作成台のレシピを追加します
365          * @param materials 素材
366          * @param result 結果
367          * @param nbtRecipe NBT(Nullの場合はなし)
368          */
369         public static void addMaterialRecipe(ItemStack[] materials, ItemStack result, ChemicalNBTRecipe nbtRecipe){
370                 ChemiCraftCore.logger.write("addMaterialRecipe:" + "Materials-" + Arrays.toString(materials) + "/Result-" + result.getItemName() + "/NBT-" + nbtRecipe,
371                                 EnumLoggingType.INFO);
372
373                 materialRecipe.add(
374                                 new MaterialRecipe(
375                                                 result,
376                                                 materials,
377                                                 nbtRecipe,
378                                                 false));
379         }
380
381
382
383         /**
384          * 素材作成台の不定形レシピを追加します
385          * @param materials 素材
386          * @param result 結果
387          * @param nbtRecipe NBT(Nullの場合はなし)
388          */
389         public static void addSharplessMaterialRecipe(ItemStack[] materials, ItemStack result, ChemicalNBTRecipe nbtRecipe){
390                 ChemiCraftCore.logger.write("addMaterialRecipe:" + "Materials-" + Arrays.toString(materials) + "/Result-" + result.getItemName() + "/NBT-" + nbtRecipe,
391                                 EnumLoggingType.INFO);
392
393                 materialRecipe.add(
394                                 new MaterialRecipe(
395                                                 result,
396                                                 materials,
397                                                 nbtRecipe,
398                                                 true));
399         }
400
401
402
403         /**
404          * 化合物のハンドラーを設定します。<br>
405          * CompoundHandlerを実装したクラスをcompoundHandlerに入れることによってhandlerItemNameで指定した<br>
406          * 化合物にハンドラーをつけることができます。
407          * @param handlerItemName ハンドラーをつける化合物の英語名
408          * @param compoundHandler ハンドラー
409          */
410         public static void settingCompoundHandler(String handlerItemName, ICompoundHandler compoundHandler){
411                 ChemiCraftCore.logger.write("settingCompoundHandler:" + "Name-" + handlerItemName + "/CompoundHandler-" + compoundHandler,
412                                 EnumLoggingType.INFO);
413
414                 if (compoundHandler.getIconIndexHandler() != null) {
415                         int p = compoundsDamageToString.get(handlerItemName);
416                         if (p != -1) {
417                                 compoundsTexture.put(p, compoundHandler.getIconIndexHandler());
418                         } else {
419                                 System.out.println("化合物が存在しません(settingCompoundHandler)");
420                         }
421                 }
422
423                 compoundHandlers.add(compoundHandler);
424                 compoundHandlerItemNames.add(handlerItemName);
425         }
426
427
428
429         /**
430          * ツール&武器作成台のレシピを追加します<br>
431          * 未作成であり、動作しません
432          * @param materials 素材
433          * @param result 結果
434          */
435         @Deprecated
436         public static void addToolAndWeaponRecipe(ItemStack[] materials, ItemStack result) {
437                 toolAndWeaponMaterials.add(materials);
438                 toolAndWeaponResult.add(result);
439                 toolAndWeaponSharpless.add(false);
440         }
441
442
443
444         /**
445          * ツール&武器作成台の不定形レシピを追加します<br>
446          *       * 未作成であり、動作しません
447          * @param materials 素材
448          * @param result 結果
449          */
450         @Deprecated
451         public static void addSharplessToolAndWeaponRecipe(ItemStack[] materials, ItemStack result) {
452                 toolAndWeaponMaterials.add(materials);
453                 toolAndWeaponResult.add(result);
454                 toolAndWeaponSharpless.add(true);
455         }
456
457
458
459         //以下システム関連//////////////////////////////////////////////////////
460
461         public static ArrayList<Integer[]> getChemicalCombinationAmounts() {
462                 return chemicalCombinationAmounts;
463         }
464
465
466
467         public static ArrayList<String[]> getChemicalCombinationAtoms() {
468                 return chemicalCombinationAtoms;
469         }
470
471
472
473         public static ArrayList<ItemStack> getChemicalCombinationResult() {
474                 return chemicalCombinationResult;
475         }
476
477
478
479         public static int getCompound(String key) {
480                 if (compoundHash.get(key) != null) {
481                         return compoundHash.get(key);
482                 } else {
483                         return -1;
484                 }
485         }
486
487
488
489         public static ArrayList<ICompoundHandler> getCompoundHandler() {
490                 compoundHandlers.trimToSize();
491                 return compoundHandlers;
492         }
493
494
495
496         public static ArrayList<String> getCompoundHandlerItemName() {
497                 compoundHandlerItemNames.trimToSize();
498                 return compoundHandlerItemNames;
499         }
500
501
502
503         public static ListHash<String, String> getCompoundsName() {
504                 return compoundsNameListHash;
505         }
506
507
508
509         public static ChemiCraftCraftingManager getCraftingManager() {
510                 return chemiCraftCraftingManager;
511         }
512
513
514
515         public static HashMap<ItemStack, Integer> getElectrolysisFuelList() {
516                 return electrolysisFuelList;
517         }
518
519
520
521         public static HashMap<ItemStack, ItemStack[]> getElectrolysisRecipeList() {
522                 return electrolysisRecipeList;
523         }
524
525
526
527         public static ArrayList<MaterialRecipe> getMaterialRecipe() {
528                 return materialRecipe;
529         }
530
531
532
533         public static HashMap<ItemStack, Integer> getPyrolysisFuelList() {
534                 return pyrolysisFuelList;
535         }
536
537
538
539         public static HashMap<ItemStack, ItemStack[]> getPyrolysisRecipeList() {
540                 return pyrolysisRecipeList;
541         }
542
543
544
545         public static ArrayList<ItemStack[]> getToolAndWeaponMaterials() {
546                 return toolAndWeaponMaterials;
547         }
548
549
550
551         public static ArrayList<ItemStack> getToolAndWeaponResult() {
552                 return toolAndWeaponResult;
553         }
554
555
556
557         public static ArrayList<Boolean> getToolAndWeaponSharpless() {
558                 return toolAndWeaponSharpless;
559         }
560
561
562
563         public static ArrayList<String> getCompoundsTexture() {
564                 Iterator<String> it = compoundsTexture.values().iterator();
565                 ArrayList<String> li = new ArrayList<String>();
566                 while (it.hasNext()) {
567                         li.add(it.next());
568                 }
569                 return li;
570         }
571
572 }