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