Work on adding Comparables and Comparator stuff for the custom wrapped
stacks
This commit is contained in:
parent
2be7c58743
commit
bd86e16844
|
@ -1,6 +1,6 @@
|
|||
package com.pahimar.ee3.core.util;
|
||||
|
||||
public class EnergyStack {
|
||||
public class EnergyStack implements Comparable<EnergyStack> {
|
||||
|
||||
public static final String VANILLA_SMELTING_ENERGY_NAME = "vanillaFuelValueUnits";
|
||||
public static final int VANILLA_SMELTING_ENERGY_THRESHOLD = 200;
|
||||
|
@ -46,4 +46,15 @@ public class EnergyStack {
|
|||
return (this.stackSize == energyStack.stackSize && this.energyName.equalsIgnoreCase(energyStack.energyName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(EnergyStack energyStack) {
|
||||
|
||||
if (this.energyName.equalsIgnoreCase(energyStack.energyName)) {
|
||||
return (this.stackSize - energyStack.stackSize);
|
||||
}
|
||||
else {
|
||||
return this.energyName.toLowerCase().compareTo(energyStack.energyName.toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.pahimar.ee3.core.util;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
@ -111,6 +113,7 @@ public class ItemUtil {
|
|||
* The second ItemStack being tested for equality
|
||||
* @return true if the two ItemStacks are equivalent, false otherwise
|
||||
*/
|
||||
// FIXME Update to correspond with the new Comparator stuff for ItemStacks, and make NBT sensitive
|
||||
public static boolean compare(ItemStack first, ItemStack second) {
|
||||
|
||||
// Check to see if either argument is null
|
||||
|
@ -200,5 +203,52 @@ public class ItemUtil {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// FIXME Make NBT sensitive
|
||||
public static Comparator<ItemStack> ItemStackComparator = new Comparator<ItemStack>() {
|
||||
|
||||
public int compare(ItemStack itemStack1, ItemStack itemStack2) {
|
||||
|
||||
if (itemStack1.itemID == itemStack2.itemID) {
|
||||
|
||||
if (itemStack1.getItemDamage() == itemStack2.getItemDamage()) {
|
||||
|
||||
if ((itemStack1.getUnlocalizedName() != null) && (itemStack2.getUnlocalizedName() != null)) {
|
||||
|
||||
if (!(itemStack1.hasTagCompound()) && !(itemStack2.hasTagCompound())) {
|
||||
return itemStack1.getUnlocalizedName().toLowerCase().compareTo(itemStack2.getUnlocalizedName().toLowerCase());
|
||||
}
|
||||
else if (itemStack1.hasTagCompound() && itemStack2.hasTagCompound()) {
|
||||
// TODO We may have to go deeper with comparing NBTTagCompounds
|
||||
return 0;
|
||||
}
|
||||
else if (itemStack1.hasTagCompound() && !(itemStack2.hasTagCompound())) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if ((itemStack1.getUnlocalizedName() == null) && (itemStack2.getUnlocalizedName() == null)) {
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
if (itemStack1.getUnlocalizedName() == null) {
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
return (itemStack1.getItemDamage() - itemStack2.getItemDamage());
|
||||
}
|
||||
}
|
||||
else {
|
||||
return (itemStack1.itemID - itemStack2.itemID);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
package com.pahimar.ee3.core.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
public class OreStack implements Comparator<OreStack> {
|
||||
public class OreStack implements Comparable<OreStack> {
|
||||
|
||||
public String oreName;
|
||||
public int stackSize;
|
||||
|
@ -71,27 +70,27 @@ public class OreStack implements Comparator<OreStack> {
|
|||
|
||||
OreStack oreStackObject = (OreStack) object;
|
||||
|
||||
return stackSize == oreStackObject.stackSize && oreName.equals(oreStackObject.oreName);
|
||||
return stackSize == oreStackObject.stackSize && oreName.equalsIgnoreCase(oreStackObject.oreName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(OreStack oreStack1, OreStack oreStack2) {
|
||||
public static boolean compareOreNames(OreStack oreStack1, OreStack oreStack2) {
|
||||
|
||||
if (oreStack1 != null && oreStack2 != null) {
|
||||
if (oreStack1.oreName.equals(oreStack2.oreName))
|
||||
return 0;
|
||||
if (oreStack1 != null && oreStack2 != null) {
|
||||
if (oreStack1.oreName.equalsIgnoreCase(oreStack2.oreName))
|
||||
return true;
|
||||
}
|
||||
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean compareStacks(OreStack oreStack1, OreStack oreStack2) {
|
||||
|
||||
return oreStack1.compareToStack(oreStack2);
|
||||
}
|
||||
|
||||
public boolean compareToStack(OreStack oreStack) {
|
||||
|
||||
return compare(this, oreStack) == 0;
|
||||
}
|
||||
@Override
|
||||
public int compareTo(OreStack oreStack) {
|
||||
|
||||
if (this.oreName.equalsIgnoreCase(oreStack.oreName)) {
|
||||
return (this.stackSize - oreStack.stackSize);
|
||||
}
|
||||
else {
|
||||
return this.oreName.toLowerCase().compareTo(oreStack.oreName.toLowerCase());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.pahimar.ee3.emc;
|
||||
|
||||
public class EmcComponent {
|
||||
public class EmcComponent implements Comparable<EmcComponent> {
|
||||
|
||||
private final EmcType emcType;
|
||||
private final float percentage;
|
||||
|
@ -43,4 +43,10 @@ public class EmcComponent {
|
|||
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(EmcComponent o) {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ import com.pahimar.ee3.lib.Strings;
|
|||
* @license Lesser GNU Public License v3 (http://www.gnu.org/licenses/lgpl.html)
|
||||
*
|
||||
*/
|
||||
public class EmcValue {
|
||||
public class EmcValue implements Comparable<EmcValue> {
|
||||
|
||||
private float value, recoveryPercentage;
|
||||
private List<EmcComponent> emcComponents;
|
||||
|
@ -158,4 +158,10 @@ public class EmcValue {
|
|||
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(EmcValue o) {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ import com.pahimar.ee3.core.util.ItemUtil;
|
|||
import com.pahimar.ee3.core.util.OreStack;
|
||||
import com.pahimar.ee3.lib.Reference;
|
||||
|
||||
public class CustomWrappedStack {
|
||||
public class CustomWrappedStack implements Comparable<CustomWrappedStack> {
|
||||
|
||||
private int stackSize;
|
||||
private ItemStack itemStack;
|
||||
|
@ -293,4 +293,85 @@ public class CustomWrappedStack {
|
|||
|
||||
return (object instanceof CustomWrappedStack || object instanceof ItemStack || object instanceof OreStack || object instanceof EnergyStack || object instanceof Item || object instanceof Block);
|
||||
}
|
||||
|
||||
@Override
|
||||
/*
|
||||
* Sort order (class-wise) goes null, EnergyStack, OreStack, ItemStack
|
||||
* @see java.lang.Comparable#compareTo(java.lang.Object)
|
||||
*/
|
||||
public int compareTo(CustomWrappedStack customWrappedStack) {
|
||||
|
||||
if (this.getWrappedStack() instanceof EnergyStack) {
|
||||
|
||||
if (customWrappedStack.getWrappedStack() instanceof EnergyStack) {
|
||||
|
||||
if (this.energyStack.equals(customWrappedStack.energyStack)) {
|
||||
return (this.stackSize - customWrappedStack.stackSize);
|
||||
}
|
||||
else {
|
||||
return this.energyStack.compareTo(customWrappedStack.energyStack);
|
||||
}
|
||||
}
|
||||
else if (customWrappedStack.getWrappedStack() instanceof OreStack) {
|
||||
return -1;
|
||||
}
|
||||
else if (customWrappedStack.getWrappedStack() instanceof ItemStack) {
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else if (this.getWrappedStack() instanceof OreStack) {
|
||||
|
||||
if (customWrappedStack.getWrappedStack() instanceof EnergyStack) {
|
||||
return 1;
|
||||
}
|
||||
else if (customWrappedStack.getWrappedStack() instanceof OreStack) {
|
||||
|
||||
if (this.oreStack.equals(customWrappedStack.oreStack)) {
|
||||
return (this.stackSize - customWrappedStack.stackSize);
|
||||
}
|
||||
else {
|
||||
return this.oreStack.compareTo(customWrappedStack.oreStack);
|
||||
}
|
||||
}
|
||||
else if (customWrappedStack.getWrappedStack() instanceof ItemStack) {
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else if (this.getWrappedStack() instanceof ItemStack) {
|
||||
|
||||
if (customWrappedStack.getWrappedStack() instanceof EnergyStack) {
|
||||
return 1;
|
||||
}
|
||||
else if (customWrappedStack.getWrappedStack() instanceof OreStack) {
|
||||
|
||||
return 1;
|
||||
}
|
||||
else if (customWrappedStack.getWrappedStack() instanceof ItemStack) {
|
||||
|
||||
if (ItemUtil.compare(this.itemStack, customWrappedStack.itemStack)) {
|
||||
return (this.stackSize - customWrappedStack.stackSize);
|
||||
}
|
||||
else {
|
||||
return ItemUtil.ItemStackComparator.compare(this.itemStack, customWrappedStack.itemStack);
|
||||
}
|
||||
}
|
||||
else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (customWrappedStack.getWrappedStack() != null) {
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -232,7 +232,7 @@ public class RecipeRegistry {
|
|||
}
|
||||
}
|
||||
else if (wrappedInputStack.getWrappedStack() instanceof OreStack && collatedStacks.get(i).getWrappedStack() instanceof OreStack) {
|
||||
if (OreStack.compareStacks((OreStack) wrappedInputStack.getWrappedStack(), (OreStack) collatedStacks.get(i).getWrappedStack())) {
|
||||
if (OreStack.compareOreNames((OreStack) wrappedInputStack.getWrappedStack(), (OreStack) collatedStacks.get(i).getWrappedStack())) {
|
||||
collatedStacks.get(i).setStackSize(collatedStacks.get(i).getStackSize() + wrappedInputStack.getStackSize());
|
||||
found = true;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue