Skip to content

Commit

Permalink
Fix incorrect reversibility check
Browse files Browse the repository at this point in the history
  • Loading branch information
62832 committed Jan 16, 2023
1 parent 20bc300 commit c1499a2
Showing 1 changed file with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package gripe._90.megacells.item.cell;

import java.util.Collections;
import java.util.List;
import java.util.stream.Stream;

Expand All @@ -9,7 +8,6 @@
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;

import net.minecraft.server.MinecraftServer;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.crafting.CraftingRecipe;
import net.minecraft.world.item.crafting.RecipeType;
Expand Down Expand Up @@ -40,53 +38,62 @@ private boolean isDecompressionRecipe(CraftingRecipe recipe) {
}

private List<CraftingRecipe> getCompressionRecipes(List<CraftingRecipe> recipes) {
List<CraftingRecipe> compressionRecipes = new ObjectArrayList<>();
var compressionRecipes = new ObjectArrayList<CraftingRecipe>();

for (var recipe : recipes) {
if (isCompressionRecipe(recipe)) {
compressionRecipes.add(recipe);
}
}

return compressionRecipes;
}

private List<CraftingRecipe> getDecompressionRecipes(List<CraftingRecipe> recipes) {
List<CraftingRecipe> decompressionRecipes = new ObjectArrayList<>();
var decompressionRecipes = new ObjectArrayList<CraftingRecipe>();

for (var recipe : recipes) {
if (isDecompressionRecipe(recipe)) {
decompressionRecipes.add(recipe);
}
}

return decompressionRecipes;
}

private List<CraftingRecipe> getCandidateRecipes() {
MinecraftServer currentServer = AppEng.instance().getCurrentServer();
List<CraftingRecipe> allRecipes = currentServer != null
var currentServer = AppEng.instance().getCurrentServer();
var allRecipes = currentServer != null
? currentServer.getRecipeManager().getAllRecipesFor(RecipeType.CRAFTING)
: Collections.emptyList();
: new ObjectArrayList<CraftingRecipe>();

return Stream.concat(
allRecipes.stream().filter(this::isCompressionRecipe),
allRecipes.stream().filter(this::isDecompressionRecipe)).toList();
}

private boolean isReversibleRecipe(CraftingRecipe recipe, List<CraftingRecipe> candidates) {
var compressible = false;
var decompressible = false;

var input = recipe.getIngredients().get(0);
var output = recipe.getResultItem();

for (var candidate : candidates) {
for (var item : candidate.getIngredients().get(0).getItems()) {
if (item.getItem().equals(output.getItem())) {
return true;
compressible = true;
}
}

for (var item : input.getItems()) {
if (item.getItem().equals(candidate.getResultItem().getItem())) {
return true;
decompressible = true;
}
}
}
return false;

return compressible && decompressible;
}

public void load() {
Expand All @@ -104,16 +111,19 @@ private Pair<Item, Integer> getSubsequentVariant(Item item, List<CraftingRecipe>
}
}
}

return null;
}

private int getMultiplier(CraftingRecipe recipe) {
if (isCompressionRecipe(recipe)) {
return recipe.getIngredients().size();
}

if (isDecompressionRecipe(recipe)) {
return recipe.getResultItem().getCount();
}

return 1;
}

Expand Down

0 comments on commit c1499a2

Please sign in to comment.