Skip to content

Commit 2c43ee7

Browse files
Revert "Changed item merging from full inventory copy to partial stacks copy"
This reverts commit f05c193.
1 parent 80d3ed8 commit 2c43ee7

2 files changed

Lines changed: 5 additions & 25 deletions

File tree

src/main/java/gregtech/api/metatileentity/MetaTileEntity.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import gregtech.api.render.Textures;
2323
import gregtech.api.util.GTFluidUtils;
2424
import gregtech.api.util.GTUtility;
25-
import gregtech.api.util.InventoryUtils;
2625
import net.minecraft.block.Block;
2726
import net.minecraft.block.state.BlockFaceShape;
2827
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
@@ -57,6 +56,8 @@
5756
import java.util.List;
5857
import java.util.function.Consumer;
5958

59+
import static gregtech.api.util.InventoryUtils.simulateItemStackMerge;
60+
6061
public abstract class MetaTileEntity implements ICoverable {
6162

6263
public static final int DEFAULT_PAINTING_COLOR = 0xFFFFFF;
@@ -990,14 +991,8 @@ public static boolean addItemsToItemHandler(final IItemHandler handler,
990991
final boolean simulate,
991992
final List<ItemStack> items) {
992993
// determine if there is sufficient room to insert all items into the target inventory
993-
boolean canMerge;
994-
if (items.size() == 1) {
995-
canMerge = ItemHandlerHelper.insertItemStacked(handler, items.get(0), true).isEmpty();
996-
} else {
997-
// merging 2 or more stacks may change the slots available for merging,
998-
// needing full simulation of the state of the inventory after every merge
999-
canMerge = InventoryUtils.simulateItemStackMerge(items, handler);
1000-
}
994+
final boolean canMerge = simulateItemStackMerge(items, handler);
995+
1001996
// if we're not simulating and the merge should succeed, perform the merge.
1002997
if (!simulate && canMerge)
1003998
items.forEach(stack -> {

src/main/java/gregtech/api/util/InventoryUtils.java

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,6 @@ public static List<ItemStack> deepCopy(final IItemHandler inventory,
4343
.collect(Collectors.toList());
4444
}
4545

46-
/**
47-
* Creates a copy of the partial stacks in target inventory
48-
*
49-
* @param inventory the target inventory
50-
* @return a copy of the partial stacks of the inventory.
51-
*/
52-
public static List<ItemStack> copyPartialStacks(final IItemHandler inventory) {
53-
54-
return streamFrom(inventory)
55-
.filter(not(ItemStack::isEmpty))
56-
.filter(not(itemStack -> itemStack.getCount() == itemStack.getMaxStackSize()))
57-
.map(ItemStack::copy)
58-
.collect(Collectors.toList());
59-
}
60-
6146
/**
6247
* Determines whether all specified items will fit into a target inventory by
6348
* simulating merging like items into existing stacks, then checking if there
@@ -90,7 +75,7 @@ public static boolean simulateItemStackMerge(List<ItemStack> inputItems,
9075
itemStacks.sort(Comparator.comparingInt(ItemStack::getCount));
9176

9277
// Deep copy the contents of the target inventory, skipping empty stacks
93-
final List<ItemStack> inventoryStacks = copyPartialStacks(inventory);
78+
final List<ItemStack> inventoryStacks = deepCopy(inventory, false);
9479

9580
// Perform a merge of the ItemStacks
9681
mergeItemStacks(itemStacks, inventoryStacks);

0 commit comments

Comments
 (0)