From e07ec4b596c1b83ddf092425f87c2951ab070d74 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Sun, 21 Jul 2024 10:31:01 -0600 Subject: [PATCH 1/4] fix filters --- .../common/util/inventory/FluidFilter.java | 13 ++++++------- .../common/util/inventory/ItemFilter.java | 13 ++++++------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidFilter.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidFilter.java index faad46a1f..393fac7da 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidFilter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidFilter.java @@ -103,16 +103,15 @@ public boolean test(FluidStack stack) { return fingerprint.equals(testFingerprint); } - // If the filter does not have nbt values, a tag or a fingerprint, just test if the items are the same - if (fluid != Fluids.EMPTY) { - if (tag == null && nbt == null && fingerprint.isEmpty()) - return stack.getFluid().isSame(fluid); + if (fluid != Fluids.EMPTY && !stack.getFluid().isSame(fluid)) { + return false; } - if (tag != null && !stack.getFluid().is(tag)) + if (tag != null && !stack.getFluid().is(tag)) { return false; - if (nbt != null && !stack.getOrCreateTag().equals(nbt) && (fluid == Fluids.EMPTY || stack.getFluid().isSame(fluid))) + } + if (nbt != null && !stack.getOrCreateTag().equals(nbt)) { return false; - + } return true; } diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java index bd943c892..f8a8074cf 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java @@ -118,16 +118,15 @@ public boolean test(ItemStack stack) { return fingerprint.equals(testFingerprint); } - // If the filter does not have nbt values, a tag or a fingerprint, just test if the items are the same - if (item != Items.AIR) { - if (tag == null && nbt == null && fingerprint.isEmpty()) - return stack.is(item); + if (item != Items.AIR && !stack.is(item)) { + return false; } - if (tag != null && !stack.is(tag)) + if (tag != null && !stack.is(tag)) { return false; - if (nbt != null && !stack.getOrCreateTag().equals(nbt) && (item == Items.AIR || stack.is(item))) + } + if (nbt != null && !stack.getOrCreateTag().equals(nbt)) { return false; - + } return true; } From 7ac8f696911aea506812f2cd2a206d3970de3b6d Mon Sep 17 00:00:00 2001 From: zyxkad Date: Sun, 21 Jul 2024 11:04:55 -0600 Subject: [PATCH 2/4] remove some unnecessary ItemStack.copy()s --- .../peripheral/RsBridgePeripheral.java | 2 +- .../addons/refinedstorage/RefinedStorage.java | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java index a45b81086..b65ce5135 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java @@ -74,7 +74,7 @@ public final MethodResult listCraftableItems() { return notConnected(); List items = new ArrayList<>(); - RefinedStorage.getCraftableItems(getNetwork()).forEach(item -> items.add(RefinedStorage.getObjectFromStack(item.copy(), getNetwork()))); + RefinedStorage.getCraftableItems(getNetwork()).forEach(item -> items.add(RefinedStorage.getObjectFromStack(item, getNetwork()))); return MethodResult.of(items); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorage.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorage.java index 9e13e7d8d..7f58105d6 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorage.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorage.java @@ -55,7 +55,7 @@ public static ItemStack findStackFromStack(INetwork network, @Nullable ICrafting public static ItemStack findStackFromFilter(INetwork network, @Nullable ICraftingManager crafting, ItemFilter filter) { for (StackListEntry temp : network.getItemStorageCache().getList().getStacks()) { - if (filter.test(temp.getStack().copy())) + if (filter.test(temp.getStack())) return temp.getStack().copy(); } @@ -64,7 +64,7 @@ public static ItemStack findStackFromFilter(INetwork network, @Nullable ICraftin for (ICraftingPattern pattern : crafting.getPatterns()) { for(ItemStack stack : pattern.getOutputs()) { - if (filter.test(stack.copy())) + if (filter.test(stack)) return stack.copy(); } } @@ -78,7 +78,7 @@ public static FluidStack findFluidFromStack(INetwork network, @Nullable ICraftin public static FluidStack findFluidFromFilter(INetwork network, @Nullable ICraftingManager crafting, FluidFilter filter) { for (StackListEntry temp : network.getFluidStorageCache().getList().getStacks()) { - if (filter.test(temp.getStack().copy())) + if (filter.test(temp.getStack())) return temp.getStack().copy(); } @@ -165,7 +165,7 @@ public static Object getObjectFromPattern(ICraftingPattern pattern, INetwork net List outputsList = pattern.getOutputs(); List outputs = new ArrayList<>(); for (ItemStack itemStack : outputsList) - outputs.add(getObjectFromStack(itemStack.copy(), network)); + outputs.add(getObjectFromStack(itemStack, network)); map.put("outputs", outputs); @@ -174,7 +174,7 @@ public static Object getObjectFromPattern(ICraftingPattern pattern, INetwork net for (List singleInputList : inputList) { List inputs1 = new ArrayList<>(); for (ItemStack stack : singleInputList) - inputs1.add(getObjectFromStack(stack.copy(), network)); + inputs1.add(getObjectFromStack(stack, network)); inputs.add(inputs1); } @@ -182,7 +182,7 @@ public static Object getObjectFromPattern(ICraftingPattern pattern, INetwork net if (!pattern.isProcessing()) { List byproductsList = pattern.getByproducts(); for (ItemStack stack : byproductsList) - byproducts.add(getObjectFromStack(stack.copy(), network)); + byproducts.add(getObjectFromStack(stack, network)); } map.put("inputs", inputs); @@ -228,7 +228,7 @@ public static Map getObjectFromFluid(@Nullable FluidStack fluidS public static Object getItem(INetwork network, ItemStack item) { for (ItemStack itemStack : getItems(network)) { if (itemStack.sameItem(item) && Objects.equals(itemStack.getTag(), item.getTag())) - return getObjectFromStack(itemStack.copy(), network); + return getObjectFromStack(itemStack, network); } return null; } From a80ac92f2ed8d27048f30317d09647fa500bd449 Mon Sep 17 00:00:00 2001 From: zyxkad Date: Sun, 21 Jul 2024 11:27:56 -0600 Subject: [PATCH 3/4] return nil instead of empty item for getItem --- .../peripheral/MeBridgePeripheral.java | 5 ++++- .../peripheral/RsBridgePeripheral.java | 13 ++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java index 731e451f4..2696ed9ed 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java @@ -420,7 +420,10 @@ public final MethodResult getItem(IArguments arguments) throws LuaException { if (parsedFilter.isEmpty()) return MethodResult.of(null, "EMPTY_FILTER"); - return MethodResult.of(AppEngApi.getObjectFromStack(AppEngApi.findAEStackFromFilter(monitor, getCraftingService(), parsedFilter), getCraftingService())); + Pair item = AppEngApi.findAEStackFromFilter(monitor, getCraftingService(), parsedFilter) + if (item.getRight().isEmpty()) + return MethodResult.of(null, "NOT_FOUND"); + return MethodResult.of(AppEngApi.getObjectFromStack(item, getCraftingService())); } @LuaFunction(mainThread = true) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java index b65ce5135..f9466bf80 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java @@ -296,10 +296,13 @@ public final MethodResult getItem(IArguments arguments) throws LuaException { return notConnected(); Pair filter = ItemFilter.parse(arguments.getTable(0)); - if (filter.rightPresent()) + if (filter.rightPresent()) return MethodResult.of(null, filter.getRight()); - return MethodResult.of(RefinedStorage.getObjectFromStack(RefinedStorage.findStackFromFilter(getNetwork(), getNetwork().getCraftingManager(), filter.getLeft()), getNetwork())); + ItemStack item = RefinedStorage.findStackFromFilter(getNetwork(), getNetwork().getCraftingManager(), filter.getLeft()) + if (item.isEmpty()) + return MethodResult.of(null, "NOT_FOUND"); + return MethodResult.of(RefinedStorage.getObjectFromStack(item, getNetwork())); } @LuaFunction(mainThread = true) @@ -313,7 +316,7 @@ public final MethodResult craftItem(IArguments arguments) throws LuaException { return MethodResult.of(null, filter.getRight()); ItemStack stack = RefinedStorage.findStackFromFilter(getNetwork(), getNetwork().getCraftingManager(), filter.getLeft()); - if (stack == null) + if (stack.isEmpty()) return MethodResult.of(null, "NOT_CRAFTABLE"); ICalculationResult result = getNetwork().getCraftingManager().create(stack, filter.getLeft().getCount()); @@ -334,7 +337,7 @@ public final MethodResult craftFluid(IArguments arguments) throws LuaException { return MethodResult.of(null, filter.getRight()); FluidStack stack = RefinedStorage.findFluidFromFilter(getNetwork(), getNetwork().getCraftingManager(), filter.getLeft()); - if (stack == null) + if (stack.isEmpty()) return MethodResult.of(null, "NOT_CRAFTABLE"); ICalculationResult result = getNetwork().getCraftingManager().create(stack, filter.getLeft().getCount()); @@ -355,7 +358,7 @@ public final MethodResult isItemCrafting(IArguments arguments) throws LuaExcepti return MethodResult.of(null, filter.getRight()); ItemStack stack = RefinedStorage.findStackFromFilter(getNetwork(), getNetwork().getCraftingManager(), filter.getLeft()); - if (stack == null) + if (stack.isEmpty()) return MethodResult.of(null, "NOT_CRAFTABLE"); for (ICraftingTask task : getNetwork().getCraftingManager().getTasks()) { From e61c391ec01254d3845f636bb6e894ed92e6056a Mon Sep 17 00:00:00 2001 From: zyxkad Date: Sun, 21 Jul 2024 13:42:01 -0600 Subject: [PATCH 4/4] remove trailing space --- .../addons/computercraft/peripheral/RsBridgePeripheral.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java index f9466bf80..ee71949cb 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java @@ -296,7 +296,7 @@ public final MethodResult getItem(IArguments arguments) throws LuaException { return notConnected(); Pair filter = ItemFilter.parse(arguments.getTable(0)); - if (filter.rightPresent()) + if (filter.rightPresent()) return MethodResult.of(null, filter.getRight()); ItemStack item = RefinedStorage.findStackFromFilter(getNetwork(), getNetwork().getCraftingManager(), filter.getLeft())