OSDN Git Service

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