diff --git a/src/main/java/com/pahimar/ee3/recipe/CalcinationManager.java b/src/main/java/com/pahimar/ee3/recipe/CalcinationManager.java index 9d900242..29e51db4 100644 --- a/src/main/java/com/pahimar/ee3/recipe/CalcinationManager.java +++ b/src/main/java/com/pahimar/ee3/recipe/CalcinationManager.java @@ -2,14 +2,13 @@ package com.pahimar.ee3.recipe; import com.pahimar.ee3.emc.EmcRegistry; import com.pahimar.ee3.emc.EmcValue; -import com.pahimar.ee3.helper.LogHelper; import com.pahimar.ee3.item.ModItems; -import com.pahimar.ee3.lib.Compare; import net.minecraft.item.ItemStack; import java.util.ArrayList; import java.util.List; import java.util.Random; +import java.util.TreeMap; /** * Equivalent-Exchange-3 @@ -20,94 +19,47 @@ import java.util.Random; */ public class CalcinationManager { - // Helper stacks - private static ItemStack ASH_DUST_STACK = new ItemStack(ModItems.alchemicalDust.itemID, 1, 0); - private static ItemStack VERDANT_DUST_STACK = new ItemStack(ModItems.alchemicalDust.itemID, 1, 1); - private static ItemStack AZURE_DUST_STACK = new ItemStack(ModItems.alchemicalDust.itemID, 1, 2); - private static ItemStack MINIUM_DUST_STACK = new ItemStack(ModItems.alchemicalDust.itemID, 1, 3); - private static ItemStack AMARANTHINE_DUST_STACK = new ItemStack(ModItems.alchemicalDust.itemID, 1, 4); - private static ItemStack IRIDESCENT_DUST_STACK = new ItemStack(ModItems.alchemicalDust.itemID, 1, 5); - private static Random random = new Random(); - public static List getCalcinationResult(ItemStack itemStack) + public static List getCalcinationResult(ItemStack calcinedStack) { - ItemStack stack = itemStack.copy(); + ItemStack itemStack = calcinedStack.copy(); List calcinationResults = new ArrayList(); - EmcValue emcValue = EmcRegistry.getInstance().getEmcValue(itemStack); + TreeMap sortedItems = new TreeMap(); - EmcValue ashEmcValue = EmcRegistry.getInstance().getEmcValue(ASH_DUST_STACK); - EmcValue verdantEmcValue = EmcRegistry.getInstance().getEmcValue(VERDANT_DUST_STACK); - EmcValue azureEmcValue = EmcRegistry.getInstance().getEmcValue(AZURE_DUST_STACK); - EmcValue miniumEmcValue = EmcRegistry.getInstance().getEmcValue(MINIUM_DUST_STACK); - EmcValue amarathineEmcValue = EmcRegistry.getInstance().getEmcValue(AMARANTHINE_DUST_STACK); - EmcValue iridescentEmcValue = EmcRegistry.getInstance().getEmcValue(IRIDESCENT_DUST_STACK); - - if (emcValue != null) + for (ItemStack dustStack : ModItems.alchemicalDust.getSubTypes()) { - if (emcValue.compareTo(ashEmcValue) < Compare.EQUALS) + if (EmcRegistry.getInstance().hasEmcValue(dustStack)) { - LogHelper.debug("1"); + sortedItems.put(EmcRegistry.getInstance().getEmcValue(dustStack), dustStack); } - else if (emcValue.equals(ashEmcValue)) + } + + if (EmcRegistry.getInstance().hasEmcValue(itemStack)) + { + if (sortedItems.containsKey(EmcRegistry.getInstance().getEmcValue(itemStack))) { - LogHelper.debug("1"); - calcinationResults.add(ASH_DUST_STACK.copy()); + calcinationResults.add(sortedItems.get(EmcRegistry.getInstance().getEmcValue(itemStack))); } - else if (emcValue.compareTo(ashEmcValue) == Compare.GREATER_THAN && emcValue.compareTo(verdantEmcValue) == Compare.LESSER_THAN) + else { - LogHelper.debug("1,2"); - } - else if (emcValue.equals(verdantEmcValue)) - { - LogHelper.debug("2"); - calcinationResults.add(VERDANT_DUST_STACK.copy()); - } - else if (emcValue.compareTo(verdantEmcValue) == Compare.GREATER_THAN && emcValue.compareTo(azureEmcValue) == Compare.LESSER_THAN) - { - LogHelper.debug("2,3"); - } - else if (emcValue.equals(azureEmcValue)) - { - LogHelper.debug("3"); - calcinationResults.add(AZURE_DUST_STACK.copy()); - } - else if (emcValue.compareTo(azureEmcValue) == Compare.GREATER_THAN && emcValue.compareTo(miniumEmcValue) == Compare.LESSER_THAN) - { - LogHelper.debug("3,4"); - } - else if (emcValue.equals(miniumEmcValue)) - { - LogHelper.debug("4"); - calcinationResults.add(MINIUM_DUST_STACK.copy()); - } - else if (emcValue.compareTo(miniumEmcValue) == Compare.GREATER_THAN && emcValue.compareTo(amarathineEmcValue) == Compare.LESSER_THAN) - { - LogHelper.debug("4,5"); - } - else if (emcValue.equals(amarathineEmcValue)) - { - LogHelper.debug("5"); - calcinationResults.add(AMARANTHINE_DUST_STACK.copy()); - } - else if (emcValue.compareTo(amarathineEmcValue) == Compare.GREATER_THAN && emcValue.compareTo(iridescentEmcValue) == Compare.LESSER_THAN) - { - LogHelper.debug("5,6"); - } - else if (emcValue.equals(iridescentEmcValue)) - { - LogHelper.debug("6"); - calcinationResults.add(IRIDESCENT_DUST_STACK.copy()); - } - else if (emcValue.compareTo(iridescentEmcValue) == Compare.GREATER_THAN) - { - LogHelper.debug("6"); - calcinationResults.add(IRIDESCENT_DUST_STACK.copy()); + sortedItems.put(EmcRegistry.getInstance().getEmcValue(itemStack), itemStack); + + TreeMap lessThanMap = new TreeMap(sortedItems.headMap(EmcRegistry.getInstance().getEmcValue(itemStack))); + + if (lessThanMap.size() == 0) + { + calcinationResults.add(new ItemStack(ModItems.alchemicalDust, 1, 0)); + } + else + { + calcinationResults.add(lessThanMap.lastEntry().getValue()); + } } } else { - calcinationResults.add(ASH_DUST_STACK.copy()); + calcinationResults.add(new ItemStack(ModItems.alchemicalDust, 1, 0)); } return calcinationResults;