Adapt the same sorting logic used for items stored in the network for items obtained from patterns, which fixes items from patterns not being able to be shift-clicked into new patterns.

This commit is contained in:
Sebastian Hartte
2020-09-16 17:44:49 +02:00
parent e73dbe4891
commit 475c8ff5a1
@@ -19,6 +19,7 @@
package appeng.core.sync.packets; package appeng.core.sync.packets;
import java.util.Arrays; import java.util.Arrays;
import java.util.stream.Stream;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@@ -310,15 +311,10 @@ public class JEIRecipePacket extends BasePacket {
*/ */
private IAEItemStack findBestMatchingItemStack(Ingredient ingredients, IPartitionList<IAEItemStack> filter, private IAEItemStack findBestMatchingItemStack(Ingredient ingredients, IPartitionList<IAEItemStack> filter,
IMEMonitor<IAEItemStack> storage, IContainerCraftingPacket cct) { IMEMonitor<IAEItemStack> storage, IContainerCraftingPacket cct) {
return Arrays.stream(ingredients.getMatchingStacks()).map(AEItemStack::fromItemStack) // Stream<AEItemStack> stacks = Arrays.stream(ingredients.getMatchingStacks())//
.filter(r -> r != null && (filter == null || filter.isListed(r))) // .map(AEItemStack::fromItemStack) //
.map(s -> { .filter(r -> r != null && (filter == null || filter.isListed(r)));
// Determine the stored count return getMostStored(stacks, storage, cct);
IAEItemStack stored = storage.extractItems(s.copy().setStackSize(Long.MAX_VALUE),
Actionable.SIMULATE, cct.getActionSource());
return Pair.of(s, stored != null ? stored.getStackSize() : 0);
}).min((left, right) -> Long.compare(right.getSecond(), left.getSecond()))//
.map(Pair::getFirst).orElse(null);
} }
/** /**
@@ -329,16 +325,30 @@ public class JEIRecipePacket extends BasePacket {
*/ */
private IAEItemStack findBestMatchingPattern(Ingredient ingredients, IPartitionList<IAEItemStack> filter, private IAEItemStack findBestMatchingPattern(Ingredient ingredients, IPartitionList<IAEItemStack> filter,
ICraftingGrid crafting, IMEMonitor<IAEItemStack> storage, IContainerCraftingPacket cct) { ICraftingGrid crafting, IMEMonitor<IAEItemStack> storage, IContainerCraftingPacket cct) {
return Arrays.stream(ingredients.getMatchingStacks()).map(AEItemStack::fromItemStack) Stream<IAEItemStack> stacks = Arrays.stream(ingredients.getMatchingStacks())//
.filter(r -> r != null && (filter == null || filter.isListed(r))) .map(AEItemStack::fromItemStack)//
.map(s -> s.setCraftable(!crafting.getCraftingFor(s, null, 0, null).isEmpty())) .filter(r -> r != null && (filter == null || filter.isListed(r)))//
.filter(IAEItemStack::isCraftable).map(s -> { .map(s -> s.setCraftable(!crafting.getCraftingFor(s, null, 0, null).isEmpty()))//
final IAEItemStack stored = storage.extractItems(s, Actionable.SIMULATE, cct.getActionSource()); .filter(IAEItemStack::isCraftable);
return s.setStackSize(stored != null ? stored.getStackSize() : 0); return getMostStored(stacks, storage, cct);
}).min((left, right) -> { }
final int craftable = Boolean.compare(left.isCraftable(), right.isCraftable());
return craftable != 0 ? craftable : Long.compare(right.getStackSize(), left.getStackSize()); /**
}).orElse(null); * From a stream of AE item stacks, pick the one with the highest available
* amount in the network. Returns null if the stream is empty.
*/
private static IAEItemStack getMostStored(Stream<? extends IAEItemStack> stacks, IMEMonitor<IAEItemStack> storage,
IContainerCraftingPacket cct) {
return stacks//
.map(s -> {
// Determine the stored count
IAEItemStack stored = storage.extractItems(s.copy().setStackSize(Long.MAX_VALUE),
Actionable.SIMULATE, cct.getActionSource());
return Pair.of(s, stored != null ? stored.getStackSize() : 0);
})//
.min((left, right) -> Long.compare(right.getSecond(), left.getSecond()))//
.map(Pair::getFirst)//
.orElse(null);
} }
private void handleProcessing(Container con, IContainerCraftingPacket cct, IRecipe<?> recipe) { private void handleProcessing(Container con, IContainerCraftingPacket cct, IRecipe<?> recipe) {