OSDN Git Service

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