OSDN Git Service

修正・変更
[chemicraft/chemicraft.git] / common / chemicraft / ChemiCraftAPI.java
1 package chemicraft;
2
3 import java.util.ArrayList;
4 import java.util.HashMap;
5
6 import net.minecraft.item.ItemStack;
7 import chemicraft.system.ChemiCraftCraftingManager;
8 import chemicraft.tileentity.TileEntityPyrolysisTable;
9 import chemicraft.util.ChemicalNBTRecipe;
10 import chemicraft.util.ICompoundHandler;
11 import chemicraft.util.MaterialRecipe;
12
13 /**
14  * ChemiCraftのAPI
15  * 基本的にAddonはこのクラスのインスタンスを使う
16  * @author mozipi
17  *
18  */
19 public class ChemiCraftAPI {
20
21         /**
22          * Instance of the ChemiCraftAPI.
23          */
24         private static ChemiCraftAPI instance = new ChemiCraftAPI();
25
26
27         /**
28          * List of compounds names.
29          */
30         private ArrayList<String> compoundsNameList = new ArrayList<String>();
31
32
33         /**
34          * List of compounds names(Some kind of language).
35          */
36         private ArrayList<String> compoundsLangNameList = new ArrayList<String>();
37
38
39         /**
40          * List of compounds the language names.
41          */
42         private ArrayList<String> compoundsLangList = new ArrayList<String>();
43
44
45         /**
46          * List of compounds handlers.
47          */
48         private ArrayList<ICompoundHandler> compoundHandlers = new ArrayList<ICompoundHandler>();
49
50
51         /**
52          * 化合物の文字列をダメージ値に変換します。
53          */
54         private HashMap<String, Integer> compoundHash = new HashMap<String, Integer>();
55
56
57         /**
58          * List of item name of handler to compounds.
59          */
60         private ArrayList<String> compoundHandlerItemNames = new ArrayList<String>();
61
62
63         /**
64          * 分解台の素材のリスト
65          */
66         private ArrayList<ItemStack> decompositionMaterial = new ArrayList<ItemStack>();
67
68
69         /**
70          * 分解台の結果のリスト
71          */
72         private ArrayList<ItemStack[]> decompositionResults = new ArrayList<ItemStack[]>();
73
74
75         /**
76          * 化合台の原子の種類のリスト
77          */
78         private ArrayList<String[]> chemicalCombinationAtoms = new ArrayList<String[]>();
79
80
81         /**
82          * 化合台の原子の数のリスト
83          */
84         private ArrayList<Integer[]> chemicalCombinationAmounts = new ArrayList<Integer[]>();
85
86
87         /**
88          * 化合台の結果のリスト
89          */
90         private ArrayList<ItemStack> chemicalCombinationResult = new ArrayList<ItemStack>();
91
92
93         /**
94          * 素材製作台のレシピクラス
95          */
96         private ArrayList<MaterialRecipe> materialRecipe = new ArrayList<MaterialRecipe>();
97
98
99         /**
100          * ChemiCraftの化学作業台類のレシピのマネージャー
101          */
102         private ChemiCraftCraftingManager chemiCraftCraftingManager = new ChemiCraftCraftingManager();
103
104
105
106         /**
107          * add compound.
108          * @param name compound name.
109          */
110         public void addCompound(String name){
111                 addLangCompound("", name, "");
112         }
113
114
115
116         /**
117          * add compound corresponding to the language.
118          * @param lang Language to the corresponding
119          * @param englishName compound name
120          * @param langName compound name(specified language)
121          */
122         public void addLangCompound(String lang, String englishName, String langName){
123                 compoundsNameList.add(englishName);
124                 compoundsLangNameList.add(langName);
125                 compoundsLangList.add(lang);
126                 compoundHash.put(englishName, compoundHash.size());
127         }
128
129
130
131         public int getCompound(String key){
132                 if(compoundHash.get(key) != null){
133                         return compoundHash.get(key);
134                 } else {
135                         return -1;
136                 }
137         }
138
139
140
141         /**
142          * setting compound handler.
143          * @param handlerItemName
144          * @param compoundHandler
145          */
146         public void settingCompoundHandler(String handlerItemName, ICompoundHandler compoundHandler){
147                 compoundHandlers.add(compoundHandler);
148                 compoundHandlerItemNames.add(handlerItemName);
149         }
150
151
152
153         /**
154          * 分解レシピを追加します。resultの要素数は0<= n <= 16にしてください。
155          * @param material 素材
156          * @param result 結果
157          */
158         public void addDecompositionRecipe(ItemStack material, ItemStack[] result){
159                 if(result.length <= 16){
160                         decompositionMaterial.add(material);
161                         decompositionResults.add(result);
162                 }else{
163                         System.err.println("ChemiCraft内でエラー:addDecompositionRecipeの引数resultの要素数が16を超えています。" + "Material:" + material + "  Result:" + result);
164                 }
165         }
166
167
168
169         /**
170          * 化合レシピを追加します。materialの要素数は0<= n <= 16にしてください。
171          * @param material 素材
172          * @param result 結果
173          */
174         public void addChemicalCombinationRecipe(String[] atoms, Integer[] amounts, ItemStack result){
175                 chemicalCombinationAtoms.add(atoms);
176                 chemicalCombinationAmounts.add(amounts);
177                 chemicalCombinationResult.add(result);
178         }
179
180
181
182         public void addDecompositionRecipe(ItemStack material, int[] results, int[] stacks) {
183                 ItemStack[] itemstacks = new ItemStack[results.length];
184                 for (int i = 0; i < itemstacks.length; i++) {
185                         itemstacks[i] = new ItemStack(ChemiCraft.instance.atomsID,stacks[i], results[i]);
186                 }
187                 TileEntityPyrolysisTable.addRecipe(material, itemstacks);
188         }
189
190
191
192         public void addDecompositionRecipe(ItemStack itemstack, int burnTime) {
193                 TileEntityPyrolysisTable.addFuel(itemstack, burnTime);
194         }
195
196
197
198         public void addSharplessMaterialRecipe(ItemStack[] materials, ItemStack result, ChemicalNBTRecipe nbtRecipe){
199                 materialRecipe.add(new MaterialRecipe(result, materials, nbtRecipe, true));
200         }
201
202
203
204         public void addMaterialRecipe(ItemStack[] materials, ItemStack result, ChemicalNBTRecipe nbtRecipe){
205                 materialRecipe.add(new MaterialRecipe(result, materials, nbtRecipe, false));
206         }
207         //以下システム関連//////////////////////////////////////////////////////
208
209         public ArrayList<ICompoundHandler> getCompoundHandler(){
210                 compoundHandlers.trimToSize();
211                 return compoundHandlers;
212
213         }
214
215
216
217         public ArrayList<String> getCompoundHandlerItemName(){
218                 compoundHandlerItemNames.trimToSize();
219                 return compoundHandlerItemNames;
220         }
221
222
223
224         public ArrayList<String> getCompoundsName(){
225                 compoundsNameList.trimToSize();
226                 return compoundsNameList;
227         }
228
229
230
231         public ArrayList<String> getCompoundsLangName(){
232                 compoundsLangNameList.trimToSize();
233                 return compoundsLangNameList;
234         }
235
236
237
238         public ArrayList<String> getCompoundsLang(){
239                 compoundsLangList.trimToSize();
240                 return compoundsLangList;
241         }
242
243
244
245         public ArrayList<ItemStack> getDecompositionMaterial(){
246                 return decompositionMaterial;
247         }
248
249
250
251         public ArrayList<ItemStack[]> getDecompositionResult(){
252                 return decompositionResults;
253         }
254
255
256
257         public ArrayList<String[]> getChemicalCombinationAtoms(){
258                 return chemicalCombinationAtoms;
259         }
260
261
262
263         public ArrayList<Integer[]> getChemicalCombinationAmounts(){
264                 return chemicalCombinationAmounts;
265         }
266
267
268
269         public ArrayList<ItemStack> getChemicalCombinationResult(){
270                 return chemicalCombinationResult;
271         }
272
273
274
275         public ArrayList<MaterialRecipe> getMaterialRecipe(){
276                 return materialRecipe;
277         }
278
279
280
281         public ChemiCraftCraftingManager getCraftingManager(){
282                 return chemiCraftCraftingManager;
283         }
284
285
286
287         public static ChemiCraftAPI getInstance(){
288                 return instance;
289         }
290
291 }