Improvements to the flud stack comparator, and fixed a missed case in the wrapped stack set comparator

This commit is contained in:
Pahimar 2016-05-19 21:49:21 -04:00
parent 429a0fc51b
commit a7e85aba7b
2 changed files with 47 additions and 62 deletions

View file

@ -34,10 +34,13 @@ public class Comparators {
}
}
else if (collection1 != null) {
return -1;
}
else if (collection2 != null) {
return 1;
}
else {
return -1;
return 0;
}
}
};

View file

@ -10,80 +10,64 @@ import net.minecraftforge.fluids.FluidStack;
import java.util.Comparator;
public class FluidHelper
{
public static Comparator<FluidStack> comparator = new Comparator<FluidStack>()
{
public class FluidHelper {
public int compare(FluidStack fluidStack1, FluidStack fluidStack2)
{
public static final Comparator<FluidStack> COMPARATOR = new Comparator<FluidStack>() {
if (fluidStack1 != null)
{
if (fluidStack2 != null)
{
// if (fluidStack1.fluidID == fluidStack2.fluidID)
if (FluidRegistry.getFluidID(fluidStack1.getFluid()) == FluidRegistry.getFluidID(fluidStack2.getFluid()))
{
if (fluidStack1.amount == fluidStack2.amount)
{
if (fluidStack1.tag != null)
{
if (fluidStack2.tag != null)
{
return (fluidStack1.tag.hashCode() - fluidStack2.tag.hashCode());
}
else
{
return -1;
}
@Override
public int compare(FluidStack fluidStack1, FluidStack fluidStack2) {
if (fluidStack1 != null && fluidStack2 != null) {
if (fluidStack1.getFluid() != null && fluidStack2.getFluid() != null) {
if (FluidRegistry.getFluidName(fluidStack1).equalsIgnoreCase(FluidRegistry.getFluidName(fluidStack2))) {
if (fluidStack1.amount == fluidStack2.amount) {
if (fluidStack1.tag != null && fluidStack2.tag != null) {
return fluidStack1.tag.hashCode() - fluidStack2.tag.hashCode();
}
else
{
if (fluidStack2.tag != null)
{
return 1;
}
else
{
return 0;
}
else if (fluidStack1.tag != null) {
return -1;
}
else if (fluidStack2.tag != null) {
return 1;
}
else {
return 0;
}
}
else
{
return (fluidStack1.amount - fluidStack2.amount);
else {
return fluidStack1.amount - fluidStack2.amount;
}
}
else
{
return (FluidRegistry.getFluidID(fluidStack1.getFluid()) - FluidRegistry.getFluidID(fluidStack2.getFluid()));
else {
return FluidRegistry.getFluidName(fluidStack1).compareToIgnoreCase(FluidRegistry.getFluidName(fluidStack2));
}
}
else
{
else if (fluidStack1.getFluid() != null) {
return -1;
}
}
else
{
if (fluidStack2 != null)
{
else if (fluidStack2.getFluid() != null) {
return 1;
}
else
{
else {
return 0;
}
}
else if (fluidStack1 != null) {
return -1;
}
else if (fluidStack2 != null) {
return 1;
}
else {
return 0;
}
}
};
public static void registerFluids()
{
public static void registerFluids() {
// Register Milk in the FluidRegistry if it hasn't already been done
if (!FluidRegistry.isFluidRegistered("milk"))
{
if (!FluidRegistry.isFluidRegistered("milk")) {
Fluid milk = new Fluid("milk").setUnlocalizedName(Names.Fluids.MILK);
if (FluidRegistry.registerFluid(milk))
{
@ -92,15 +76,13 @@ public class FluidHelper
}
}
public static int compare(FluidStack fluidStack1, FluidStack fluidStack2)
{
return comparator.compare(fluidStack1, fluidStack2);
public static int compare(FluidStack fluidStack1, FluidStack fluidStack2) {
return COMPARATOR.compare(fluidStack1, fluidStack2);
}
public static String toString(FluidStack fluidStack)
{
if (fluidStack != null)
{
public static String toString(FluidStack fluidStack) {
if (fluidStack != null) {
return String.format("%sxfluidStack.%s", fluidStack.amount, fluidStack.getFluid().getName());
}