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:
@@ -19,6 +19,7 @@
|
||||
package appeng.core.sync.packets;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@@ -310,15 +311,10 @@ public class JEIRecipePacket extends BasePacket {
|
||||
*/
|
||||
private IAEItemStack findBestMatchingItemStack(Ingredient ingredients, IPartitionList<IAEItemStack> filter,
|
||||
IMEMonitor<IAEItemStack> storage, IContainerCraftingPacket cct) {
|
||||
return Arrays.stream(ingredients.getMatchingStacks()).map(AEItemStack::fromItemStack) //
|
||||
.filter(r -> r != null && (filter == null || filter.isListed(r))) //
|
||||
.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);
|
||||
Stream<AEItemStack> stacks = Arrays.stream(ingredients.getMatchingStacks())//
|
||||
.map(AEItemStack::fromItemStack) //
|
||||
.filter(r -> r != null && (filter == null || filter.isListed(r)));
|
||||
return getMostStored(stacks, storage, cct);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -329,16 +325,30 @@ public class JEIRecipePacket extends BasePacket {
|
||||
*/
|
||||
private IAEItemStack findBestMatchingPattern(Ingredient ingredients, IPartitionList<IAEItemStack> filter,
|
||||
ICraftingGrid crafting, IMEMonitor<IAEItemStack> storage, IContainerCraftingPacket cct) {
|
||||
return Arrays.stream(ingredients.getMatchingStacks()).map(AEItemStack::fromItemStack)
|
||||
.filter(r -> r != null && (filter == null || filter.isListed(r)))
|
||||
.map(s -> s.setCraftable(!crafting.getCraftingFor(s, null, 0, null).isEmpty()))
|
||||
.filter(IAEItemStack::isCraftable).map(s -> {
|
||||
final IAEItemStack stored = storage.extractItems(s, Actionable.SIMULATE, cct.getActionSource());
|
||||
return s.setStackSize(stored != null ? stored.getStackSize() : 0);
|
||||
}).min((left, right) -> {
|
||||
final int craftable = Boolean.compare(left.isCraftable(), right.isCraftable());
|
||||
return craftable != 0 ? craftable : Long.compare(right.getStackSize(), left.getStackSize());
|
||||
}).orElse(null);
|
||||
Stream<IAEItemStack> stacks = Arrays.stream(ingredients.getMatchingStacks())//
|
||||
.map(AEItemStack::fromItemStack)//
|
||||
.filter(r -> r != null && (filter == null || filter.isListed(r)))//
|
||||
.map(s -> s.setCraftable(!crafting.getCraftingFor(s, null, 0, null).isEmpty()))//
|
||||
.filter(IAEItemStack::isCraftable);
|
||||
return getMostStored(stacks, storage, cct);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
|
||||
Reference in New Issue
Block a user