Skip to content

Commit

Permalink
Merge pull request #649 from zyxkad/filter-patch
Browse files Browse the repository at this point in the history
Fix filters
resolve #648
  • Loading branch information
zyxkad authored Aug 8, 2024
2 parents 5586f56 + e61c391 commit 4ee4f91
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Long, AEItemKey> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public final MethodResult listCraftableItems() {
return notConnected();

List<Object> 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);
}

Expand Down Expand Up @@ -299,7 +299,10 @@ public final MethodResult getItem(IArguments arguments) throws LuaException {
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)
Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ItemStack> temp : network.getItemStorageCache().getList().getStacks()) {
if (filter.test(temp.getStack().copy()))
if (filter.test(temp.getStack()))
return temp.getStack().copy();
}

Expand All @@ -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();
}
}
Expand All @@ -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<FluidStack> temp : network.getFluidStorageCache().getList().getStacks()) {
if (filter.test(temp.getStack().copy()))
if (filter.test(temp.getStack()))
return temp.getStack().copy();
}

Expand Down Expand Up @@ -165,7 +165,7 @@ public static Object getObjectFromPattern(ICraftingPattern pattern, INetwork net
List<ItemStack> outputsList = pattern.getOutputs();
List<Object> outputs = new ArrayList<>();
for (ItemStack itemStack : outputsList)
outputs.add(getObjectFromStack(itemStack.copy(), network));
outputs.add(getObjectFromStack(itemStack, network));

map.put("outputs", outputs);

Expand All @@ -174,15 +174,15 @@ public static Object getObjectFromPattern(ICraftingPattern pattern, INetwork net
for (List<ItemStack> singleInputList : inputList) {
List<Object> inputs1 = new ArrayList<>();
for (ItemStack stack : singleInputList)
inputs1.add(getObjectFromStack(stack.copy(), network));
inputs1.add(getObjectFromStack(stack, network));
inputs.add(inputs1);
}

List<Object> byproducts = new ArrayList<>();
if (!pattern.isProcessing()) {
List<ItemStack> byproductsList = pattern.getByproducts();
for (ItemStack stack : byproductsList)
byproducts.add(getObjectFromStack(stack.copy(), network));
byproducts.add(getObjectFromStack(stack, network));
}

map.put("inputs", inputs);
Expand Down Expand Up @@ -228,7 +228,7 @@ public static Map<String, Object> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 4ee4f91

Please sign in to comment.