Camerapture

Camerapture

376k Downloads

PictureCloningRecipe matches empty inventories

DaFuqs opened this issue ยท 2 comments

commented

I got a bug report that Spectrum's Pedestal, which is able to craft vanilla recipes, breaks when Camerapture is also installed.

Checking out both in a dev env, I found that the recipe camerapture:picture_cloning returns a valid recipe on getRecipe when the input inventory is completely empty.

Your loop iterates all non-empty stacks in the inventory (of which there are none) and then returns a Optional.of(new Pair<>(<ItemStack.EMPTY>.copyWithCount(0), remainder)); in this case. It should be accounted for, so empty inventories don't match.

private Optional<Pair<ItemStack, DefaultedList<ItemStack>>> getRecipe(List<ItemStack> items) {
DefaultedList<ItemStack> remainder = DefaultedList.ofSize(items.size(), ItemStack.EMPTY);
ItemStack picture = ItemStack.EMPTY;
int paper = 0;
for (int i = 0; i < items.size(); i++) {
ItemStack stack = items.get(i);
if (!stack.isEmpty()) {
if (stack.isOf(Camerapture.PICTURE)) {
if (!picture.isEmpty() || PictureItem.getPictureData(stack) == null) {
return Optional.empty();
}
remainder.set(i, stack.copyWithCount(1));
picture = stack;
} else {
if (!stack.isOf(Items.PAPER)) {
return Optional.empty();
}
++paper;
}
}
}
return Optional.of(new Pair<>(picture.copyWithCount(paper), remainder));
}

commented

Ah yeah you're right, good find! I'll make sure this is fixed in the next release!

commented

Thank you!