Skip to content

Commit

Permalink
Fix compression handling in edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
MattiDragon committed Jul 13, 2023
1 parent f91b264 commit cd9034f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions changelog/2.0.3+1.20.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Fix compression handling in edge cases
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ private ItemVariant findBottom(ItemVariant item, World world) {
return candidate;
}

@Nullable
private RecipePair findCompressionRecipe(ItemVariant decompressed, World world) {
return IntStream.of(3, 2, 1)
.mapToObj(size -> findCompressionRecipeForSize(decompressed, world, size))
Expand All @@ -101,17 +102,19 @@ private RecipePair findCompressionRecipe(ItemVariant decompressed, World world)
}

private Stream<RecipePair> findCompressionRecipeForSize(ItemVariant decompressed, World world, int size) {
var decompressedStack = decompressed.toStack(size * size);
return findRecipes(decompressed.toStack(), size, world) // Find compression recipes
.filter(compressed -> findRecipes(compressed, 1, world).anyMatch(decompressed::matches))// Find matching decompression recipe
.filter(compressed -> findRecipes(compressed, 1, world).anyMatch(decompressed2 -> ItemStack.areEqual(decompressed2, decompressedStack))) // Find matching decompression recipe
.map(compressed -> new RecipePair(ItemVariant.of(compressed), decompressed, size * size));
}

@Nullable
private RecipePair findDecompressionRecipe(ItemVariant compressed, World world) {
return findRecipes(compressed.toStack(), 1, world) // Find decompression recipe
.flatMap(result -> IntStream.of(3, 2, 1) // Check each size from largest to smallest for matching compression recipes
.filter(size -> findRecipes(result, size, world).anyMatch(compressed::matches))
.mapToObj(size -> new RecipePair(compressed, ItemVariant.of(result), size * size)))
var compressedStack = compressed.toStack();
return findRecipes(compressedStack, 1, world) // Find decompression recipe
.flatMap(decompressed -> IntStream.of(3, 2, 1) // Check each size from largest to smallest for matching compression recipes
.filter(size -> findRecipes(decompressed, size, world).anyMatch(compressed2 -> ItemStack.areEqual(compressedStack, compressed2)))
.mapToObj(size -> new RecipePair(compressed, ItemVariant.of(decompressed), size * size)))
.findFirst()
.orElse(null);
}
Expand Down

0 comments on commit cd9034f

Please sign in to comment.