mirror of
https://github.com/Minestom/Minestom.git
synced 2024-11-15 15:16:46 +01:00
Added StackingRule#apply with unary operator for amount
This commit is contained in:
parent
aac32420de
commit
8f6a651bda
@ -95,18 +95,17 @@ public class InventoryClickProcessor {
|
||||
if (!clickedRule.canApply(clicked, amount)) {
|
||||
return clickResult;
|
||||
} else {
|
||||
resultCursor = cursorRule.apply(cursor, cursorRule.getAmount(cursor) - 1);
|
||||
resultCursor = cursorRule.apply(cursor, operand -> operand - 1);
|
||||
resultClicked = clickedRule.apply(clicked, amount);
|
||||
}
|
||||
} else {
|
||||
if (cursor.isAir()) {
|
||||
final int amount = (int) Math.ceil((double) clickedRule.getAmount(clicked) / 2d);
|
||||
resultCursor = cursorRule.apply(clicked, amount);
|
||||
resultClicked = clickedRule.apply(clicked, clickedRule.getAmount(clicked) / 2);
|
||||
resultClicked = clickedRule.apply(clicked, operand -> operand / 2);
|
||||
} else {
|
||||
if (clicked.isAir()) {
|
||||
final int amount = cursorRule.getAmount(cursor);
|
||||
resultCursor = cursorRule.apply(cursor, amount - 1);
|
||||
resultCursor = cursorRule.apply(cursor, operand -> operand - 1);
|
||||
resultClicked = clickedRule.apply(cursor, 1);
|
||||
} else {
|
||||
resultCursor = clicked;
|
||||
@ -573,6 +572,7 @@ public class InventoryClickProcessor {
|
||||
@NotNull ClickType clickType, @NotNull ItemStack clicked, @NotNull ItemStack cursor) {
|
||||
InventoryClickEvent inventoryClickEvent = new InventoryClickEvent(inventory, player, slot, clickType, clicked, cursor);
|
||||
player.callEvent(InventoryClickEvent.class, inventoryClickEvent);
|
||||
System.out.println("click");
|
||||
}
|
||||
|
||||
public void clearCache(@NotNull Player player) {
|
||||
|
@ -3,6 +3,8 @@ package net.minestom.server.item;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.IntUnaryOperator;
|
||||
|
||||
/**
|
||||
* Represents the stacking rule of an {@link ItemStack}.
|
||||
* This can be used to mimic the vanilla one (using the displayed item quantity)
|
||||
@ -46,6 +48,11 @@ public abstract class StackingRule {
|
||||
@Contract("_, _ -> new")
|
||||
public abstract @NotNull ItemStack apply(@NotNull ItemStack item, int newAmount);
|
||||
|
||||
@Contract("_, _ -> new")
|
||||
public @NotNull ItemStack apply(@NotNull ItemStack item, @NotNull IntUnaryOperator amountOperator) {
|
||||
return apply(item, amountOperator.applyAsInt(getAmount(item)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to determine the current stack size of an {@link ItemStack}.
|
||||
* It is possible to have it stored in its {@link net.minestom.server.data.Data} object, lore, etc...
|
||||
|
Loading…
Reference in New Issue
Block a user