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