OSDN Git Service

RaditionGunのSE追加。Credit表記も
[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 par2Atoms 元素
244          * @param par3Amounts 元素数
245          * @param par4Id ID
246          * @param par5Size 量
247          * @param par6Frequency 頻度
248          * @param par7PosY Y座標
249          */
250         public void addAtomOres(String par1Name, Integer[] par2Atoms, Integer[] par3Amounts, int par4Id, int par5Size, EnumOreSpawnFrequency par6Enum){
251                 addAtomOres(
252                                 par1Name,
253                                 par2Atoms,
254                                 par3Amounts,
255                                 par4Id,
256                                 par5Size,
257                                 par6Enum.getFrequency(),
258                                 par6Enum.getPosY());
259         }
260
261
262
263         /**
264          * 既に登録した鉱石の新しい名前・言語を追加します
265          * @param par1Name 英語名
266          * @param par2NewName 新しい名前
267          * @param par3Language 言語
268          */
269         public void addAtomOresLanguage(String par1Name, String par2NewName, String par3Language){
270                 atomOresNameListHash.add(par1Name,
271                                 par2NewName);
272                 atomOresLangListHash.add(par1Name,
273                                 par3Language);
274         }
275
276
277
278         /**
279          * 電池を追加します
280          * @param par1Name
281          */
282         public void addChemicalCell(Item par1ChemicalCell, String par2Name, int par3OperationTime){
283                 chemicalCellsList.put(
284                                 new ItemStack(
285                                                 par1ChemicalCell,
286                                                 0,
287                                                 chemicalCellsNameListHash.sizeKeysList()),
288                                                 par3OperationTime);
289                 addChemicalCellLanguage(
290                                 par2Name,
291                                 "en_US",
292                                 par2Name);
293         }
294
295
296         /**
297          * 既に登録した電池の新しい名前・言語を追加します
298          * @param par1Name 英語名
299          * @param par2NewName 新しい名前
300          * @param par3Language 言語
301          */
302         public void addChemicalCellLanguage(String par1Name, String par3NewLanguage, String par2NewName){
303                 chemicalCellsNameListHash.add(par1Name, par2NewName);
304                 chemicalCellsLangListHash.add(par1Name, par3NewLanguage);
305         }
306
307
308
309         /**
310          * 化合レシピを追加します。materialの要素数は0<= n <= 16にしてください。
311          * @param material 素材
312          * @param result 結果
313          */
314         public void addChemicalCombinationRecipe(String[] atoms, Integer[] amounts, ItemStack result){
315                 chemicalCombinationAtoms.add(atoms);
316                 chemicalCombinationAmounts.add(amounts);
317                 chemicalCombinationResult.add(result);
318         }
319
320
321
322         /**
323          * add compound.
324          * @param name compound name.
325          */
326         public void addCompound(String name){
327                 compoundsNameListHash.add(name, name);
328                 compoundsLangListHash.add(name, "en_US");
329                 compoundHash.put(name, compoundHash.size());
330         }
331
332
333
334         /**
335          * add compound corresponding to the language.
336          * @param lang Language to the corresponding
337          * @param englishName compound name
338          * @param langName compound name(specified language)
339          */
340         public void addCompound(String lang, String englishName, String langName){
341                 addCompound(englishName);
342                 addCompoundLanguage(lang, englishName, langName);
343         }
344
345
346
347         public void addCompoundLanguage(String lang, String englishName, String langName){
348                 compoundsNameListHash.add(
349                                 englishName,
350                                 langName);
351                 compoundsLangListHash.add(
352                                 englishName,
353                                 lang);
354         }
355
356
357
358         /**
359          * 分解台の燃料を追加します
360          * @param itemstack 燃料のItemStack
361          * @param burnTime 燃焼時間(tick * rate)
362          */
363         public void addPyrolysisDecompositionFuel(ItemStack itemstack, int burnTime) {
364                 TileEntityPyrolysisTable.addFuel(
365                                 itemstack,
366                                 burnTime);
367         }
368
369
370         /**
371          * 分解台のレシピを追加します
372          * @param material 素材
373          * @param integers 原子の元素番号の配列
374          * @param integers2 原子のできる数の配列
375          */
376         public void addPyrolysisDecompositionRecipe(ItemStack material, Integer[] integers, Integer[] integers2) {
377                 ItemStack[] itemstacks =
378                                 new ItemStack[integers.length];
379                 for (int i = 0; i < itemstacks.length; i++) {
380                         itemstacks[i] =
381                                         new ItemStack(
382                                                         ChemiCraft.instance.itemAtoms,
383                                                         integers2[i],
384                                                         integers[i]);
385                 }
386                 TileEntityPyrolysisTable.addRecipe(
387                                 material,
388                                 itemstacks);
389         }
390
391
392
393         public void addElectrolysisDecompositionRecipe(ItemStack material, Integer[] integers, Integer[] integers2) {
394                 ItemStack[] itemstacks =
395                                 new ItemStack[integers.length];
396                 for (int i = 0; i < itemstacks.length; i++) {
397                         itemstacks[i] =
398                                         new ItemStack(
399                                                         ChemiCraft.instance.itemAtoms,
400                                                         integers2[i],
401                                                         integers[i]);
402                 }
403                 TileEntityElectrolysisTable.addRecipe(
404                                 material,
405                                 itemstacks);
406         }
407
408
409
410         /**
411          * 素材作成台のレシピを追加します
412          * @param materials 素材
413          * @param result 結果
414          * @param nbtRecipe NBT(Nullの場合はなし)
415          */
416         public void addMaterialRecipe(ItemStack[] materials, ItemStack result, ChemicalNBTRecipe nbtRecipe){
417                 materialRecipe.add(
418                                 new MaterialRecipe(
419                                                 result,
420                                                 materials,
421                                                 nbtRecipe,
422                                                 false));
423         }
424
425
426
427         /**
428          * 素材作成台の不定形レシピを追加します
429          * @param materials 素材
430          * @param result 結果
431          * @param nbtRecipe NBT(Nullの場合はなし)
432          */
433         public void addSharplessMaterialRecipe(ItemStack[] materials, ItemStack result, ChemicalNBTRecipe nbtRecipe){
434                 materialRecipe.add(
435                                 new MaterialRecipe(
436                                                 result,
437                                                 materials,
438                                                 nbtRecipe,
439                                                 true));
440         }
441
442
443
444         /**
445          * ツール&武器作成台の不定形レシピを追加します
446          * @param materials 素材
447          * @param result 結果
448          */
449         public void addSharplessToolAndWeaponRecipe(ItemStack[] materials, ItemStack result) {
450                 toolAndWeaponMaterials.add(materials);
451                 toolAndWeaponResult.add(result);
452                 toolAndWeaponSharpless.add(true);
453         }
454
455
456         /**
457          * ツール&武器作成台のレシピを追加します
458          * @param materials 素材
459          * @param result 結果
460          */
461         public void addToolAndWeaponRecipe(ItemStack[] materials, ItemStack result) {
462                 toolAndWeaponMaterials.add(materials);
463                 toolAndWeaponResult.add(result);
464                 toolAndWeaponSharpless.add(false);
465         }
466
467
468         public ArrayList<WorldGenAtomsOre> getAtomOres(){
469                 return atomOresList;
470         }
471
472
473         //以下システム関連//////////////////////////////////////////////////////
474
475         public HashMap<String, Integer[]> getAtomOresAmounts(){
476                 return atomOresAmountsHash;
477         }
478
479
480
481         public HashMap<String, Integer[]> getAtomOresAtoms(){
482                 return atomOresAtomsHash;
483         }
484
485
486
487         public ListHash<String, String> getAtomOresLanguage(){
488                 return atomOresLangListHash;
489         }
490
491
492
493         public int getAtomOresLastIndex(){
494                 return atomOresNameListHash.sizeKeysList() / 16;
495         }
496
497
498
499         public int getAtomOresMetaOfLastIndex(){
500                 return atomOresNameListHash.sizeKeysList() - getAtomOresLastIndex() * 16;
501         }
502
503
504
505         public ListHash<String, String> getAtomOresName(){
506                 return atomOresNameListHash;
507         }
508
509
510
511         public HashMap<ItemStack, Integer> getChemicalCellsList(){
512                 return chemicalCellsList;
513         }
514
515
516
517         public ListHash<String, String> getChemicalCellsLanguage(){
518                 return chemicalCellsLangListHash;
519         }
520
521
522
523         public ListHash<String, String> getChemicalCellsName(){
524                 return chemicalCellsNameListHash;
525         }
526
527
528
529         public ArrayList<Integer[]> getChemicalCombinationAmounts(){
530                 return chemicalCombinationAmounts;
531         }
532
533
534
535         public ArrayList<String[]> getChemicalCombinationAtoms(){
536                 return chemicalCombinationAtoms;
537         }
538
539
540
541         public ArrayList<ItemStack> getChemicalCombinationResult(){
542                 return chemicalCombinationResult;
543         }
544
545
546
547         public int getCompound(String key){
548                 if(compoundHash.get(key) != null){
549                         return compoundHash.get(key);
550                 } else {
551                         return -1;
552                 }
553         }
554
555
556
557         public ArrayList<ICompoundHandler> getCompoundHandler(){
558                 compoundHandlers.trimToSize();
559                 return compoundHandlers;
560
561         }
562
563
564
565         public ArrayList<String> getCompoundHandlerItemName(){
566                 compoundHandlerItemNames.trimToSize();
567                 return compoundHandlerItemNames;
568         }
569
570
571
572         public ListHash<String, String> getCompoundsLang(){
573                 return compoundsLangListHash;
574         }
575
576
577
578         public ListHash<String, String> getCompoundsName(){
579                 return compoundsNameListHash;
580         }
581
582
583
584         public ChemiCraftCraftingManager getCraftingManager(){
585                 return chemiCraftCraftingManager;
586         }
587
588
589
590         public ArrayList<MaterialRecipe> getMaterialRecipe(){
591                 return materialRecipe;
592         }
593
594
595
596         public ArrayList<ItemStack[]> getToolAndWeaponMaterials() {
597                 return toolAndWeaponMaterials;
598         }
599
600
601
602         public ArrayList<ItemStack> getToolAndWeaponResult() {
603                 return toolAndWeaponResult;
604         }
605
606
607
608         public ArrayList<Boolean> getToolAndWeaponSharpless() {
609                 return toolAndWeaponSharpless;
610         }
611
612
613
614         /**
615          * setting compound handler.
616          * @param handlerItemName
617          * @param compoundHandler
618          */
619         public void settingCompoundHandler(String handlerItemName, ICompoundHandler compoundHandler){
620                 compoundHandlers.add(compoundHandler);
621                 compoundHandlerItemNames.add(handlerItemName);
622         }
623
624 }