Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (packetplayinwindowclick.d() == -1) {
- type = SlotType.OUTSIDE; // override
- click = packetplayinwindowclick.e() == 0 ? ClickType.WINDOW_BORDER_LEFT : ClickType.WINDOW_BORDER_RIGHT;
- action = InventoryAction.NOTHING;
- } else if (packetplayinwindowclick.h() == 0) {
- if (packetplayinwindowclick.e() == 0) {
- click = ClickType.LEFT;
- } else if (packetplayinwindowclick.e() == 1) {
- click = ClickType.RIGHT;
- }
- if (packetplayinwindowclick.e() == 0 || packetplayinwindowclick.e() == 1) {
- action = InventoryAction.NOTHING; // Don't want to repeat ourselves
- if (packetplayinwindowclick.d() == -999) {
- if (player.inventory.getCarried() != null) {
- action = packetplayinwindowclick.e() == 0 ? InventoryAction.DROP_ALL_CURSOR : InventoryAction.DROP_ONE_CURSOR;
- }
- } else {
- Slot slot = this.player.activeContainer.getSlot(packetplayinwindowclick.d());
- if (slot != null) {
- ItemStack clickedItem = slot.getItem();
- ItemStack cursor = player.inventory.getCarried();
- if (clickedItem == null) {
- if (cursor != null) {
- action = packetplayinwindowclick.e() == 0 ? InventoryAction.PLACE_ALL : InventoryAction.PLACE_ONE;
- }
- } else if (slot.a(player)) { // Should be Slot.isPlayerAllowed
- if (cursor == null) {
- action = packetplayinwindowclick.e() == 0 ? InventoryAction.PICKUP_ALL : InventoryAction.PICKUP_HALF;
- } else if (slot.isAllowed(cursor)) { // Should be Slot.isItemAllowed
- if (clickedItem.doMaterialsMatch(cursor) && ItemStack.equals(clickedItem, cursor)) {
- int toPlace = packetplayinwindowclick.e() == 0 ? cursor.count : 1;
- toPlace = Math.min(toPlace, clickedItem.getMaxStackSize() - clickedItem.count);
- toPlace = Math.min(toPlace, slot.inventory.getMaxStackSize() - clickedItem.count);
- if (toPlace == 1) {
- action = InventoryAction.PLACE_ONE;
- } else if (toPlace == cursor.count) {
- action = InventoryAction.PLACE_ALL;
- } else if (toPlace < 0) {
- action = toPlace != -1 ? InventoryAction.PICKUP_SOME : InventoryAction.PICKUP_ONE; // this happens with oversized stacks
- } else if (toPlace != 0) {
- action = InventoryAction.PLACE_SOME;
- }
- } else if (cursor.count <= slot.a()) { // Should be Slot.getMaxStackSize()
- action = InventoryAction.SWAP_WITH_CURSOR;
- }
- } else if (cursor.getItem() == clickedItem.getItem() && (!cursor.usesData() || cursor.getData() == clickedItem.getData()) && ItemStack.equals(cursor, clickedItem)) {
- if (clickedItem.count >= 0) {
- if (clickedItem.count + cursor.count <= cursor.getMaxStackSize()) {
- // As of 1.5, this is result slots only
- action = InventoryAction.PICKUP_ALL;
- }
- }
- }
- }
- }
- }
- }
- } else if (packetplayinwindowclick.h() == 1) {
- if (packetplayinwindowclick.e() == 0) {
- click = ClickType.SHIFT_LEFT;
- } else if (packetplayinwindowclick.e() == 1) {
- click = ClickType.SHIFT_RIGHT;
- }
- if (packetplayinwindowclick.e() == 0 || packetplayinwindowclick.e() == 1) {
- if (packetplayinwindowclick.d() < 0) {
- action = InventoryAction.NOTHING;
- } else {
- Slot slot = this.player.activeContainer.getSlot(packetplayinwindowclick.d());
- if (slot != null && slot.a(this.player) && slot.e()) { // Should be Slot.hasItem()
- action = InventoryAction.MOVE_TO_OTHER_INVENTORY;
- } else {
- action = InventoryAction.NOTHING;
- }
- }
- }
- } else if (packetplayinwindowclick.h() == 2) {
- if (packetplayinwindowclick.e() >= 0 && packetplayinwindowclick.e() < 9) {
- click = ClickType.NUMBER_KEY;
- Slot clickedSlot = this.player.activeContainer.getSlot(packetplayinwindowclick.d());
- if (clickedSlot.a(player)) {
- ItemStack hotbar = this.player.inventory.getItem(packetplayinwindowclick.e());
- boolean canCleanSwap = hotbar == null || (clickedSlot.inventory == player.inventory && clickedSlot.isAllowed(hotbar)); // the slot will accept the hotbar item
- if (clickedSlot.e()) {
- if (canCleanSwap) {
- action = InventoryAction.HOTBAR_SWAP;
- } else {
- int firstEmptySlot = player.inventory.j(); // Should be Inventory.firstEmpty()
- if (firstEmptySlot > -1) {
- action = InventoryAction.HOTBAR_MOVE_AND_READD;
- } else {
- action = InventoryAction.NOTHING; // This is not sane! Mojang: You should test for other slots of same type
- }
- }
- } else if (!clickedSlot.e() && hotbar != null && clickedSlot.isAllowed(hotbar)) {
- action = InventoryAction.HOTBAR_SWAP;
- } else {
- action = InventoryAction.NOTHING;
- }
- } else {
- action = InventoryAction.NOTHING;
- }
- // Special constructor for number key
- event = new InventoryClickEvent(inventory, type, packetplayinwindowclick.d(), click, action, packetplayinwindowclick.e());
- }
- } else if (packetplayinwindowclick.h() == 3) {
- if (packetplayinwindowclick.e() == 2) {
- click = ClickType.MIDDLE;
- if (packetplayinwindowclick.d() == -999) {
- action = InventoryAction.NOTHING;
- } else {
- Slot slot = this.player.activeContainer.getSlot(packetplayinwindowclick.d());
- if (slot != null && slot.e() && player.abilities.canInstantlyBuild && player.inventory.getCarried() == null) {
- action = InventoryAction.CLONE_STACK;
- } else {
- action = InventoryAction.NOTHING;
- }
- }
- } else {
- click = ClickType.UNKNOWN;
- action = InventoryAction.UNKNOWN;
- }
- } else if (packetplayinwindowclick.h() == 4) {
- if (packetplayinwindowclick.d() >= 0) {
- if (packetplayinwindowclick.e() == 0) {
- click = ClickType.DROP;
- Slot slot = this.player.activeContainer.getSlot(packetplayinwindowclick.d());
- if (slot != null && slot.e() && slot.a(player) && slot.getItem() != null && slot.getItem().getItem() != Item.getItemOf(Blocks.AIR)) {
- action = InventoryAction.DROP_ONE_SLOT;
- } else {
- action = InventoryAction.NOTHING;
- }
- } else if (packetplayinwindowclick.e() == 1) {
- click = ClickType.CONTROL_DROP;
- Slot slot = this.player.activeContainer.getSlot(packetplayinwindowclick.d());
- if (slot != null && slot.e() && slot.a(player) && slot.getItem() != null && slot.getItem().getItem() != Item.getItemOf(Blocks.AIR)) {
- action = InventoryAction.DROP_ALL_SLOT;
- } else {
- action = InventoryAction.NOTHING;
- }
- }
- } else {
- // Sane default (because this happens when they are holding nothing. Don't ask why.)
- click = ClickType.LEFT;
- if (packetplayinwindowclick.e() == 1) {
- click = ClickType.RIGHT;
- }
- action = InventoryAction.NOTHING;
- }
- } else if (packetplayinwindowclick.h() == 5) {
- itemstack = this.player.activeContainer.clickItem(packetplayinwindowclick.d(), packetplayinwindowclick.e(), 5, this.player);
- } else if (packetplayinwindowclick.h() == 6) {
- click = ClickType.DOUBLE_CLICK;
- action = InventoryAction.NOTHING;
- if (packetplayinwindowclick.d() >= 0 && this.player.inventory.getCarried() != null) {
- ItemStack cursor = this.player.inventory.getCarried();
- action = InventoryAction.NOTHING;
- // Quick check for if we have any of the item
- if (inventory.getTopInventory().contains(org.bukkit.Material.getMaterial(Item.b(cursor.getItem()))) || inventory.getBottomInventory().contains(org.bukkit.Material.getMaterial(Item.b(cursor.getItem())))) {
- action = InventoryAction.COLLECT_TO_CURSOR;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement