Skip to content

Commit

Permalink
fix(menu): wrong replaceExistingItem behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
StarWishsama committed May 11, 2024
1 parent 09f5b0c commit 53a00c8
Showing 1 changed file with 2 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ public ChestMenu addPlayerInventoryClickHandler(MenuClickHandler handler) {
* @return The ChestMenu Instance
*/
public ChestMenu addItem(int slot, ItemStack item) {
resizeCheck(slot);

setSize((int) (Math.max(getSize(), Math.ceil((slot + 1) / 9d) * 9)));
this.items.set(slot, item);
this.inventory.setItem(slot, item);
return this;
}

Expand Down Expand Up @@ -266,8 +266,6 @@ public void reset(boolean update) {
*/
public void replaceExistingItem(int slot, ItemStack item) {
setup();
resizeCheck(slot);
this.items.set(slot, item);
this.inventory.setItem(slot, item);
}

Expand Down Expand Up @@ -339,7 +337,6 @@ public int getSize() {

public ChestMenu setSize(int size) {
if (size % 9 == 0 && size >= 0 && size < 55) {

// Resize items list to match actual inventory size in order to reset inventory.
// I'm sure that use size of items as inventory size is somehow strange.
if (size > items.size()) {
Expand Down Expand Up @@ -371,17 +368,6 @@ public boolean isSizeAutomaticallyInferred() {
return size == -1;
}

private void resizeCheck(int operateSlot) {
if (isSizeAutomaticallyInferred()) {
setSize((int) (Math.max(getSize(), Math.ceil((operateSlot + 1) / 9d) * 9)));
} else {
if ((operateSlot - 1) > getSize()) {
throw new IllegalStateException(
"Unable to add item since slot is larger than inv size (" + getSize() + ")");
}
}
}

@FunctionalInterface
public interface MenuClickHandler {

Expand Down

0 comments on commit 53a00c8

Please sign in to comment.