Implemented getStorage command for OC integration (#1828)
* Added first iteration of getStorage command for OC integration * Attempted to add an option to fetch the UUID of a Storage Disk. Ended up having to return a randomly generated UUID for now. * Add logic for traversing the fluid storage cache * Removed unused import
This commit is contained in:
@@ -19,6 +19,15 @@ public interface IStorageDiskManager {
|
||||
@Nullable
|
||||
IStorageDisk get(UUID id);
|
||||
|
||||
/**
|
||||
* Gets the UUID of the given Storage Disk
|
||||
*
|
||||
* @param disk the storage disk
|
||||
* @return the storage disk's UUID, or null if no UUID is found
|
||||
*/
|
||||
@Nullable
|
||||
UUID getUuid(IStorageDisk disk);
|
||||
|
||||
/**
|
||||
* Gets a storage disk by disk stack (a {@link IStorageDiskProvider}).
|
||||
*
|
||||
|
||||
@@ -40,6 +40,12 @@ public class StorageDiskManager extends WorldSavedData implements IStorageDiskMa
|
||||
return disks.get(id);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public UUID getUuid(IStorageDisk disk) {
|
||||
// Return random UUID for now
|
||||
return UUID.randomUUID();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IStorageDisk getByStack(ItemStack disk) {
|
||||
|
||||
@@ -4,8 +4,14 @@ import com.raoulvdberge.refinedstorage.api.autocrafting.ICraftingPattern;
|
||||
import com.raoulvdberge.refinedstorage.api.autocrafting.task.ICraftingTask;
|
||||
import com.raoulvdberge.refinedstorage.api.autocrafting.task.ICraftingTaskError;
|
||||
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNode;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorage;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDisk;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskManager;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskRegistry;
|
||||
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.diskdrive.StorageDiskItemDriveWrapper;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.disk.StorageDiskManager;
|
||||
import li.cil.oc.api.Network;
|
||||
import li.cil.oc.api.machine.Arguments;
|
||||
import li.cil.oc.api.machine.Callback;
|
||||
@@ -13,6 +19,7 @@ import li.cil.oc.api.machine.Context;
|
||||
import li.cil.oc.api.network.Visibility;
|
||||
import li.cil.oc.api.prefab.AbstractManagedEnvironment;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
@@ -23,9 +30,7 @@ import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
import static com.raoulvdberge.refinedstorage.api.util.IComparer.COMPARE_DAMAGE;
|
||||
import static com.raoulvdberge.refinedstorage.api.util.IComparer.COMPARE_NBT;
|
||||
@@ -328,4 +333,70 @@ public class EnvironmentNetwork extends AbstractManagedEnvironment {
|
||||
|
||||
return new Object[]{node.getNetwork().getItemStorageCache().getList().getStacks()};
|
||||
}
|
||||
|
||||
@Callback(doc = "function():table -- Gets a list of all connected Storage Disks / Blocks in this network.")
|
||||
public Object[] getStorage(final Context context, final Arguments args) {
|
||||
int totalItemStored = 0;
|
||||
int totalItemCapacity = 0;
|
||||
int totalFluidStored = 0;
|
||||
int totalFluidCapacity = 0;
|
||||
|
||||
HashMap<String, HashMap<String, Object>> devices = new HashMap<String, HashMap<String, Object>>();
|
||||
|
||||
IStorageDiskManager sdm = API.instance().getStorageDiskManager(node.getWorld());
|
||||
|
||||
for (IStorage s : node.getNetwork().getItemStorageCache().getStorages()) {
|
||||
if (s instanceof IStorageDisk) {
|
||||
IStorageDisk sd = (IStorageDisk) s;
|
||||
String id = sd.getId();
|
||||
HashMap<String, Object> data = new HashMap();
|
||||
|
||||
data.put("type", "item");
|
||||
data.put("usage", sd.getStored());
|
||||
data.put("capacity", sd.getCapacity());
|
||||
|
||||
totalItemStored += sd.getStored();
|
||||
totalItemCapacity += sd.getCapacity();
|
||||
|
||||
UUID uuid = sdm.getUuid(sd);
|
||||
devices.put(uuid.toString(), data);
|
||||
}
|
||||
}
|
||||
|
||||
for (IStorage s : node.getNetwork().getFluidStorageCache().getStorages()) {
|
||||
if (s instanceof IStorageDisk) {
|
||||
IStorageDisk sd = (IStorageDisk) s;
|
||||
String id = sd.getId();
|
||||
HashMap<String, Object> data = new HashMap();
|
||||
|
||||
data.put("type", "fluid");
|
||||
data.put("usage", sd.getStored());
|
||||
data.put("capacity", sd.getCapacity());
|
||||
|
||||
totalFluidStored += sd.getStored();
|
||||
totalFluidCapacity += sd.getCapacity();
|
||||
|
||||
UUID uuid = sdm.getUuid(sd);
|
||||
devices.put(uuid.toString(), data);
|
||||
}
|
||||
}
|
||||
|
||||
HashMap<String, Integer> itemTotals = new HashMap<>();
|
||||
itemTotals.put("usage", totalItemStored);
|
||||
itemTotals.put("capacity", totalItemCapacity);
|
||||
|
||||
HashMap<String, Integer> fluidTotals = new HashMap<>();
|
||||
fluidTotals.put("usage", totalFluidStored);
|
||||
fluidTotals.put("capacity", totalFluidCapacity);
|
||||
|
||||
HashMap<String, Object> totals = new HashMap<>();
|
||||
totals.put("item", itemTotals);
|
||||
totals.put("fluid", fluidTotals);
|
||||
|
||||
HashMap<String, Object> response = new HashMap<>();
|
||||
response.put("total", totals);
|
||||
response.put("devices", devices);
|
||||
|
||||
return new Object[]{response};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user