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