1 package pcc.chemicraft.core;
3 import java.util.ArrayList;
4 import java.util.Arrays;
5 import java.util.HashMap;
6 import java.util.Iterator;
7 import java.util.TreeMap;
9 import net.minecraft.item.ItemStack;
10 import pcc.chemicraft.ChemiCraftData;
11 import pcc.chemicraft.EnumLoggingType;
12 import pcc.chemicraft.core.nbt.ChemicalNBTRecipe;
13 import pcc.chemicraft.core.system.ChemiCraftCraftingManager;
14 import pcc.chemicraft.util.Formula;
15 import pcc.chemicraft.util.ICompoundHandler;
16 import pcc.chemicraft.util.ListHash;
17 import pcc.chemicraft.util.MaterialRecipe;
21 * ChemiCraftのAPIを提供するクラスです<br>
22 * ChemiCraftのAPIを作成する場合はこのクラスを使用します<br>
26 public class ChemiCraftAPI {
31 private static ChemiCraftAPI instance = new ChemiCraftAPI();
38 public static ChemiCraftAPI instance(){
46 private static ArrayList<Integer[]> chemicalCombinationAmounts = new ArrayList<Integer[]>();
52 private static ArrayList<String[]> chemicalCombinationAtoms = new ArrayList<String[]>();
58 private static ArrayList<ItemStack> chemicalCombinationResult = new ArrayList<ItemStack>();
62 * ChemiCraftの化学作業台類のレシピのマネージャー
64 private static ChemiCraftCraftingManager chemiCraftCraftingManager = new ChemiCraftCraftingManager();
68 * List of item name of handler to compounds.
70 private static ArrayList<String> compoundHandlerItemNames = new ArrayList<String>();
76 private static TreeMap<String, Integer> compoundsDamageToString = new TreeMap<String, Integer>();
82 private static TreeMap<Integer, String> compoundsTexture = new TreeMap<Integer, String>();
86 * List of compounds handlers.
88 private static ArrayList<ICompoundHandler> compoundHandlers = new ArrayList<ICompoundHandler>();
92 * 化合物の文字列をダメージ値に変換します。
94 private static HashMap<String, Integer> compoundHash = new HashMap<String, Integer>();
98 * List of compounds names.
100 private static ListHash<String, String> compoundsNameListHash = new ListHash<String, String>();
106 private static HashMap<ItemStack, Integer> electrolysisFuelList = new HashMap<ItemStack, Integer>();
112 private static HashMap<ItemStack, ItemStack[]> electrolysisRecipeList = new HashMap<ItemStack, ItemStack[]>();
118 private static ArrayList<MaterialRecipe> materialRecipe = new ArrayList<MaterialRecipe>();
124 private static HashMap<ItemStack, Integer> pyrolysisFuelList = new HashMap<ItemStack, Integer>();
130 private static HashMap<ItemStack, ItemStack[]> pyrolysisRecipeList = new HashMap<ItemStack, ItemStack[]>();
136 private static ArrayList<ItemStack[]> toolAndWeaponMaterials = new ArrayList<ItemStack[]>();
142 private static ArrayList<ItemStack> toolAndWeaponResult = new ArrayList<ItemStack>();
148 private static ArrayList<Boolean> toolAndWeaponSharpless = new ArrayList<Boolean>();
153 * 化合レシピを追加します。materialの要素数は0<= n <= 16にしてください。
157 public static void addChemicalCombinationRecipe(ItemStack result, Formula formula){
158 ChemiCraftCore.logger.write("addChemicalCombinationRecipe:" + "Result-" + result.getItemName() + "/Material-" + Arrays.toString(formula.getAtoms())
159 , EnumLoggingType.INFO);
160 chemicalCombinationAtoms.add(formula.getAtoms());
161 chemicalCombinationAmounts.add(formula.getAmonts());
162 chemicalCombinationResult.add(result);
167 private static int compoundTexturePointer = 0;
172 public static void addCompound(String name){
173 ChemiCraftCore.logger.write("addCompound:" + name
174 , EnumLoggingType.INFO);
176 compoundsDamageToString.put(name, compoundTexturePointer);
177 compoundsTexture.put(compoundTexturePointer, "ChemiCraft:CompoundEmpty");
178 compoundTexturePointer++;
179 compoundsNameListHash.add("en_US", name);
180 compoundHash.put(name, compoundHash.size());
185 * 既に登録された化合物に対して別の言語をを追加します
187 * @param englishName 英語名
188 * @param langName 別言語への名前
190 public static void addCompound(String lang, String englishName, String langName){
191 ChemiCraftCore.logger.write("addCompound(MultiLang):" + "lang-" + lang + "/name-" + englishName + "/langToName-" + langName
192 , EnumLoggingType.INFO);
193 addCompound(englishName);
194 addCompoundLanguage(lang, langName);
200 * 単体で使用すると異常が発生するため、API以外での使用を固く非推奨する
202 * @param langName 言語への名前
205 private static void addCompoundLanguage(String lang, String langName){
206 compoundsNameListHash.add(
216 * @param formula 化学式(結果)
218 public static void addElectrolysisDecompositionRecipe(ItemStack material, Formula formula) {
219 ChemiCraftCore.logger.write("addElectrolysisRecipe:" + "Material-" + material.getItemName() + "/Result-" + Arrays.toString(formula.getAtoms()),
220 EnumLoggingType.INFO);
222 ItemStack[] itemstacks =
223 new ItemStack[formula.getAtoms().length];
224 for (int i = 0; i < itemstacks.length; i++) {
227 ChemiCraftCore.instance.itemAtoms,
228 formula.getAmonts()[i],
229 ChemiCraftData.toAtoms(formula.getAtoms()[i]));
231 electrolysisRecipeList.put(
240 * @param material 素材 (すべて結果は同じになります)
241 * @param formula 化学式(結果)
243 public static void addElectrolysisDecompositionRecipe(ArrayList<ItemStack> material, Formula formula) {
244 for (ItemStack item : material) {
246 addElectrolysisDecompositionRecipe(item, formula);
256 * @param formula 化学式(結果)
258 public static void addPyrolysisDecompositionRecipe(ItemStack material, Formula formula) {
259 ChemiCraftCore.logger.write("addPyrolysisRecipe:" + "Material-" + material.getItemName() + "/Result-" + Arrays.toString(formula.getAtoms()),
260 EnumLoggingType.INFO);
262 ItemStack[] itemstacks =
263 new ItemStack[formula.getAtoms().length];
264 for (int i = 0; i < itemstacks.length; i++) {
267 ChemiCraftCore.instance.itemAtoms,
268 formula.getAmonts()[i],
269 ChemiCraftData.toAtoms(formula.getAtoms()[i]));
271 pyrolysisRecipeList.put(
280 * @param material 素材 (すべて結果は同じになります)
281 * @param formula 化学式(結果)
283 public static void addPyrolysisDecompositionRecipe(ArrayList<ItemStack> material, Formula formula) {
284 for (ItemStack item : material) {
286 addPyrolysisDecompositionRecipe(item, formula);
295 * 化合,熱分解,電気分解ができるレシピを追加します
296 * @param materialAndResult 素材(分解)と結果(化合)
297 * @param formula 化学式(分解なら結果に。化合なら素材に)
299 public static void addReversible(ItemStack materialAndResult, Formula formula){
300 addChemicalCombinationRecipe(materialAndResult, formula);
301 addPyrolysisDecompositionRecipe(materialAndResult, formula);
302 addElectrolysisDecompositionRecipe(materialAndResult, formula);
308 * 化合,電気分解ができるレシピを追加します
309 * @param materialAndResult 素材(分解)と結果(化合)
310 * @param formula 化学式(分解なら結果に。化合なら素材に)
312 public static void addReversibleOfElectrolysis(ItemStack result, Formula formula){
313 addChemicalCombinationRecipe(result, formula);
314 addElectrolysisDecompositionRecipe(result, formula);
320 * 化合,熱分解ができるレシピを追加します
321 * @param materialAndResult 素材(分解)と結果(化合)
322 * @param formula 化学式(分解なら結果に。化合なら素材に)
324 public static void addReversibleOfPyrolysis(ItemStack result, Formula formula){
325 addChemicalCombinationRecipe(result, formula);
326 addPyrolysisDecompositionRecipe(result, formula);
333 * @param itemstack 燃料のItemStack
334 * @param burnTime 燃焼時間(tick * rate)
336 public static void addElectrolysisDecompositionFuel(ItemStack itemstack, int burnTime) {
337 ChemiCraftCore.logger.write("addElectrolysisFuel:" + "Fuel-" + itemstack.getItemName() + "/BurnTime-" + burnTime,
338 EnumLoggingType.INFO);
340 electrolysisFuelList.put(
349 * @param itemstack 燃料のItemStack
350 * @param burnTime 燃焼時間(tick * rate)
352 public static void addPyrolysisDecompositionFuel(ItemStack itemstack, int burnTime) {
353 ChemiCraftCore.logger.write("addPyrolysisFuel:" + "Fuel-" + itemstack.getItemName() + "/BurnTime-" + burnTime,
354 EnumLoggingType.INFO);
356 pyrolysisFuelList.put(
365 * @param materials 素材
367 * @param nbtRecipe NBT(Nullの場合はなし)
369 public static void addMaterialRecipe(ItemStack[] materials, ItemStack result, ChemicalNBTRecipe nbtRecipe){
370 ChemiCraftCore.logger.write("addMaterialRecipe:" + "Materials-" + Arrays.toString(materials) + "/Result-" + result.getItemName() + "/NBT-" + nbtRecipe,
371 EnumLoggingType.INFO);
385 * @param materials 素材
387 * @param nbtRecipe NBT(Nullの場合はなし)
389 public static void addSharplessMaterialRecipe(ItemStack[] materials, ItemStack result, ChemicalNBTRecipe nbtRecipe){
390 ChemiCraftCore.logger.write("addMaterialRecipe:" + "Materials-" + Arrays.toString(materials) + "/Result-" + result.getItemName() + "/NBT-" + nbtRecipe,
391 EnumLoggingType.INFO);
404 * 化合物のハンドラーを設定します。<br>
405 * CompoundHandlerを実装したクラスをcompoundHandlerに入れることによってhandlerItemNameで指定した<br>
406 * 化合物にハンドラーをつけることができます。
407 * @param handlerItemName ハンドラーをつける化合物の英語名
408 * @param compoundHandler ハンドラー
410 public static void settingCompoundHandler(String handlerItemName, ICompoundHandler compoundHandler){
411 ChemiCraftCore.logger.write("settingCompoundHandler:" + "Name-" + handlerItemName + "/CompoundHandler-" + compoundHandler,
412 EnumLoggingType.INFO);
414 if (compoundHandler.getIconIndexHandler() != null) {
415 int p = compoundsDamageToString.get(handlerItemName);
417 compoundsTexture.put(p, compoundHandler.getIconIndexHandler());
419 System.out.println("化合物が存在しません(settingCompoundHandler)");
423 compoundHandlers.add(compoundHandler);
424 compoundHandlerItemNames.add(handlerItemName);
430 * ツール&武器作成台のレシピを追加します<br>
432 * @param materials 素材
436 public static void addToolAndWeaponRecipe(ItemStack[] materials, ItemStack result) {
437 toolAndWeaponMaterials.add(materials);
438 toolAndWeaponResult.add(result);
439 toolAndWeaponSharpless.add(false);
445 * ツール&武器作成台の不定形レシピを追加します<br>
447 * @param materials 素材
451 public static void addSharplessToolAndWeaponRecipe(ItemStack[] materials, ItemStack result) {
452 toolAndWeaponMaterials.add(materials);
453 toolAndWeaponResult.add(result);
454 toolAndWeaponSharpless.add(true);
459 //以下システム関連//////////////////////////////////////////////////////
461 public static ArrayList<Integer[]> getChemicalCombinationAmounts() {
462 return chemicalCombinationAmounts;
467 public static ArrayList<String[]> getChemicalCombinationAtoms() {
468 return chemicalCombinationAtoms;
473 public static ArrayList<ItemStack> getChemicalCombinationResult() {
474 return chemicalCombinationResult;
479 public static int getCompound(String key) {
480 if (compoundHash.get(key) != null) {
481 return compoundHash.get(key);
489 public static ArrayList<ICompoundHandler> getCompoundHandler() {
490 compoundHandlers.trimToSize();
491 return compoundHandlers;
496 public static ArrayList<String> getCompoundHandlerItemName() {
497 compoundHandlerItemNames.trimToSize();
498 return compoundHandlerItemNames;
503 public static ListHash<String, String> getCompoundsName() {
504 return compoundsNameListHash;
509 public static ChemiCraftCraftingManager getCraftingManager() {
510 return chemiCraftCraftingManager;
515 public static HashMap<ItemStack, Integer> getElectrolysisFuelList() {
516 return electrolysisFuelList;
521 public static HashMap<ItemStack, ItemStack[]> getElectrolysisRecipeList() {
522 return electrolysisRecipeList;
527 public static ArrayList<MaterialRecipe> getMaterialRecipe() {
528 return materialRecipe;
533 public static HashMap<ItemStack, Integer> getPyrolysisFuelList() {
534 return pyrolysisFuelList;
539 public static HashMap<ItemStack, ItemStack[]> getPyrolysisRecipeList() {
540 return pyrolysisRecipeList;
545 public static ArrayList<ItemStack[]> getToolAndWeaponMaterials() {
546 return toolAndWeaponMaterials;
551 public static ArrayList<ItemStack> getToolAndWeaponResult() {
552 return toolAndWeaponResult;
557 public static ArrayList<Boolean> getToolAndWeaponSharpless() {
558 return toolAndWeaponSharpless;
563 public static ArrayList<String> getCompoundsTexture() {
564 Iterator<String> it = compoundsTexture.values().iterator();
565 ArrayList<String> li = new ArrayList<String>();
566 while (it.hasNext()) {