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