OSDN Git Service

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