diff --git a/common/src/main/java/gripe/_90/megacells/item/cell/CompressionHandler.java b/common/src/main/java/gripe/_90/megacells/item/cell/CompressionHandler.java index 734291f1..f887e327 100644 --- a/common/src/main/java/gripe/_90/megacells/item/cell/CompressionHandler.java +++ b/common/src/main/java/gripe/_90/megacells/item/cell/CompressionHandler.java @@ -1,6 +1,5 @@ package gripe._90.megacells.item.cell; -import java.util.Collections; import java.util.List; import java.util.stream.Stream; @@ -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; @@ -40,30 +38,34 @@ private boolean isDecompressionRecipe(CraftingRecipe recipe) { } private List getCompressionRecipes(List recipes) { - List compressionRecipes = new ObjectArrayList<>(); + var compressionRecipes = new ObjectArrayList(); + for (var recipe : recipes) { if (isCompressionRecipe(recipe)) { compressionRecipes.add(recipe); } } + return compressionRecipes; } private List getDecompressionRecipes(List recipes) { - List decompressionRecipes = new ObjectArrayList<>(); + var decompressionRecipes = new ObjectArrayList(); + for (var recipe : recipes) { if (isDecompressionRecipe(recipe)) { decompressionRecipes.add(recipe); } } + return decompressionRecipes; } private List getCandidateRecipes() { - MinecraftServer currentServer = AppEng.instance().getCurrentServer(); - List allRecipes = currentServer != null + var currentServer = AppEng.instance().getCurrentServer(); + var allRecipes = currentServer != null ? currentServer.getRecipeManager().getAllRecipesFor(RecipeType.CRAFTING) - : Collections.emptyList(); + : new ObjectArrayList(); return Stream.concat( allRecipes.stream().filter(this::isCompressionRecipe), @@ -71,22 +73,27 @@ private List getCandidateRecipes() { } private boolean isReversibleRecipe(CraftingRecipe recipe, List 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() { @@ -104,6 +111,7 @@ private Pair getSubsequentVariant(Item item, List } } } + return null; } @@ -111,9 +119,11 @@ private int getMultiplier(CraftingRecipe recipe) { if (isCompressionRecipe(recipe)) { return recipe.getIngredients().size(); } + if (isDecompressionRecipe(recipe)) { return recipe.getResultItem().getCount(); } + return 1; }