BloodMagic/src/main/java/WayofTime/alchemicalWizardry/api/compress/CompressionRegistry.java

68 lines
1.7 KiB
Java
Raw Normal View History

package WayofTime.alchemicalWizardry.api.compress;
import java.util.ArrayList;
2014-11-20 15:49:21 +00:00
import java.util.HashMap;
import java.util.List;
2014-11-20 15:49:21 +00:00
import java.util.Map;
import java.util.Map.Entry;
import net.minecraft.item.ItemStack;
2014-11-20 15:19:45 +00:00
import net.minecraft.world.World;
/**
* A registry aimed to help compress items in an inventory into its compressible form.
*
*/
public class CompressionRegistry
{
2015-07-30 18:52:39 +00:00
public static List<CompressionHandler> compressionRegistry = new ArrayList<CompressionHandler>();
public static Map<ItemStack, Integer> thresholdMap = new HashMap<ItemStack, Integer>();
public static void registerHandler(CompressionHandler handler)
{
compressionRegistry.add(handler);
}
2014-11-20 15:49:21 +00:00
/**
* Registers an item so that it only compresses while above this threshold
* @param stack
* @param threshold
*/
public static void registerItemThreshold(ItemStack stack, int threshold)
{
thresholdMap.put(stack, threshold);
2014-11-20 15:49:21 +00:00
}
2014-11-20 15:19:45 +00:00
public static ItemStack compressInventory(ItemStack[] inv, World world)
{
for(CompressionHandler handler : compressionRegistry)
{
2014-11-20 15:19:45 +00:00
ItemStack stack = handler.compressInventory(inv, world);
if(stack != null)
{
return stack;
}
}
return null;
}
2014-11-20 15:49:21 +00:00
public static int getItemThreshold(ItemStack stack)
{
for(Entry<ItemStack, Integer> entry : thresholdMap.entrySet())
{
2014-12-10 01:34:48 +00:00
if(areItemStacksEqual(entry.getKey(), stack))
2014-11-20 15:49:21 +00:00
{
return entry.getValue();
}
}
return 0;
}
2014-12-10 01:34:48 +00:00
public static boolean areItemStacksEqual(ItemStack stack, ItemStack compressedStack)
{
return stack.isItemEqual(compressedStack) && (stack.getTagCompound() == null ? compressedStack.getTagCompound() == null : stack.getTagCompound().equals(compressedStack.getTagCompound()));
}
}