generify some IStorage things to improve sorting
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package com.raoulvdberge.refinedstorage.api.storage;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IStorage<T> {
|
||||
/**
|
||||
* @return stacks stored in this storage
|
||||
*/
|
||||
List<T> getStacks();
|
||||
|
||||
/**
|
||||
* @return the amount of fluids stored in this storage
|
||||
*/
|
||||
int getStored();
|
||||
|
||||
/**
|
||||
* @return the priority of this storage
|
||||
*/
|
||||
int getPriority();
|
||||
|
||||
/**
|
||||
* @return the access type of this storage
|
||||
*/
|
||||
default AccessType getAccessType() {
|
||||
return AccessType.READ_WRITE;
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,17 @@
|
||||
package com.raoulvdberge.refinedstorage.api.storage.fluid;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorage;
|
||||
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents a fluid storage sink for the storage network.
|
||||
* Provide this through an {@link IFluidStorageProvider}.
|
||||
*/
|
||||
public interface IFluidStorage {
|
||||
/**
|
||||
* @return fluids stored in this storage
|
||||
*/
|
||||
List<FluidStack> getStacks();
|
||||
|
||||
public interface IFluidStorage extends IStorage<FluidStack> {
|
||||
/**
|
||||
* Inserts a fluid in this storage.
|
||||
*
|
||||
@@ -42,20 +36,5 @@ public interface IFluidStorage {
|
||||
@Nullable
|
||||
FluidStack extractFluid(@Nonnull FluidStack stack, int size, int flags);
|
||||
|
||||
/**
|
||||
* @return the amount of fluids stored in this storage
|
||||
*/
|
||||
int getStored();
|
||||
|
||||
/**
|
||||
* @return the priority of this storage
|
||||
*/
|
||||
int getPriority();
|
||||
|
||||
/**
|
||||
* @return the access type of this storage
|
||||
*/
|
||||
default AccessType getAccessType() {
|
||||
return AccessType.READ_WRITE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,23 +1,17 @@
|
||||
package com.raoulvdberge.refinedstorage.api.storage.item;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorage;
|
||||
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents an item storage sink for the storage network.
|
||||
* Provide this through an {@link IItemStorageProvider}.
|
||||
*/
|
||||
public interface IItemStorage {
|
||||
/**
|
||||
* @return items stored in this storage
|
||||
*/
|
||||
List<ItemStack> getItems();
|
||||
|
||||
public interface IItemStorage extends IStorage<ItemStack> {
|
||||
/**
|
||||
* Inserts an item to this storage.
|
||||
*
|
||||
@@ -41,21 +35,4 @@ public interface IItemStorage {
|
||||
*/
|
||||
@Nullable
|
||||
ItemStack extractItem(@Nonnull ItemStack stack, int size, int flags);
|
||||
|
||||
/**
|
||||
* @return The amount of items stored in this storage
|
||||
*/
|
||||
int getStored();
|
||||
|
||||
/**
|
||||
* @return The priority of this storage
|
||||
*/
|
||||
int getPriority();
|
||||
|
||||
/**
|
||||
* @return the access type of this storage
|
||||
*/
|
||||
default AccessType getAccessType() {
|
||||
return AccessType.READ_WRITE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public class ItemStorageCache implements IItemStorageCache {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (ItemStack stack : storage.getItems()) {
|
||||
for (ItemStack stack : storage.getStacks()) {
|
||||
add(stack, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ public abstract class ItemStorageNBT implements IItemStorage {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getItems() {
|
||||
public List<ItemStack> getStacks() {
|
||||
return stacks;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ import com.raoulvdberge.refinedstorage.api.network.IWirelessGridHandler;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IFluidGridHandler;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IItemGridHandler;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorage;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.fluid.IFluidStorage;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.fluid.IFluidStorageCache;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.item.IItemStorage;
|
||||
@@ -147,36 +148,9 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
|
||||
return (left.getEnergyUsage() > right.getEnergyUsage()) ? -1 : 1;
|
||||
};
|
||||
|
||||
private static final Comparator<IItemStorage> ITEM_SIZE_COMPARATOR = (left, right) -> {
|
||||
if (left.getStored() == right.getStored()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (left.getStored() > right.getStored()) ? -1 : 1;
|
||||
};
|
||||
|
||||
private static final Comparator<IItemStorage> ITEM_PRIORITY_COMPARATOR = (left, right) -> {
|
||||
if (left.getPriority() == right.getPriority()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (left.getPriority() > right.getPriority()) ? -1 : 1;
|
||||
};
|
||||
|
||||
private static final Comparator<IFluidStorage> FLUID_SIZE_COMPARATOR = (left, right) -> {
|
||||
if (left.getStored() == right.getStored()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (left.getStored() > right.getStored()) ? -1 : 1;
|
||||
};
|
||||
|
||||
private static final Comparator<IFluidStorage> FLUID_PRIORITY_COMPARATOR = (left, right) -> {
|
||||
if (left.getPriority() == right.getPriority()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (left.getPriority() > right.getPriority()) ? -1 : 1;
|
||||
private static final Comparator<IStorage> STORAGE_COMPARATOR = (left, right) -> {
|
||||
int compare = Integer.compare(left.getPriority(), right.getPriority());
|
||||
return compare != 0 ? compare : Integer.compare(left.getStored(), right.getStored());
|
||||
};
|
||||
|
||||
private IItemGridHandler itemGridHandler = new ItemGridHandler(this);
|
||||
@@ -267,11 +241,8 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
|
||||
}
|
||||
|
||||
if (canRun()) {
|
||||
Collections.sort(itemStorage.getStorages(), ITEM_SIZE_COMPARATOR);
|
||||
Collections.sort(itemStorage.getStorages(), ITEM_PRIORITY_COMPARATOR);
|
||||
|
||||
Collections.sort(fluidStorage.getStorages(), FLUID_SIZE_COMPARATOR);
|
||||
Collections.sort(fluidStorage.getStorages(), FLUID_PRIORITY_COMPARATOR);
|
||||
Collections.sort(itemStorage.getStorages(), STORAGE_COMPARATOR);
|
||||
Collections.sort(fluidStorage.getStorages(), STORAGE_COMPARATOR);
|
||||
|
||||
boolean craftingTasksChanged = !craftingTasksToAdd.isEmpty() || !craftingTasksToCancel.isEmpty();
|
||||
|
||||
|
||||
@@ -221,8 +221,8 @@ public class TileDiskManipulator extends TileNode implements IComparable, IFilte
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < storage.getItems().size(); i++) {
|
||||
ItemStack stack = storage.getItems().get(i);
|
||||
for (int i = 0; i < storage.getStacks().size(); i++) {
|
||||
ItemStack stack = storage.getStacks().get(i);
|
||||
if (stack == null) {
|
||||
continue;
|
||||
}
|
||||
@@ -241,7 +241,7 @@ public class TileDiskManipulator extends TileNode implements IComparable, IFilte
|
||||
storage.insertItem(((extracted == remainder) ? remainder.copy() : remainder), remainder.stackSize, false);
|
||||
}
|
||||
|
||||
if (storage.getItems().size() == 0) {
|
||||
if (storage.getStacks().size() == 0) {
|
||||
moveDriveToOutput(slot);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ public class ItemStorageDSU extends ItemStorageExternal {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getItems() {
|
||||
public List<ItemStack> getStacks() {
|
||||
if (unit.getStoredItemType() != null && unit.getStoredItemType().stackSize > 0) {
|
||||
return Collections.singletonList(unit.getStoredItemType().copy());
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ public class ItemStorageDrawer extends ItemStorageExternal {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getItems() {
|
||||
public List<ItemStack> getStacks() {
|
||||
if (!drawer.isEmpty() && drawer.getStoredItemCount() > 0) {
|
||||
return Collections.singletonList(drawer.getStoredItemCopy());
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ public abstract class ItemStorageExternal implements IItemStorage {
|
||||
public abstract int getCapacity();
|
||||
|
||||
public boolean updateCache() {
|
||||
List<ItemStack> items = getItems();
|
||||
List<ItemStack> items = getStacks();
|
||||
|
||||
if (cache == null) {
|
||||
cache = items;
|
||||
@@ -34,6 +34,6 @@ public abstract class ItemStorageExternal implements IItemStorage {
|
||||
}
|
||||
|
||||
public void updateCacheForcefully() {
|
||||
cache = getItems();
|
||||
cache = getStacks();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public class ItemStorageItemHandler extends ItemStorageExternal {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getItems() {
|
||||
public List<ItemStack> getStacks() {
|
||||
List<ItemStack> items = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < handler.getSlots(); ++i) {
|
||||
|
||||
Reference in New Issue
Block a user