Skip to content

Commit

Permalink
Fix dim and off-by-one error
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Jan 26, 2021
1 parent 58ce063 commit 2d2209e
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/main/java/net/citizensnpcs/api/gui/InventoryMenu.java
Expand Up @@ -32,7 +32,6 @@
import com.google.common.collect.Maps;
import com.google.common.collect.Queues;

// TODO: fix dim
public class InventoryMenu implements Listener {
private PageContext page;
private final Queue<PageContext> stack = Queues.newArrayDeque();
Expand Down Expand Up @@ -70,6 +69,8 @@ private int getInventorySize(InventoryType type, int[] dim) {
if (size % 9 != 0) {
size += 9 - (size % 9);
}
dim[0] = Math.min(54, size) / 9;
dim[1] = 9;
return Math.min(54, size);
case ANVIL:
case BLAST_FURNACE:
Expand All @@ -78,28 +79,46 @@ private int getInventorySize(InventoryType type, int[] dim) {
case GRINDSTONE:
case SMITHING:
case SMOKER:
dim[0] = 0;
dim[1] = 3;
return 3;
case BARREL:
case ENDER_CHEST:
case SHULKER_BOX:
dim[0] = 3;
dim[1] = 9;
return 27;
case BEACON:
case LECTERN:
dim[0] = 0;
dim[1] = 1;
return 1;
case BREWING:
case HOPPER:
dim[0] = 0;
dim[1] = 5;
return 5;
case DISPENSER:
case DROPPER:
dim[0] = 0;
dim[1] = 9;
return 9;
case ENCHANTING:
case STONECUTTER:
dim[0] = 0;
dim[1] = 2;
return 2;
case LOOM:
dim[0] = 0;
dim[1] = 4;
return 4;
case PLAYER:
dim[0] = 4;
dim[1] = 9;
return 41;
case WORKBENCH:
dim[0] = 0;
dim[1] = 10;
return 10;
default:
throw new UnsupportedOperationException(); // TODO
Expand Down Expand Up @@ -130,7 +149,6 @@ public void onInventoryClick(InventoryClickEvent event) {
}
InventoryMenuSlot slot = page.ctx.getSlot(event.getSlot());
page.page.onClick(slot, event);
System.out.println(page.clickHandlers.length);
for (Invokable<ClickHandler> invokable : page.clickHandlers) {
int idx = posToIndex(page.dim, invokable.data.slot());
if (event.getSlot() == idx && acceptFilter(event.getClick(), invokable.data.value())) {
Expand Down Expand Up @@ -180,7 +198,9 @@ private InventoryMenuPattern parsePattern(int[] dim, List<InventoryMenuTransitio
for (int i = 0; i < pattern.length(); i++) {
char c = pattern.charAt(i);
if (c == '\n' || (c == '\\' && i + 1 < pattern.length() && pattern.charAt(i + 1) == 'n')) {
i++;
if (c != '\n') {
i++;
}
row++;
col = 0;
continue;
Expand Down

0 comments on commit 2d2209e

Please sign in to comment.