Fix StackingRule not being used inside to retrieve item count

This commit is contained in:
themode 2021-04-04 15:41:05 +02:00
parent d6b6d41f41
commit ea58d0f693
2 changed files with 10 additions and 8 deletions

View File

@ -132,7 +132,7 @@ public abstract class AbstractInventory implements InventoryClickHandler, DataCo
*/ */
public boolean canAddItemStack(@NotNull ItemStack itemStack) { public boolean canAddItemStack(@NotNull ItemStack itemStack) {
final StackingRule stackingRule = itemStack.getStackingRule(); final StackingRule stackingRule = itemStack.getStackingRule();
int amountLeft = itemStack.getAmount(); int amountLeft = stackingRule.getAmount(itemStack);
for (int i = 0; i < getInnerSize(); i++) { for (int i = 0; i < getInnerSize(); i++) {
ItemStack inventoryItem = getItemStack(i); ItemStack inventoryItem = getItemStack(i);
if (stackingRule.canBeStacked(itemStack, inventoryItem)) { if (stackingRule.canBeStacked(itemStack, inventoryItem)) {
@ -189,7 +189,7 @@ public abstract class AbstractInventory implements InventoryClickHandler, DataCo
} }
itemChangesMap.put(i, ItemStack.AIR); itemChangesMap.put(i, ItemStack.AIR);
itemStack = itemStack.withAmount(amount -> amount - itemAmount); itemStack = itemStack.withAmount(amount -> amount - itemAmount);
if (itemStack.getAmount() == 0) { if (stackingRule.getAmount(itemStack) == 0) {
itemStack = ItemStack.AIR; itemStack = ItemStack.AIR;
break; break;
} }

View File

@ -91,7 +91,7 @@ public class InventoryClickProcessor {
ItemStack resultClicked; ItemStack resultClicked;
if (clickedRule.canBeStacked(clicked, cursor)) { if (clickedRule.canBeStacked(clicked, cursor)) {
final int amount = clicked.getAmount() + 1; final int amount = clickedRule.getAmount(clicked) + 1;
if (!clickedRule.canApply(clicked, amount)) { if (!clickedRule.canApply(clicked, amount)) {
return clickResult; return clickResult;
} else { } else {
@ -100,12 +100,12 @@ public class InventoryClickProcessor {
} }
} else { } else {
if (cursor.isAir()) { if (cursor.isAir()) {
final int amount = (int) Math.ceil((double) clicked.getAmount() / 2d); final int amount = (int) Math.ceil((double) clickedRule.getAmount(clicked) / 2d);
resultCursor = cursorRule.apply(clicked, amount); resultCursor = cursorRule.apply(clicked, amount);
resultClicked = clickedRule.apply(clicked, clicked.getAmount() / 2); resultClicked = clickedRule.apply(clicked, clickedRule.getAmount(clicked) / 2);
} else { } else {
if (clicked.isAir()) { if (clicked.isAir()) {
final int amount = cursor.getAmount(); final int amount = cursorRule.getAmount(cursor);
resultCursor = cursorRule.apply(cursor, amount - 1); resultCursor = cursorRule.apply(cursor, amount - 1);
resultClicked = clickedRule.apply(cursor, 1); resultClicked = clickedRule.apply(cursor, 1);
} else { } else {
@ -287,10 +287,11 @@ public class InventoryClickProcessor {
clickResult = startCondition(inventory, player, s, ClickType.DRAGGING, slotItem, cursor); clickResult = startCondition(inventory, player, s, ClickType.DRAGGING, slotItem, cursor);
if (clickResult.isCancel()) if (clickResult.isCancel())
break; break;
StackingRule slotItemRule = slotItem.getStackingRule();
final int maxSize = stackingRule.getMaxSize(); final int maxSize = stackingRule.getMaxSize();
if (stackingRule.canBeStacked(draggedItem, slotItem)) { if (stackingRule.canBeStacked(draggedItem, slotItem)) {
final int amount = slotItem.getAmount() + slotSize; final int amount = slotItemRule.getAmount(slotItem) + slotSize;
if (stackingRule.canApply(slotItem, amount)) { if (stackingRule.canApply(slotItem, amount)) {
slotItem = stackingRule.apply(slotItem, amount); slotItem = stackingRule.apply(slotItem, amount);
finalCursorAmount -= slotSize; finalCursorAmount -= slotSize;
@ -328,8 +329,9 @@ public class InventoryClickProcessor {
if (clickResult.isCancel()) if (clickResult.isCancel())
break; break;
StackingRule slotItemRule = slotItem.getStackingRule();
if (stackingRule.canBeStacked(draggedItem, slotItem)) { if (stackingRule.canBeStacked(draggedItem, slotItem)) {
final int amount = slotItem.getAmount() + 1; final int amount = slotItemRule.getAmount(slotItem) + 1;
if (stackingRule.canApply(slotItem, amount)) { if (stackingRule.canApply(slotItem, amount)) {
slotItem = stackingRule.apply(slotItem, amount); slotItem = stackingRule.apply(slotItem, amount);
itemSetter.accept(s, slotItem); itemSetter.accept(s, slotItem);