Advertisement
riking

Untitled

Dec 8th, 2013
374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.59 KB | None | 0 0
  1.  
  2.             if (packetplayinwindowclick.d() == -1) {
  3.                 type = SlotType.OUTSIDE; // override
  4.                 click = packetplayinwindowclick.e() == 0 ? ClickType.WINDOW_BORDER_LEFT : ClickType.WINDOW_BORDER_RIGHT;
  5.                 action = InventoryAction.NOTHING;
  6.             } else if (packetplayinwindowclick.h() == 0) {
  7.                 if (packetplayinwindowclick.e() == 0) {
  8.                     click = ClickType.LEFT;
  9.                 } else if (packetplayinwindowclick.e() == 1) {
  10.                     click = ClickType.RIGHT;
  11.                 }
  12.                 if (packetplayinwindowclick.e() == 0 || packetplayinwindowclick.e() == 1) {
  13.                     action = InventoryAction.NOTHING; // Don't want to repeat ourselves
  14.                     if (packetplayinwindowclick.d() == -999) {
  15.                         if (player.inventory.getCarried() != null) {
  16.                             action = packetplayinwindowclick.e() == 0 ? InventoryAction.DROP_ALL_CURSOR : InventoryAction.DROP_ONE_CURSOR;
  17.                         }
  18.                     } else {
  19.                         Slot slot = this.player.activeContainer.getSlot(packetplayinwindowclick.d());
  20.                         if (slot != null) {
  21.                             ItemStack clickedItem = slot.getItem();
  22.                             ItemStack cursor = player.inventory.getCarried();
  23.                             if (clickedItem == null) {
  24.                                 if (cursor != null) {
  25.                                     action = packetplayinwindowclick.e() == 0 ? InventoryAction.PLACE_ALL : InventoryAction.PLACE_ONE;
  26.                                 }
  27.                             } else if (slot.a(player)) { // Should be Slot.isPlayerAllowed
  28.                                 if (cursor == null) {
  29.                                     action = packetplayinwindowclick.e() == 0 ? InventoryAction.PICKUP_ALL : InventoryAction.PICKUP_HALF;
  30.                                 } else if (slot.isAllowed(cursor)) { // Should be Slot.isItemAllowed
  31.                                     if (clickedItem.doMaterialsMatch(cursor) && ItemStack.equals(clickedItem, cursor)) {
  32.                                         int toPlace = packetplayinwindowclick.e() == 0 ? cursor.count : 1;
  33.                                         toPlace = Math.min(toPlace, clickedItem.getMaxStackSize() - clickedItem.count);
  34.                                         toPlace = Math.min(toPlace, slot.inventory.getMaxStackSize() - clickedItem.count);
  35.                                         if (toPlace == 1) {
  36.                                             action = InventoryAction.PLACE_ONE;
  37.                                         } else if (toPlace == cursor.count) {
  38.                                             action = InventoryAction.PLACE_ALL;
  39.                                         } else if (toPlace < 0) {
  40.                                             action = toPlace != -1 ? InventoryAction.PICKUP_SOME : InventoryAction.PICKUP_ONE; // this happens with oversized stacks
  41.                                         } else if (toPlace != 0) {
  42.                                             action = InventoryAction.PLACE_SOME;
  43.                                         }
  44.                                     } else if (cursor.count <= slot.a()) { // Should be Slot.getMaxStackSize()
  45.                                         action = InventoryAction.SWAP_WITH_CURSOR;
  46.                                     }
  47.                                 } else if (cursor.getItem() == clickedItem.getItem() && (!cursor.usesData() || cursor.getData() == clickedItem.getData()) && ItemStack.equals(cursor, clickedItem)) {
  48.                                     if (clickedItem.count >= 0) {
  49.                                         if (clickedItem.count + cursor.count <= cursor.getMaxStackSize()) {
  50.                                             // As of 1.5, this is result slots only
  51.                                             action = InventoryAction.PICKUP_ALL;
  52.                                         }
  53.                                     }
  54.                                 }
  55.                             }
  56.                         }
  57.                     }
  58.                 }
  59.             } else if (packetplayinwindowclick.h() == 1) {
  60.                 if (packetplayinwindowclick.e() == 0) {
  61.                     click = ClickType.SHIFT_LEFT;
  62.                 } else if (packetplayinwindowclick.e() == 1) {
  63.                     click = ClickType.SHIFT_RIGHT;
  64.                 }
  65.                 if (packetplayinwindowclick.e() == 0 || packetplayinwindowclick.e() == 1) {
  66.                     if (packetplayinwindowclick.d() < 0) {
  67.                         action = InventoryAction.NOTHING;
  68.                     } else {
  69.                         Slot slot = this.player.activeContainer.getSlot(packetplayinwindowclick.d());
  70.                         if (slot != null && slot.a(this.player) && slot.e()) { // Should be Slot.hasItem()
  71.                             action = InventoryAction.MOVE_TO_OTHER_INVENTORY;
  72.                         } else {
  73.                             action = InventoryAction.NOTHING;
  74.                         }
  75.                     }
  76.                 }
  77.             } else if (packetplayinwindowclick.h() == 2) {
  78.                 if (packetplayinwindowclick.e() >= 0 && packetplayinwindowclick.e() < 9) {
  79.                     click = ClickType.NUMBER_KEY;
  80.                     Slot clickedSlot = this.player.activeContainer.getSlot(packetplayinwindowclick.d());
  81.                     if (clickedSlot.a(player)) {
  82.                         ItemStack hotbar = this.player.inventory.getItem(packetplayinwindowclick.e());
  83.                         boolean canCleanSwap = hotbar == null || (clickedSlot.inventory == player.inventory && clickedSlot.isAllowed(hotbar)); // the slot will accept the hotbar item
  84.                         if (clickedSlot.e()) {
  85.                             if (canCleanSwap) {
  86.                                 action = InventoryAction.HOTBAR_SWAP;
  87.                             } else {
  88.                                 int firstEmptySlot = player.inventory.j(); // Should be Inventory.firstEmpty()
  89.                                 if (firstEmptySlot > -1) {
  90.                                     action = InventoryAction.HOTBAR_MOVE_AND_READD;
  91.                                 } else {
  92.                                     action = InventoryAction.NOTHING; // This is not sane! Mojang: You should test for other slots of same type
  93.                                 }
  94.                             }
  95.                         } else if (!clickedSlot.e() && hotbar != null && clickedSlot.isAllowed(hotbar)) {
  96.                             action = InventoryAction.HOTBAR_SWAP;
  97.                         } else {
  98.                             action = InventoryAction.NOTHING;
  99.                         }
  100.                     } else {
  101.                         action = InventoryAction.NOTHING;
  102.                     }
  103.                     // Special constructor for number key
  104.                     event = new InventoryClickEvent(inventory, type, packetplayinwindowclick.d(), click, action, packetplayinwindowclick.e());
  105.                 }
  106.             } else if (packetplayinwindowclick.h() == 3) {
  107.                 if (packetplayinwindowclick.e() == 2) {
  108.                     click = ClickType.MIDDLE;
  109.                     if (packetplayinwindowclick.d() == -999) {
  110.                         action = InventoryAction.NOTHING;
  111.                     } else {
  112.                         Slot slot = this.player.activeContainer.getSlot(packetplayinwindowclick.d());
  113.                         if (slot != null && slot.e() && player.abilities.canInstantlyBuild && player.inventory.getCarried() == null) {
  114.                             action = InventoryAction.CLONE_STACK;
  115.                         } else {
  116.                             action = InventoryAction.NOTHING;
  117.                         }
  118.                     }
  119.                 } else {
  120.                     click = ClickType.UNKNOWN;
  121.                     action = InventoryAction.UNKNOWN;
  122.                 }
  123.             } else if (packetplayinwindowclick.h() == 4) {
  124.                 if (packetplayinwindowclick.d() >= 0) {
  125.                     if (packetplayinwindowclick.e() == 0) {
  126.                         click = ClickType.DROP;
  127.                         Slot slot = this.player.activeContainer.getSlot(packetplayinwindowclick.d());
  128.                         if (slot != null && slot.e() && slot.a(player) && slot.getItem() != null && slot.getItem().getItem() != Item.getItemOf(Blocks.AIR)) {
  129.                             action = InventoryAction.DROP_ONE_SLOT;
  130.                         } else {
  131.                             action = InventoryAction.NOTHING;
  132.                         }
  133.                     } else if (packetplayinwindowclick.e() == 1) {
  134.                         click = ClickType.CONTROL_DROP;
  135.                         Slot slot = this.player.activeContainer.getSlot(packetplayinwindowclick.d());
  136.                         if (slot != null && slot.e() && slot.a(player) && slot.getItem() != null && slot.getItem().getItem() != Item.getItemOf(Blocks.AIR)) {
  137.                             action = InventoryAction.DROP_ALL_SLOT;
  138.                         } else {
  139.                             action = InventoryAction.NOTHING;
  140.                         }
  141.                     }
  142.                 } else {
  143.                     // Sane default (because this happens when they are holding nothing. Don't ask why.)
  144.                     click = ClickType.LEFT;
  145.                     if (packetplayinwindowclick.e() == 1) {
  146.                         click = ClickType.RIGHT;
  147.                     }
  148.                     action = InventoryAction.NOTHING;
  149.                 }
  150.             } else if (packetplayinwindowclick.h() == 5) {
  151.                 itemstack = this.player.activeContainer.clickItem(packetplayinwindowclick.d(), packetplayinwindowclick.e(), 5, this.player);
  152.             } else if (packetplayinwindowclick.h() == 6) {
  153.                 click = ClickType.DOUBLE_CLICK;
  154.                 action = InventoryAction.NOTHING;
  155.                 if (packetplayinwindowclick.d() >= 0 && this.player.inventory.getCarried() != null) {
  156.                     ItemStack cursor = this.player.inventory.getCarried();
  157.                     action = InventoryAction.NOTHING;
  158.                     // Quick check for if we have any of the item
  159.                     if (inventory.getTopInventory().contains(org.bukkit.Material.getMaterial(Item.b(cursor.getItem()))) || inventory.getBottomInventory().contains(org.bukkit.Material.getMaterial(Item.b(cursor.getItem())))) {
  160.                         action = InventoryAction.COLLECT_TO_CURSOR;
  161.                     }
  162.                 }
  163.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement