Fixed OpenComputers voiding items with extract item API when there is no inventory space. Fixes #2081

This commit is contained in:
raoulvdberge
2018-11-17 12:12:58 +01:00
parent 90a0ddfdd7
commit 73d8cb3310
2 changed files with 13 additions and 8 deletions

View File

@@ -7,6 +7,7 @@
- Fixed network node scanning allowing multiple controllers in some cases (raoulvdberge) - Fixed network node scanning allowing multiple controllers in some cases (raoulvdberge)
- Fixed OpenComputers integration not giving back a crafting task instance in the schedule task API (raoulvdberge) - Fixed OpenComputers integration not giving back a crafting task instance in the schedule task API (raoulvdberge)
- Fixed OpenComputers integration causing log spam when getting processing patterns (raoulvdberge) - Fixed OpenComputers integration causing log spam when getting processing patterns (raoulvdberge)
- Fixed OpenComputers voiding items with extract item API when there is no inventory space (raoulvdberge)
- Fixed CraftingTweaks buttons resetting sometimes in the Crafting Grid (raoulvdberge) - Fixed CraftingTweaks buttons resetting sometimes in the Crafting Grid (raoulvdberge)
- Removed getMissingItems() and getMissingFluids() functions from the OpenComputers integration, that info is now accessible through schedule(Fluid)Task(). If you just want to check if there are missing items/fluids but don't want to start an actual task, use the "canSchedule" parameter (raoulvdberge) - Removed getMissingItems() and getMissingFluids() functions from the OpenComputers integration, that info is now accessible through schedule(Fluid)Task(). If you just want to check if there are missing items/fluids but don't want to start an actual task, use the "canSchedule" parameter (raoulvdberge)
- Added fluid functions for the fluid autocrafting to the OpenComputers integration (raoulvdberge) - Added fluid functions for the fluid autocrafting to the OpenComputers integration (raoulvdberge)

View File

@@ -309,18 +309,18 @@ public class EnvironmentNetwork extends AbstractManagedEnvironment {
} }
// Simulate extracting the item and get the amount of items that can be extracted // Simulate extracting the item and get the amount of items that can be extracted
ItemStack extractedSim = node.getNetwork().extractItem(stack, count, Action.SIMULATE); ItemStack extracted = node.getNetwork().extractItem(stack, count, Action.SIMULATE);
if (extractedSim == null) { if (extracted == null) {
return new Object[]{null, "could not extract the specified item"}; return new Object[]{null, "could not extract the specified item"};
} }
int transferableAmount = extractedSim.getCount(); int transferableAmount = extracted.getCount();
// Simulate inserting the item and see how many we were able to insert // Simulate inserting the item and see how many we were able to insert
IItemHandler handler = targetEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing.getOpposite()); IItemHandler handler = targetEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing.getOpposite());
ItemStack insertedSim = ItemHandlerHelper.insertItemStacked(handler, extractedSim, true); ItemStack remainder = ItemHandlerHelper.insertItemStacked(handler, extracted, true);
if (!insertedSim.isEmpty() && insertedSim.getCount() > 0) { if (!remainder.isEmpty()) {
transferableAmount -= insertedSim.getCount(); transferableAmount -= remainder.getCount();
} }
// Abort early if we can not insert items // Abort early if we can not insert items
@@ -329,9 +329,13 @@ public class EnvironmentNetwork extends AbstractManagedEnvironment {
} }
// Actually do it and return how many items we've inserted // Actually do it and return how many items we've inserted
ItemStack extracted = node.getNetwork().extractItem(stack, count, Action.PERFORM); extracted = node.getNetwork().extractItem(stack, transferableAmount, Action.PERFORM);
if (extracted != null) { if (extracted != null) {
ItemHandlerHelper.insertItemStacked(handler, extracted, false); remainder = ItemHandlerHelper.insertItemStacked(handler, extracted, false);
if (!remainder.isEmpty()) {
node.getNetwork().insertItem(remainder, remainder.getCount(), Action.PERFORM);
}
} }
return new Object[]{transferableAmount}; return new Object[]{transferableAmount};