equivalent-exchange-3/src/main/java/com/pahimar/ee3/util/CalcinationHelper.java

60 lines
2.1 KiB
Java
Raw Normal View History

2014-07-03 21:44:44 +02:00
package com.pahimar.ee3.util;
import com.pahimar.ee3.api.EnergyValue;
import com.pahimar.ee3.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;
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>();
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)
if (ItemHelper.equals(itemStack, dustStack))
{
2014-07-03 21:44:44 +02:00
return null;
}
if (EnergyValueRegistry.getInstance().hasEnergyValue(dustStack))
{
2014-07-03 21:44:44 +02:00
sortedItems.put(EnergyValueRegistry.getInstance().getEnergyValue(dustStack), dustStack);
}
}
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));
}
else
{
2014-07-03 21:44:44 +02:00
sortedItems.put(EnergyValueRegistry.getInstance().getEnergyValue(itemStack), itemStack);
if (sortedItems.lowerEntry(EnergyValueRegistry.getInstance().getEnergyValue(itemStack)) == null)
{
2014-07-03 21:44:44 +02:00
return new ItemStack(ModItems.alchemicalDust, 1, 0);
}
else
{
2014-07-03 21:44:44 +02:00
return sortedItems.lowerEntry(EnergyValueRegistry.getInstance().getEnergyValue(itemStack)).getValue();
}
}
}
else
{
2014-07-03 21:44:44 +02:00
return new ItemStack(ModItems.alchemicalDust, 1, 0);
}
}
}