OSDN Git Service

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