Fixes #4508: Correctly construct the sparse lists. (#4511)

* Fixes #4508: Correctly construct the sparse lists.

Also renamed all uncondensed getters to sparse and all condensed to the simple ones.

* Apply suggestions from code review

Co-authored-by: shartte <shartte@users.noreply.github.com>

* Streamlined collapsing the sparse lists

* Extracted helper to condense stacks

* Sort lists desc by stack size

Co-authored-by: shartte <shartte@users.noreply.github.com>
This commit is contained in:
yueh
2020-07-27 11:21:06 +02:00
committed by GitHub
parent 6cb6c21495
commit 662dbca3e1
8 changed files with 152 additions and 136 deletions
@@ -23,6 +23,8 @@
package appeng.api.networking.crafting;
import java.util.List;
import net.minecraft.inventory.CraftingInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
@@ -60,24 +62,65 @@ public interface ICraftingPatternDetails {
boolean isCraftable();
/**
* Equal itemstacks will be aggregated into one, respectively 3*64 will be
* returned as one stack of 192, up to 576 of a single type.
* <p>
* This should be the preferred way to deal with the list of inputs.
* <p>
* The list will be sorted in descending order by stack size. However there is
* no guarantee about maintaining the placement order of the inputs in case of
* equal values.
*
* @return an immutable list of inputs without nulls
*/
List<IAEItemStack> getInputs();
/**
* Equal itemstacks will be aggregated into one, respectively 2*32 will be
* returned as one stack of 64, up to 192 of a single type.
* <p>
* This should be the preferred way to deal with the list of outputs.
* <p>
*
* The list will be sorted in descending order by stack size. However there is
* no guarantee about maintaining the placement order of the outputs in case of
* equal values.
*
* @return an immutable list of outputs without nulls
*/
List<IAEItemStack> getOutputs();
/**
* A sparse list representing the placement order of a crafting grid, left to
* right, then top to bottom.
* <p>
* Only use when absolutely necessary, always prefer
* {@link ICraftingPatternDetails#getInputs()}
* <p>
* This will contain exactly 9 entries.
* <p>
* This can return a copy from the internal structure, so there are no
* guarantees about modifications.
*
* @return a list of the inputs, will include nulls.
*/
IAEItemStack[] getInputs();
/**
* @return a list of the inputs, will be clean
*/
IAEItemStack[] getCondensedInputs();
/**
* @return a list of the outputs, will be clean
*/
IAEItemStack[] getCondensedOutputs();
IAEItemStack[] getSparseInputs();
/**
* A sparse list representing the placement order of the respective output
* slots.
* <p>
* Only use when absolutely necessary, always prefer
* {@link ICraftingPatternDetails#getOutputs()}
* <p>
* This will either contain 1 entry for crafting patterns or 3 for processing.
* <p>
* This can return a copy from the internal structure, so there are no
* guarantees about modifications.
*
* @return a list of the outputs, will include nulls.
*/
IAEItemStack[] getOutputs();
IAEItemStack[] getSparseOutputs();
/**
* @return if this pattern is enabled to support substitutions.