2014-11-20 12:57:08 +00:00
|
|
|
package WayofTime.alchemicalWizardry.api.compress;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2014-11-20 15:49:21 +00:00
|
|
|
import java.util.HashMap;
|
2014-11-20 12:57:08 +00:00
|
|
|
import java.util.List;
|
2014-11-20 15:49:21 +00:00
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map.Entry;
|
2014-11-20 12:57:08 +00:00
|
|
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
2014-11-20 15:19:45 +00:00
|
|
|
import net.minecraft.world.World;
|
2014-11-20 12:57:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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>();
|
2014-11-20 12:57:08 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2015-07-02 15:05:07 +00:00
|
|
|
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)
|
2014-11-20 12:57:08 +00:00
|
|
|
{
|
|
|
|
for(CompressionHandler handler : compressionRegistry)
|
|
|
|
{
|
2014-11-20 15:19:45 +00:00
|
|
|
ItemStack stack = handler.compressInventory(inv, world);
|
2014-11-20 12:57:08 +00:00
|
|
|
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()));
|
|
|
|
}
|
2014-11-20 12:57:08 +00:00
|
|
|
}
|