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