mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-03 23:17:48 +01:00
Give the right result for InventoryClickHandler#drop
This commit is contained in:
parent
45d901a0bc
commit
28e6ef9b87
@ -7,7 +7,6 @@ import net.minestom.server.item.ItemStack;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Represent an inventory which can receive click input
|
* Represent an inventory which can receive click input
|
||||||
* <p>
|
|
||||||
* all methods returning boolean returns true if the action is successful, false otherwise
|
* all methods returning boolean returns true if the action is successful, false otherwise
|
||||||
*/
|
*/
|
||||||
public interface InventoryClickHandler {
|
public interface InventoryClickHandler {
|
||||||
|
@ -443,13 +443,17 @@ public class InventoryClickProcessor {
|
|||||||
// Left (drop all)
|
// Left (drop all)
|
||||||
int amount = cursorRule.getAmount(resultCursor);
|
int amount = cursorRule.getAmount(resultCursor);
|
||||||
ItemStack dropItem = cursorRule.apply(resultCursor.clone(), amount);
|
ItemStack dropItem = cursorRule.apply(resultCursor.clone(), amount);
|
||||||
if (player.dropItem(dropItem)) {
|
boolean dropResult = player.dropItem(dropItem);
|
||||||
|
clickResult.setCancel(!dropResult);
|
||||||
|
if (dropResult) {
|
||||||
resultCursor = cursorRule.apply(resultCursor, 0);
|
resultCursor = cursorRule.apply(resultCursor, 0);
|
||||||
}
|
}
|
||||||
} else if (button == 1) {
|
} else if (button == 1) {
|
||||||
// Right (drop 1)
|
// Right (drop 1)
|
||||||
ItemStack dropItem = cursorRule.apply(resultCursor.clone(), 1);
|
ItemStack dropItem = cursorRule.apply(resultCursor.clone(), 1);
|
||||||
if (player.dropItem(dropItem)) {
|
boolean dropResult = player.dropItem(dropItem);
|
||||||
|
clickResult.setCancel(!dropResult);
|
||||||
|
if (dropResult) {
|
||||||
int amount = cursorRule.getAmount(resultCursor);
|
int amount = cursorRule.getAmount(resultCursor);
|
||||||
int newAmount = amount - 1;
|
int newAmount = amount - 1;
|
||||||
resultCursor = cursorRule.apply(resultCursor, newAmount);
|
resultCursor = cursorRule.apply(resultCursor, newAmount);
|
||||||
@ -460,7 +464,9 @@ public class InventoryClickProcessor {
|
|||||||
if (button == 0) {
|
if (button == 0) {
|
||||||
// Drop key Q (drop 1)
|
// Drop key Q (drop 1)
|
||||||
ItemStack dropItem = cursorRule.apply(resultClicked.clone(), 1);
|
ItemStack dropItem = cursorRule.apply(resultClicked.clone(), 1);
|
||||||
if (player.dropItem(dropItem)) {
|
boolean dropResult = player.dropItem(dropItem);
|
||||||
|
clickResult.setCancel(!dropResult);
|
||||||
|
if (dropResult) {
|
||||||
int amount = clickedRule.getAmount(resultClicked);
|
int amount = clickedRule.getAmount(resultClicked);
|
||||||
int newAmount = amount - 1;
|
int newAmount = amount - 1;
|
||||||
resultClicked = cursorRule.apply(resultClicked, newAmount);
|
resultClicked = cursorRule.apply(resultClicked, newAmount);
|
||||||
@ -469,7 +475,9 @@ public class InventoryClickProcessor {
|
|||||||
// Ctrl + Drop key Q (drop all)
|
// Ctrl + Drop key Q (drop all)
|
||||||
int amount = cursorRule.getAmount(resultClicked);
|
int amount = cursorRule.getAmount(resultClicked);
|
||||||
ItemStack dropItem = clickedRule.apply(resultClicked.clone(), amount);
|
ItemStack dropItem = clickedRule.apply(resultClicked.clone(), amount);
|
||||||
if (player.dropItem(dropItem)) {
|
boolean dropResult = player.dropItem(dropItem);
|
||||||
|
clickResult.setCancel(!dropResult);
|
||||||
|
if (dropResult) {
|
||||||
resultClicked = cursorRule.apply(resultClicked, 0);
|
resultClicked = cursorRule.apply(resultClicked, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user