diff --git a/src/api/java/appeng/api/networking/energy/IAEPowerStorage.java b/src/api/java/appeng/api/networking/energy/IAEPowerStorage.java index e571e3c4e..8917516bf 100644 --- a/src/api/java/appeng/api/networking/energy/IAEPowerStorage.java +++ b/src/api/java/appeng/api/networking/energy/IAEPowerStorage.java @@ -27,6 +27,7 @@ import javax.annotation.Nonnull; import appeng.api.config.AccessRestriction; import appeng.api.config.Actionable; +import appeng.api.networking.IGrid; /** * Used to access information about AE's various power accepting blocks for @@ -78,6 +79,10 @@ public interface IAEPowerStorage extends IEnergySource { * A higher value means it is more likely to be extracted from first, and less * likely to be inserted into first. * + * The value needs to be constant once added to a {@link IGrid}. Should it ever + * need to be changed, it has to be removed from the grid, then update the + * value, and finally added back to the grid. + * * This should never use {@link Integer#MIN_VALUE} or {@link Integer#MAX_VALUE}. * * @return the priority for this storage diff --git a/src/main/java/appeng/me/cache/EnergyGridCache.java b/src/main/java/appeng/me/cache/EnergyGridCache.java index abc983454..db92ac10a 100644 --- a/src/main/java/appeng/me/cache/EnergyGridCache.java +++ b/src/main/java/appeng/me/cache/EnergyGridCache.java @@ -74,10 +74,13 @@ public class EnergyGridCache implements IEnergyGrid { return Double.compare(percent1, percent2); }; - private static final Comparator COMPARATOR_HIGHEST_PRIORITY_FIRST = (o1, o2) -> Integer - .compare(o2.getPriority(), o1.getPriority()); - private static final Comparator COMPARATOR_LOWEST_PRIORITY_FIRST = (o1, o2) -> Integer - .compare(o1.getPriority(), o2.getPriority()); + private static final Comparator COMPARATOR_HIGHEST_PRIORITY_FIRST = (o1, o2) -> { + final int cmp = Integer.compare(o2.getPriority(), o1.getPriority()); + return cmp != 0 ? cmp : Integer.compare(System.identityHashCode(o2), System.identityHashCode(o1)); + }; + + private static final Comparator COMPARATOR_LOWEST_PRIORITY_FIRST = (o1, + o2) -> -COMPARATOR_HIGHEST_PRIORITY_FIRST.compare(o1, o2); private final NavigableSet interests = Sets.newTreeSet(); private final double averageLength = 40.0;