mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-14 23:53:42 +01:00
Fix bad behavior with small-max-stack-sized items when extracting multiple items at once
This commit is contained in:
parent
16cf6a44de
commit
dff459a75f
2 changed files with 24 additions and 12 deletions
|
@ -7,6 +7,8 @@ import java.util.function.Predicate;
|
|||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
|
||||
import org.apache.commons.lang3.mutable.MutableInt;
|
||||
|
||||
import com.simibubi.create.foundation.config.AllConfigs;
|
||||
|
@ -161,7 +163,7 @@ public class ItemHelper {
|
|||
continue;
|
||||
if (!test.test(stack))
|
||||
continue;
|
||||
if (!extracting.isEmpty() && !ItemHandlerHelper.canItemStacksStack(stack, extracting)) {
|
||||
if (!extracting.isEmpty() && !canItemStackAmountsStack(stack, extracting)) {
|
||||
potentialOtherMatch = true;
|
||||
continue;
|
||||
}
|
||||
|
@ -174,8 +176,7 @@ public class ItemHelper {
|
|||
if (!simulate && hasEnoughItems)
|
||||
inv.extractItem(slot, stack.getCount(), false);
|
||||
|
||||
if (extracting.getCount() >= maxExtractionCount
|
||||
|| extracting.getCount() >= extracting.getMaxStackSize()) {
|
||||
if (extracting.getCount() >= maxExtractionCount) {
|
||||
if (checkHasEnoughItems) {
|
||||
hasEnoughItems = true;
|
||||
checkHasEnoughItems = false;
|
||||
|
@ -225,7 +226,7 @@ public class ItemHelper {
|
|||
|
||||
if (!test.test(stack))
|
||||
continue;
|
||||
if (!extracting.isEmpty() && !ItemHandlerHelper.canItemStacksStack(stack, extracting))
|
||||
if (!extracting.isEmpty() && !canItemStackAmountsStack(stack, extracting))
|
||||
continue;
|
||||
|
||||
if (extracting.isEmpty())
|
||||
|
@ -235,13 +236,17 @@ public class ItemHelper {
|
|||
|
||||
if (!simulate)
|
||||
inv.extractItem(slot, stack.getCount(), false);
|
||||
if (extracting.getCount() >= maxExtractionCount || extracting.getCount() >= extracting.getMaxStackSize())
|
||||
if (extracting.getCount() >= maxExtractionCount)
|
||||
break;
|
||||
}
|
||||
|
||||
return extracting;
|
||||
}
|
||||
|
||||
public static boolean canItemStackAmountsStack(ItemStack a, ItemStack b) {
|
||||
return ItemHandlerHelper.canItemStacksStack(a,b) && a.getCount() + b.getCount() <= a.getMaxStackSize();
|
||||
}
|
||||
|
||||
public static ItemStack findFirstMatch(IItemHandler inv, Predicate<ItemStack> test) {
|
||||
int slot = findFirstMatchingSlotIndex(inv, test);
|
||||
if (slot == -1)
|
||||
|
|
|
@ -107,12 +107,19 @@ public class InvManipulationBehaviour extends TileEntityBehaviour {
|
|||
return ItemStack.EMPTY;
|
||||
|
||||
Predicate<ItemStack> test = getFilterTest(filter);
|
||||
ItemStack extract = ItemStack.EMPTY;
|
||||
if (amount != -1)
|
||||
extract = ItemHelper.extract(inventory, test, amount, shouldSimulate);
|
||||
else
|
||||
extract = ItemHelper.extract(inventory, test, amountThreshold, shouldSimulate);
|
||||
return extract;
|
||||
|
||||
ItemStack simulatedItems = extractAmountOrThresh(inventory, test, amount, amountThreshold, true);
|
||||
if (shouldSimulate || simulatedItems.isEmpty())
|
||||
return simulatedItems;
|
||||
|
||||
return extractAmountOrThresh(inventory, test, amount, amountThreshold, false);
|
||||
}
|
||||
|
||||
private static ItemStack extractAmountOrThresh(IItemHandler inventory, Predicate<ItemStack> test, int amount,
|
||||
Function<ItemStack, Integer> amountThreshold, boolean shouldSimulate) {
|
||||
if (amount == -1)
|
||||
return ItemHelper.extract(inventory, test, amountThreshold, shouldSimulate);
|
||||
return ItemHelper.extract(inventory, test, amount, shouldSimulate);
|
||||
}
|
||||
|
||||
public ItemStack insert(ItemStack stack) {
|
||||
|
@ -156,7 +163,7 @@ public class InvManipulationBehaviour extends TileEntityBehaviour {
|
|||
if (!targetCapability.isPresent())
|
||||
findNewCapability();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
|
|
Loading…
Reference in a new issue