Fixed #153 - "OpenComputers / ComputerCraft API"
This commit is contained in:
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
### 1.4.5
|
### 1.4.5
|
||||||
- Updated Forge to 2296 (raoulvdberge)
|
- Updated Forge to 2296 (raoulvdberge)
|
||||||
|
- Added Portable Grid (raoulvdberge)
|
||||||
|
- Added OpenComputers integration (thraaawn)
|
||||||
- Fixed Crafting Tweaks buttons positioned wrongly (blay09)
|
- Fixed Crafting Tweaks buttons positioned wrongly (blay09)
|
||||||
- Fixed Crafting Tweaks keybindings interfering with RS keybindings (blay09)
|
- Fixed Crafting Tweaks keybindings interfering with RS keybindings (blay09)
|
||||||
- Fixed crash when updating storages (raoulvdberge)
|
- Fixed crash when updating storages (raoulvdberge)
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.raoulvdberge.refinedstorage.integration.oc;
|
||||||
|
|
||||||
|
import com.raoulvdberge.refinedstorage.api.autocrafting.ICraftingPattern;
|
||||||
|
import li.cil.oc.api.driver.Converter;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class ConverterCraftingPattern implements Converter {
|
||||||
|
@Override
|
||||||
|
public void convert(Object value, final Map<Object, Object> output) {
|
||||||
|
if (value instanceof ICraftingPattern) {
|
||||||
|
ICraftingPattern pattern = (ICraftingPattern) value;
|
||||||
|
|
||||||
|
output.put("outputs", pattern.getOutputs());
|
||||||
|
output.put("inputs", pattern.getInputs());
|
||||||
|
output.put("byproducts", pattern.getByproducts());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.raoulvdberge.refinedstorage.integration.oc;
|
||||||
|
|
||||||
|
import com.raoulvdberge.refinedstorage.api.autocrafting.task.ICraftingTask;
|
||||||
|
import li.cil.oc.api.driver.Converter;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class ConverterCraftingTask implements Converter {
|
||||||
|
@Override
|
||||||
|
public void convert(Object value, Map<Object, Object> output) {
|
||||||
|
if (value instanceof ICraftingTask) {
|
||||||
|
ICraftingTask task = (ICraftingTask) value;
|
||||||
|
|
||||||
|
output.put("stack", task.getRequested());
|
||||||
|
output.put("missing", task.getMissing().getStacks());
|
||||||
|
output.put("pattern", task.getPattern());
|
||||||
|
output.put("quantity", task.getQuantity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,20 @@
|
|||||||
package com.raoulvdberge.refinedstorage.integration.oc;
|
package com.raoulvdberge.refinedstorage.integration.oc;
|
||||||
|
|
||||||
|
import com.raoulvdberge.refinedstorage.api.autocrafting.ICraftingPattern;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.autocrafting.task.ICraftingTask;
|
||||||
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNode;
|
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNode;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
||||||
|
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||||
import li.cil.oc.api.Network;
|
import li.cil.oc.api.Network;
|
||||||
|
import li.cil.oc.api.machine.Arguments;
|
||||||
|
import li.cil.oc.api.machine.Callback;
|
||||||
|
import li.cil.oc.api.machine.Context;
|
||||||
import li.cil.oc.api.network.Visibility;
|
import li.cil.oc.api.network.Visibility;
|
||||||
import li.cil.oc.api.prefab.AbstractManagedEnvironment;
|
import li.cil.oc.api.prefab.AbstractManagedEnvironment;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
|
import static com.raoulvdberge.refinedstorage.api.util.IComparer.COMPARE_DAMAGE;
|
||||||
|
import static com.raoulvdberge.refinedstorage.api.util.IComparer.COMPARE_NBT;
|
||||||
|
|
||||||
public class EnvironmentNetwork extends AbstractManagedEnvironment {
|
public class EnvironmentNetwork extends AbstractManagedEnvironment {
|
||||||
protected final INetworkNode node;
|
protected final INetworkNode node;
|
||||||
@@ -13,5 +24,153 @@ public class EnvironmentNetwork extends AbstractManagedEnvironment {
|
|||||||
|
|
||||||
setNode(Network.newNode(this, Visibility.Network).withComponent("refinedstorage", Visibility.Network).create());
|
setNode(Network.newNode(this, Visibility.Network).withComponent("refinedstorage", Visibility.Network).create());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Callback
|
||||||
|
public Object[] isConnected(final Context context, final Arguments args) {
|
||||||
|
return new Object[]{node.getNetwork() != null};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Callback
|
||||||
|
public Object[] getEnergyUsage(final Context context, final Arguments args) {
|
||||||
|
if (node.getNetwork() == null) {
|
||||||
|
return new Object[]{null, "not connected"};
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Object[]{node.getNetwork().getEnergyUsage()};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Callback
|
||||||
|
public Object[] getCraftingTasks(final Context context, final Arguments args) {
|
||||||
|
if (node.getNetwork() == null) {
|
||||||
|
return new Object[]{null, "not connected"};
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Object[]{node.getNetwork().getCraftingManager().getTasks()};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Callback
|
||||||
|
public Object[] getPatterns(final Context context, final Arguments args) {
|
||||||
|
if (node.getNetwork() == null) {
|
||||||
|
return new Object[]{null, "not connected"};
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Object[]{node.getNetwork().getCraftingManager().getPatterns()};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Callback
|
||||||
|
public Object[] hasPattern(final Context context, final Arguments args) {
|
||||||
|
if (node.getNetwork() == null) {
|
||||||
|
return new Object[]{null, "not connected"};
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemStack stack = args.checkItemStack(0);
|
||||||
|
|
||||||
|
return new Object[]{node.getNetwork().getCraftingManager().hasPattern(stack)};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Callback
|
||||||
|
public Object[] getMissingItems(final Context context, final Arguments args) {
|
||||||
|
if (node.getNetwork() == null) {
|
||||||
|
return new Object[]{null, "not connected"};
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemStack stack = args.checkItemStack(0);
|
||||||
|
|
||||||
|
if (!node.getNetwork().getCraftingManager().hasPattern(stack)) {
|
||||||
|
throw new IllegalArgumentException("No pattern for this item stack exists");
|
||||||
|
}
|
||||||
|
|
||||||
|
int count = args.optInteger(1, 1);
|
||||||
|
ICraftingPattern pattern = node.getNetwork().getCraftingManager().getPattern(stack);
|
||||||
|
|
||||||
|
ICraftingTask task = node.getNetwork().getCraftingManager().create(stack, pattern, count, true);
|
||||||
|
task.calculate();
|
||||||
|
|
||||||
|
return new Object[]{task.getMissing().getStacks()};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Callback
|
||||||
|
public Object[] scheduleTask(final Context context, final Arguments args) {
|
||||||
|
if (node.getNetwork() == null) {
|
||||||
|
return new Object[]{"not connected"};
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemStack stack = args.checkItemStack(0);
|
||||||
|
|
||||||
|
if (!node.getNetwork().getCraftingManager().hasPattern(stack)) {
|
||||||
|
throw new IllegalArgumentException("No pattern for this item stack exists");
|
||||||
|
}
|
||||||
|
|
||||||
|
int amount = args.optInteger(1, 1);
|
||||||
|
ICraftingPattern pattern = node.getNetwork().getCraftingManager().getPattern(stack);
|
||||||
|
|
||||||
|
ICraftingTask task = node.getNetwork().getCraftingManager().create(stack, pattern, amount, true);
|
||||||
|
task.calculate();
|
||||||
|
|
||||||
|
node.getNetwork().getCraftingManager().add(task);
|
||||||
|
|
||||||
|
return new Object[]{};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Callback
|
||||||
|
public Object[] cancelTask(final Context context, final Arguments args) {
|
||||||
|
if (node.getNetwork() == null) {
|
||||||
|
return new Object[]{null, "not connected"};
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemStack stack = args.checkItemStack(0);
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
for (ICraftingTask task : node.getNetwork().getCraftingManager().getTasks()) {
|
||||||
|
if (API.instance().getComparer().isEqual(task.getRequested(), stack, COMPARE_NBT | COMPARE_DAMAGE)) {
|
||||||
|
node.getNetwork().getCraftingManager().cancel(task);
|
||||||
|
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Object[]{count};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Callback
|
||||||
|
public Object[] getFluids(final Context context, final Arguments args) {
|
||||||
|
if (node.getNetwork() == null) {
|
||||||
|
return new Object[]{null, "not connected"};
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Object[]{node.getNetwork().getFluidStorageCache().getList().getStacks()};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Callback
|
||||||
|
public Object[] getItem(final Context context, final Arguments args) {
|
||||||
|
if (node.getNetwork() == null) {
|
||||||
|
return new Object[]{null, "not connected"};
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemStack stack = args.checkItemStack(0);
|
||||||
|
boolean compareMeta = args.optBoolean(1, true);
|
||||||
|
boolean compareNBT = args.optBoolean(2, true);
|
||||||
|
|
||||||
|
int flags = 0;
|
||||||
|
|
||||||
|
if (compareMeta) {
|
||||||
|
flags |= IComparer.COMPARE_DAMAGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (compareNBT) {
|
||||||
|
flags |= IComparer.COMPARE_NBT;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Object[]{node.getNetwork().getItemStorageCache().getList().get(stack, flags)};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Callback
|
||||||
|
public Object[] getItems(final Context context, final Arguments args) {
|
||||||
|
if (node.getNetwork() == null) {
|
||||||
|
return new Object[]{null, "not connected"};
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Object[]{node.getNetwork().getItemStorageCache().getList().getStacks()};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,5 +12,8 @@ public final class IntegrationOC {
|
|||||||
|
|
||||||
public static void register() {
|
public static void register() {
|
||||||
Driver.add(new DriverNetwork());
|
Driver.add(new DriverNetwork());
|
||||||
|
|
||||||
|
Driver.add(new ConverterCraftingPattern());
|
||||||
|
Driver.add(new ConverterCraftingTask());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user