OSDN Git Service

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