OSDN Git Service

修正・更新
[chemicraft/chemicraft.git] / common / pcc / chemicraft / ChemiCraftAPI.java
1 package pcc.chemicraft;
2
3 import java.util.ArrayList;
4 import java.util.HashMap;
5
6 import net.minecraft.item.ItemStack;
7 import pcc.chemicraft.gen.WorldGenAtomsOre;
8 import pcc.chemicraft.system.ChemiCraftCraftingManager;
9 import pcc.chemicraft.tileentity.TileEntityPyrolysisTable;
10 import pcc.chemicraft.util.ChemicalNBTRecipe;
11 import pcc.chemicraft.util.ICompoundHandler;
12 import pcc.chemicraft.util.ListHash;
13 import pcc.chemicraft.util.MaterialRecipe;
14
15
16 /**
17  * ChemiCraftのAPI
18  * 基本的にAddonはこのクラスのインスタンスを使う
19  * @author mozipi
20  *
21  */
22 public class ChemiCraftAPI {
23
24         /**
25          * Instance of the ChemiCraftAPI.
26          */
27         private static ChemiCraftAPI instance = new ChemiCraftAPI();
28
29
30         /**
31          * List of compounds names.
32          */
33         private ListHash<String, String> compoundsNameListHash = new ListHash<String, String>();
34
35
36         /**
37          * List of compounds the language names.
38          */
39         private ListHash<String, String> compoundsLangListHash = new ListHash<String, String>();
40
41
42         /**
43          * List of compounds handlers.
44          */
45         private ArrayList<ICompoundHandler> compoundHandlers = new ArrayList<ICompoundHandler>();
46
47
48         /**
49          * 化合物の文字列をダメージ値に変換します。
50          */
51         private HashMap<String, Integer> compoundHash = new HashMap<String, Integer>();
52
53
54         /**
55          * List of item name of handler to compounds.
56          */
57         private ArrayList<String> compoundHandlerItemNames = new ArrayList<String>();
58
59
60         /**
61          * 化合台の原子の種類のリスト
62          */
63         private ArrayList<String[]> chemicalCombinationAtoms = new ArrayList<String[]>();
64
65
66         /**
67          * 化合台の原子の数のリスト
68          */
69         private ArrayList<Integer[]> chemicalCombinationAmounts = new ArrayList<Integer[]>();
70
71
72         /**
73          * 化合台の結果のリスト
74          */
75         private ArrayList<ItemStack> chemicalCombinationResult = new ArrayList<ItemStack>();
76
77
78         /**
79          * 素材製作台のレシピクラス
80          */
81         private ArrayList<MaterialRecipe> materialRecipe = new ArrayList<MaterialRecipe>();
82
83
84         /**
85          * ChemiCraftの化学作業台類のレシピのマネージャー
86          */
87         private ChemiCraftCraftingManager chemiCraftCraftingManager = new ChemiCraftCraftingManager();
88
89
90
91         /**
92          * 鉱石名リスト
93          */
94         private ListHash<String, String> atomsOreNameListHash = new ListHash<String, String>();
95
96
97         /**
98          * 鉱石の言語リスト
99          */
100         private ListHash<String, String> atomsOreLangListHash = new ListHash<String, String>();
101
102
103         /**
104          * 鉱石リスト
105          */
106         private ArrayList<WorldGenAtomsOre> atomsOres = new ArrayList<WorldGenAtomsOre>();
107
108
109
110         /**
111          * ツール&武器作成台の素材一覧のリスト
112          */
113         private ArrayList<ItemStack[]> toolAndWeaponMaterials = new ArrayList<ItemStack[]>();
114
115
116         /**
117          * ツール&武器作成台の結果のリスト
118          */
119         private ArrayList<ItemStack> toolAndWeaponResult = new ArrayList<ItemStack>();
120
121
122         /**
123          * ツール&武器作成台の不定形であるか
124          */
125         private ArrayList<Boolean> toolAndWeaponSharpless = new ArrayList<Boolean>();
126
127
128
129         /**
130          * add compound.
131          * @param name compound name.
132          */
133         public void addCompound(String name){
134                 compoundsNameListHash.add(name, name);
135                 compoundsLangListHash.add(name, "en_US");
136                 compoundHash.put(name, compoundHash.size());
137         }
138
139
140
141         /**
142          * add compound corresponding to the language.
143          * @param lang Language to the corresponding
144          * @param englishName compound name
145          * @param langName compound name(specified language)
146          */
147         public void addCompound(String lang, String englishName, String langName){
148                 addCompound(englishName);
149                 addCompoundLanguage(lang, englishName, langName);
150         }
151
152
153
154         public void addCompoundLanguage(String lang, String englishName, String langName){
155                 compoundsNameListHash.add(englishName, langName);
156                 compoundsLangListHash.add(englishName, lang);
157         }
158
159
160
161         public int getCompound(String key){
162                 if(compoundHash.get(key) != null){
163                         return compoundHash.get(key);
164                 } else {
165                         return -1;
166                 }
167         }
168
169
170
171         /**
172          * setting compound handler.
173          * @param handlerItemName
174          * @param compoundHandler
175          */
176         public void settingCompoundHandler(String handlerItemName, ICompoundHandler compoundHandler){
177                 compoundHandlers.add(compoundHandler);
178                 compoundHandlerItemNames.add(handlerItemName);
179         }
180
181
182
183         /**
184          * 化合レシピを追加します。materialの要素数は0<= n <= 16にしてください。
185          * @param material 素材
186          * @param result 結果
187          */
188         public void addChemicalCombinationRecipe(String[] atoms, Integer[] amounts, ItemStack result){
189                 chemicalCombinationAtoms.add(atoms);
190                 chemicalCombinationAmounts.add(amounts);
191                 chemicalCombinationResult.add(result);
192         }
193
194
195
196         /**
197          * 分解台のレシピを追加します
198          * @param material 素材
199          * @param results 原子の元素番号の配列
200          * @param stacks 原子のできる数の配列
201          */
202         public void addDecompositionRecipe(ItemStack material, int[] results, int[] stacks) {
203                 ItemStack[] itemstacks = new ItemStack[results.length];
204                 for (int i = 0; i < itemstacks.length; i++) {
205                         itemstacks[i] = new ItemStack(ChemiCraft.instance.itemAtoms,stacks[i], results[i]);
206                 }
207                 TileEntityPyrolysisTable.addRecipe(material, itemstacks);
208         }
209
210
211
212         /**
213          * 分解台の燃料を追加します
214          * @param itemstack 燃料のItemStack
215          * @param burnTime 燃焼時間(tick * rate)
216          */
217         public void addDecompositionFuel(ItemStack itemstack, int burnTime) {
218                 TileEntityPyrolysisTable.addFuel(itemstack, burnTime);
219         }
220
221
222
223         /**
224          * ツール&武器作成台のレシピを追加します
225          * @param materials 素材
226          * @param result 結果
227          */
228         public void addToolAndWeaponRecipe(ItemStack[] materials, ItemStack result) {
229                 toolAndWeaponMaterials.add(materials);
230                 toolAndWeaponResult.add(result);
231                 toolAndWeaponSharpless.add(false);
232         }
233
234
235         /**
236          * ツール&武器作成台の不定形レシピを追加します
237          * @param materials 素材
238          * @param result 結果
239          */
240         public void addSharplessToolAndWeaponRecipe(ItemStack[] materials, ItemStack result) {
241                 toolAndWeaponMaterials.add(materials);
242                 toolAndWeaponResult.add(result);
243                 toolAndWeaponSharpless.add(true);
244         }
245
246
247
248         /**
249          * 素材作成台の不定形レシピを追加します
250          * @param materials 素材
251          * @param result 結果
252          * @param nbtRecipe NBT(Nullの場合はなし)
253          */
254         public void addSharplessMaterialRecipe(ItemStack[] materials, ItemStack result, ChemicalNBTRecipe nbtRecipe){
255                 materialRecipe.add(new MaterialRecipe(result, materials, nbtRecipe, true));
256         }
257
258
259
260         /**
261          * 素材作成台のレシピを追加します
262          * @param materials 素材
263          * @param result 結果
264          * @param nbtRecipe NBT(Nullの場合はなし)
265          */
266         public void addMaterialRecipe(ItemStack[] materials, ItemStack result, ChemicalNBTRecipe nbtRecipe){
267                 materialRecipe.add(new MaterialRecipe(result, materials, nbtRecipe, false));
268         }
269
270
271
272         /**
273          * 鉱石を追加します
274          * @param name 鉱石名
275          * @param size 一度に生成される量
276          * @param frequency 生成頻度
277          * @param posY Y座標
278          */
279         public void addAtomsOre(String par1Name, int par2Id, int par3Size, int par4Frequency, int par5PosY){
280                 atomsOres.add(new WorldGenAtomsOre(par2Id, getAtomsOreMetaOfIndex(), par3Size, par4Frequency, par5PosY));
281                 addAtomsOreLanguage(par1Name, par1Name, "en_US");
282         }
283
284
285         /**
286          * 既に登録した鉱石の新しい名前・言語を追加します
287          * @param par1Name 英語名
288          * @param par2NewName 新しい名前
289          * @param par3Language 言語
290          */
291         public void addAtomsOreLanguage(String par1Name, String par2NewName, String par3Language){
292                 atomsOreNameListHash.add(par1Name, par2NewName);
293                 atomsOreLangListHash.add(par1Name, par3Language);
294         }
295
296         
297         //以下システム関連//////////////////////////////////////////////////////
298
299         public ArrayList<ICompoundHandler> getCompoundHandler(){
300                 compoundHandlers.trimToSize();
301                 return compoundHandlers;
302
303         }
304
305
306
307         public ArrayList<String> getCompoundHandlerItemName(){
308                 compoundHandlerItemNames.trimToSize();
309                 return compoundHandlerItemNames;
310         }
311
312
313
314         public ListHash<String, String> getCompoundsName(){
315                 return compoundsNameListHash;
316         }
317
318
319
320         public ListHash<String, String> getCompoundsLang(){
321                 return compoundsLangListHash;
322         }
323
324
325
326         public ArrayList<String[]> getChemicalCombinationAtoms(){
327                 return chemicalCombinationAtoms;
328         }
329
330
331
332         public ArrayList<Integer[]> getChemicalCombinationAmounts(){
333                 return chemicalCombinationAmounts;
334         }
335
336
337
338         public ArrayList<ItemStack> getChemicalCombinationResult(){
339                 return chemicalCombinationResult;
340         }
341
342
343
344         public ArrayList<MaterialRecipe> getMaterialRecipe(){
345                 return materialRecipe;
346         }
347
348
349
350         public ArrayList<ItemStack[]> getToolAndWeaponMaterials() {
351                 return toolAndWeaponMaterials;
352         }
353
354
355
356         public ArrayList<ItemStack> getToolAndWeaponResult() {
357                 return toolAndWeaponResult;
358         }
359
360
361
362         public ArrayList<Boolean> getToolAndWeaponSharpless() {
363                 return toolAndWeaponSharpless;
364         }
365
366
367
368         public ChemiCraftCraftingManager getCraftingManager(){
369                 return chemiCraftCraftingManager;
370         }
371
372
373
374         public ListHash<String, String> getAtomsOreNameListHash(){
375                 return atomsOreNameListHash;
376         }
377
378
379
380         public ListHash<String, String> getAtomsOreLangListHash(){
381                 return atomsOreLangListHash;
382         }
383
384
385
386         public int getAtomsOreIndex(){
387                 return atomsOreNameListHash.sizeKeysList() / 16;
388         }
389
390
391
392         public int getAtomsOreMetaOfIndex(){
393                 return atomsOreNameListHash.sizeKeysList() - getAtomsOreIndex() * 16;
394         }
395
396
397
398         public ArrayList<WorldGenAtomsOre> getAtomsOres(){
399                 return atomsOres;
400         }
401
402
403
404         public static ChemiCraftAPI instance(){
405                 return instance;
406         }
407
408 }