2014-07-03 21:44:44 +02:00
|
|
|
package com.pahimar.ee3.util;
|
|
|
|
|
2014-07-07 17:22:21 +02:00
|
|
|
import com.pahimar.ee3.api.exchange.EnergyValue;
|
|
|
|
import com.pahimar.ee3.api.exchange.EnergyValueRegistry;
|
2014-07-03 21:44:44 +02:00
|
|
|
import com.pahimar.ee3.init.ModItems;
|
|
|
|
import com.pahimar.ee3.item.ItemAlchemicalDust;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
|
|
|
import java.util.TreeMap;
|
|
|
|
|
2014-07-04 21:18:10 +02:00
|
|
|
public class CalcinationHelper
|
|
|
|
{
|
|
|
|
public static ItemStack getCalcinationResult(ItemStack calcinedStack)
|
|
|
|
{
|
2014-07-03 21:44:44 +02:00
|
|
|
ItemStack itemStack = calcinedStack.copy();
|
|
|
|
itemStack.stackSize = 1;
|
|
|
|
|
|
|
|
TreeMap<EnergyValue, ItemStack> sortedItems = new TreeMap<EnergyValue, ItemStack>();
|
|
|
|
|
2014-07-04 21:18:10 +02:00
|
|
|
for (ItemStack dustStack : ItemAlchemicalDust.getAlchemicalDusts())
|
|
|
|
{
|
2014-07-03 21:44:44 +02:00
|
|
|
// If the item to be calcined is an alchemical dust, return null (you cannot calcine what's already been calcined)
|
2014-07-04 21:18:10 +02:00
|
|
|
if (ItemHelper.equals(itemStack, dustStack))
|
|
|
|
{
|
2014-07-03 21:44:44 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2014-07-04 21:18:10 +02:00
|
|
|
if (EnergyValueRegistry.getInstance().hasEnergyValue(dustStack))
|
|
|
|
{
|
2014-07-03 21:44:44 +02:00
|
|
|
sortedItems.put(EnergyValueRegistry.getInstance().getEnergyValue(dustStack), dustStack);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-04 21:18:10 +02:00
|
|
|
if (EnergyValueRegistry.getInstance().hasEnergyValue(itemStack))
|
|
|
|
{
|
|
|
|
if (sortedItems.containsKey(EnergyValueRegistry.getInstance().getEnergyValue(itemStack)))
|
|
|
|
{
|
2014-07-03 21:44:44 +02:00
|
|
|
return sortedItems.get(EnergyValueRegistry.getInstance().getEnergyValue(itemStack));
|
2014-07-04 21:18:10 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-07-03 21:44:44 +02:00
|
|
|
sortedItems.put(EnergyValueRegistry.getInstance().getEnergyValue(itemStack), itemStack);
|
|
|
|
|
2014-07-04 21:18:10 +02:00
|
|
|
if (sortedItems.lowerEntry(EnergyValueRegistry.getInstance().getEnergyValue(itemStack)) == null)
|
|
|
|
{
|
2014-07-03 21:44:44 +02:00
|
|
|
return new ItemStack(ModItems.alchemicalDust, 1, 0);
|
2014-07-04 21:18:10 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-07-03 21:44:44 +02:00
|
|
|
return sortedItems.lowerEntry(EnergyValueRegistry.getInstance().getEnergyValue(itemStack)).getValue();
|
|
|
|
}
|
|
|
|
}
|
2014-07-04 21:18:10 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-07-03 21:44:44 +02:00
|
|
|
return new ItemStack(ModItems.alchemicalDust, 1, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|