Broken custom Dropper and Beacon events using Bukkit.createInventory()

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: Minor
    • None
    • Affects Version/s: None
    • None

      Creating an inventory using Bukkit.createInventory() and using either InventoryType.DROPPER or InventoryType.BEACON and then opening it causes an exception to be thrown every time a slot is clicked (See attachments for stacktrace).

      I did some code digging, and it appears this is caused by the fact that the "setupSlots" method in CraftContainer.class does not account for either beacon or droppers (Droppers are also incorrectly classified as "minecraft:chest" in "getNotchInventoryType", but that is irrellevant to this issue). 

      private void setupSlots(IInventory top, IInventory bottom) {
          switch (cachedType) {
              case CREATIVE:
                  break; // TODO: This should be an error?
              case PLAYER:
              case CHEST:
                  setupChest(top, bottom);
                  break;
              case DISPENSER:
                  setupDispenser(top, bottom);
                  break;
              case FURNACE:
                  setupFurnace(top, bottom);
                  break;
              case CRAFTING: // TODO: This should be an error?
              case WORKBENCH:
                  setupWorkbench(top, bottom);
                  break;
              case ENCHANTING:
                  setupEnchanting(top, bottom);
                  break;
              case BREWING:
                  setupBrewing(top, bottom);
                  break;
              case HOPPER:
                  setupHopper(top, bottom);
                  break;
              case ANVIL:
                  setupAnvil(top, bottom);
                  break;
          }
      }
      

       

      As you can see, beacon and dropper have no representation in this method (there are a couple others which also don't have any representation, but they are handled the vanilla way). A solution to this would be to use the setupDispenser() method for droppers aswell (as their inventory layouts are identical), and for the beacon a new method to set it up would have to be created. Here's the fixed version of the method (along with a setupBeacon() method):

      private void setupSlots(IInventory top, IInventory bottom) {
          switch (cachedType) {
              case CREATIVE:
                  break; // TODO: This should be an error?
              case PLAYER:
              case CHEST:
                  setupChest(top, bottom);
                  break;
              case DROPPER:
              case DISPENSER:
                  setupDispenser(top, bottom);
                  break;
              case FURNACE:
                  setupFurnace(top, bottom);
                  break;
              case CRAFTING: // TODO: This should be an error?
              case WORKBENCH:
                  setupWorkbench(top, bottom);
                  break;
              case ENCHANTING:
                  setupEnchanting(top, bottom);
                  break;
              case BREWING:
                  setupBrewing(top, bottom);
                  break;
              case HOPPER:
                  setupHopper(top, bottom);
                  break;
              case ANVIL:
                  setupAnvil(top, bottom);
                  break;
              case BEACON:
                  setupBeacon(top, bottom);
                  break;
          }
      }
      
      private void setupBeacon(IInventory top, IInventory bottom) {
          // This code is copied from ContainerBeacon
          this.a(new Slot(top, 0, 136, 110));  
          for(int i = 0; i < 3; ++i) {
              for(int j = 0; j < 9; ++j) {
                  this.a(new Slot(iinventory, j + i * 9 + 9, 36 + j * 18, 137 + i * 18));
              }
          }
          for(i = 0; i < 9; ++i) {
              this.a(new Slot(iinventory, i, 36 + i * 18, 195));
          }
          // End copy from ContainerBeacon
      }

      Sorry if I went a little overboard with the code, I just wanted to share my conclusions incase of any help (I wouldn't fully trust my code either.. it may not be entirely perfect..)

            Assignee:
            Unassigned
            Reporter:
            Alvin Larsson Bringholm
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: