OSDN Git Service

96c4849296daf2b527e4036dd314e93a18c055f7
[chemicraft/chemicraft.git] / common / pcc / chemicraft / util / ComparatorItemStack.java
1 package pcc.chemicraft.util;
2
3 import java.util.Comparator;
4
5 import net.minecraft.item.ItemStack;
6
7
8 public class ComparatorItemStack implements Comparator {
9
10         @Override
11         public int compare(Object o1, Object o2) {
12                 ItemStack i1 = (ItemStack) o1;
13                 ItemStack i2 = (ItemStack) o2;
14
15                 if(i1 != null && i2 != null){
16                         if(i1.itemID == i2.itemID){
17                                 return i1.getItemDamage() > i2.getItemDamage() ? 1 : -1;
18                         }
19                         return i1.itemID > i2.itemID ? 1 : -1;
20                 }
21                 if(i1 == null && i2 == null) return 0;
22                 if(i1 != null && i2 == null) return -1;
23                 if(i1 == null && i2 != null) return 1;
24                 return 0;
25         }
26
27 }