private static boolean canMergeItems(ItemStack itemstack, ItemStack itemstack1) { return itemstack.getItem() != itemstack1.getItem() ? false : (itemstack.getData() != itemstack1.getData() ? false : (itemstack.count > itemstack.getMaxStackSize() ? false : ItemStack.equals(itemstack, itemstack1))); }
public void a(Packet102WindowClick packet102windowclick) { // CraftBukkit start if (this.player.dead) { return; } // CraftBukkit end if (this.player.activeContainer.f == packet102windowclick.a && this.player.activeContainer.c(this.player)) { ItemStack itemstack = this.player.activeContainer.a( packet102windowclick.b, packet102windowclick.c, packet102windowclick.f, this.player); if (ItemStack.equals(packet102windowclick.e, itemstack)) { this.player.netServerHandler.sendPacket( new Packet106Transaction(packet102windowclick.a, packet102windowclick.d, true)); this.player.h = true; this.player.activeContainer.a(); this.player.y(); this.player.h = false; } else { this.n.put( Integer.valueOf(this.player.activeContainer.f), Short.valueOf(packet102windowclick.d)); this.player.netServerHandler.sendPacket( new Packet106Transaction(packet102windowclick.a, packet102windowclick.d, false)); this.player.activeContainer.a(this.player, false); ArrayList arraylist = new ArrayList(); for (int i = 0; i < this.player.activeContainer.e.size(); ++i) { arraylist.add(((Slot) this.player.activeContainer.e.get(i)).getItem()); } this.player.a(this.player.activeContainer, arraylist); } } }
public void a(Packet15Place packet15place) { WorldServer worldserver = this.minecraftServer.a(this.player.dimension); // CraftBukkit start if (this.player.dead) { return; } // This is b horrible hack needed because the client sends 2 packets on 'right mouse click' // aimed at b block. We shouldn't need to get the second packet if the data is handled // but we cannot know what the client will do, so we might still get it // // If the time between packets is small enough, and the 'signature' similar, we discard the // second one. This sadly has to remain until Mojang makes their packets saner. :( // -- Grum if (packet15place.face == 255) { if (packet15place.itemstack != null && packet15place.itemstack.id == lastMaterial && lastPacket != null && packet15place.timestamp - lastPacket < 100) { lastPacket = null; return; } } else { lastMaterial = packet15place.itemstack == null ? -1 : packet15place.itemstack.id; lastPacket = packet15place.timestamp; } // CraftBukkit - if rightclick decremented the item, always send the update packet. // this is not here for CraftBukkit's own functionality; rather it is to fix // b notch bug where the item doesn't update correctly. boolean always = false; // CraftBukkit end ItemStack itemstack = this.player.inventory.getItemInHand(); boolean flag = worldserver.weirdIsOpCache = worldserver.worldProvider.dimension != 0 || this.minecraftServer.serverConfigurationManager.isOp(this.player.name); if (packet15place.face == 255) { if (itemstack == null) { return; } // CraftBukkit start int itemstackAmount = itemstack.count; PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(this.player, Action.RIGHT_CLICK_AIR, itemstack); if (event.useItemInHand() != Event.Result.DENY) { this.player.itemInWorldManager.useItem(this.player, this.player.world, itemstack); } // CraftBukkit - notch decrements the counter by 1 in the above method with food, // snowballs and so forth, but he does it in b place that doesn't cause the // inventory update packet to get sent always = (itemstack.count != itemstackAmount); // CraftBukkit end } else { int i = packet15place.a; int j = packet15place.b; int k = packet15place.c; int l = packet15place.face; ChunkCoordinates chunkcoordinates = worldserver.getSpawn(); int i1 = (int) MathHelper.abs((float) (i - chunkcoordinates.x)); int j1 = (int) MathHelper.abs((float) (k - chunkcoordinates.z)); if (i1 > j1) { j1 = i1; } // CraftBukkit start - Check if we can actually do something over this large a distance Location eyeLoc = getPlayer().getEyeLocation(); if (Math.pow(eyeLoc.getX() - i, 2) + Math.pow(eyeLoc.getY() - j, 2) + Math.pow(eyeLoc.getZ() - k, 2) > PLACE_DISTANCE_SQUARED) { return; } flag = true; // spawn protection moved to ItemBlock!!! // CraftBukkit end if (j1 > 16 || flag) { this.player.itemInWorldManager.interact(this.player, worldserver, itemstack, i, j, k, l); } this.player.netServerHandler.sendPacket(new Packet53BlockChange(i, j, k, worldserver)); if (l == 0) { --j; } if (l == 1) { ++j; } if (l == 2) { --k; } if (l == 3) { ++k; } if (l == 4) { --i; } if (l == 5) { ++i; } this.player.netServerHandler.sendPacket(new Packet53BlockChange(i, j, k, worldserver)); } itemstack = this.player.inventory.getItemInHand(); if (itemstack != null && itemstack.count == 0) { this.player.inventory.items[this.player.inventory.itemInHandIndex] = null; } this.player.h = true; this.player.inventory.items[this.player.inventory.itemInHandIndex] = ItemStack.b(this.player.inventory.items[this.player.inventory.itemInHandIndex]); Slot slot = this.player.activeContainer.a(this.player.inventory, this.player.inventory.itemInHandIndex); this.player.activeContainer.a(); this.player.h = false; // CraftBukkit if (!ItemStack.equals(this.player.inventory.getItemInHand(), packet15place.itemstack) || always) { this.sendPacket( new Packet103SetSlot( this.player.activeContainer.f, slot.a, this.player.inventory.getItemInHand())); } worldserver.weirdIsOpCache = false; }
public boolean handleInventoryClick( Packet102WindowClick packet, InventorySlotType type, SpoutCraftItemStack slot, SpoutCraftItemStack cursor, Inventory inventory) { InventoryClickEvent event = null; Result result = Result.DEFAULT; boolean success = false; final int LEFT_CLICK = 0; final int RIGHT_CLICK = 1; int click = packet.c; // clicked on bottom player inventory if (!(this.player.activeContainer instanceof ContainerPlayer) && this.player.defaultContainer instanceof ContainerPlayer && packet.b >= inventory.getSize()) { int activeSlot = packet.b - inventory.getSize() + 9; if (activeSlot >= this.getPlayer().getInventory().getSize()) { activeSlot -= this.getPlayer().getInventory().getSize(); } type = getInventorySlotType(activeSlot); event = new InventoryPlayerClickEvent( this.getPlayer(), this.getPlayer().getInventory(), type, slot, cursor, activeSlot, click == LEFT_CLICK, packet.f, activeLocation); } else { event = new InventoryClickEvent( this.getPlayer(), inventory, type, slot, cursor, packet.b, click == LEFT_CLICK, packet.f, activeLocation); } if (event != null) { Bukkit.getServer().getPluginManager().callEvent(event); result = event.getResult(); cursor = SpoutCraftItemStack.getCraftItemStack(event.getCursor()); slot = SpoutCraftItemStack.getCraftItemStack(event.getItem()); } // initialize setup ItemStack itemstack = slot != null ? slot.getHandle() : null; ItemStack cursorstack = cursor != null ? cursor.getHandle() : null; // NOTE: Successful means that its successful as-is; thus, only becomes true for default // behaviour switch (result) { case DEFAULT: itemstack = this.player.activeContainer.a(packet.b, packet.c, packet.f, this.player); success = ItemStack.equals(packet.e, itemstack); break; case DENY: if (packet.b != -999) { // Only swap if target is not OUTSIDE if (itemstack != null) { setActiveSlot(packet.b, itemstack); setCursorSlot((ItemStack) null); } if (event.getCursor() != null) { setActiveSlot(packet.b, itemstack); setCursorSlot(cursorstack); } } break; case ALLOW: // Allow the placement unconditionally if (packet.b == -999) { // Clicked outside, just defer to default itemstack = this.player.activeContainer.a(packet.b, packet.c, packet.f, this.player); } else { if (click == LEFT_CLICK && (itemstack != null && cursorstack != null && itemstack.doMaterialsMatch(cursorstack))) { // Left-click full slot with full cursor of same item; merge stacks itemstack.count += cursorstack.count; cursorstack = null; } else if (click == LEFT_CLICK || (itemstack != null && cursorstack != null && !itemstack.doMaterialsMatch(cursorstack))) { // Either left-click, or right-click full slot with full cursor of different item; just // swap contents ItemStack temp = itemstack; itemstack = cursorstack; cursorstack = temp; } else if (click == RIGHT_CLICK) { // Right-click with either slot or cursor empty if (itemstack == null) { // Slot empty; drop one if (cursorstack != null) { itemstack = cursorstack.a(1); if (cursorstack.count == 0) { cursorstack = null; } } } else if (cursorstack == null) { // Cursor empty; take half cursorstack = itemstack.a((itemstack.count + 1) / 2); } else { // Neither empty, but same item; drop one ItemStack drop = cursorstack.a(1); itemstack.count += drop.count; if (cursorstack.count == 0) { cursorstack = null; } } } // update the stacks setActiveSlot(packet.b, itemstack); setCursorSlot(cursorstack); } break; } return success; }
protected boolean a(ItemStack itemstack, int i, int j, boolean flag) { boolean flag1 = false; int k = i; if (flag) { k = j - 1; } Slot slot; ItemStack itemstack1; if (itemstack.isStackable()) { while (itemstack.count > 0 && (!flag && k < j || flag && k >= i)) { slot = (Slot) this.c.get(k); itemstack1 = slot.getItem(); if (itemstack1 != null && itemstack1.id == itemstack.id && (!itemstack.usesData() || itemstack.getData() == itemstack1.getData()) && ItemStack.equals(itemstack, itemstack1)) { int l = itemstack1.count + itemstack.count; if (l <= itemstack.getMaxStackSize()) { itemstack.count = 0; itemstack1.count = l; slot.e(); flag1 = true; } else if (itemstack1.count < itemstack.getMaxStackSize()) { itemstack.count -= itemstack.getMaxStackSize() - itemstack1.count; itemstack1.count = itemstack.getMaxStackSize(); slot.e(); flag1 = true; } } if (flag) { --k; } else { ++k; } } } if (itemstack.count > 0) { if (flag) { k = j - 1; } else { k = i; } while (!flag && k < j || flag && k >= i) { slot = (Slot) this.c.get(k); itemstack1 = slot.getItem(); if (itemstack1 == null) { slot.set(itemstack.cloneItemStack()); slot.e(); itemstack.count = 0; flag1 = true; break; } if (flag) { --k; } else { ++k; } } } return flag1; }
public ItemStack clickItem(int i, int j, int k, EntityHuman entityhuman) { ItemStack itemstack = null; PlayerInventory playerinventory = entityhuman.inventory; Slot slot; ItemStack itemstack1; int l; ItemStack itemstack2; if ((k == 0 || k == 1) && (j == 0 || j == 1)) { if (i == -999) { if (playerinventory.getCarried() != null && i == -999) { if (j == 0) { entityhuman.drop(playerinventory.getCarried()); playerinventory.setCarried((ItemStack) null); } if (j == 1) { // CraftBukkit start - store a reference ItemStack itemstack3 = playerinventory.getCarried(); if (itemstack3.count > 0) { entityhuman.drop(itemstack3.a(1)); } if (itemstack3.count == 0) { // CraftBukkit end playerinventory.setCarried((ItemStack) null); } } } } else if (k == 1) { slot = (Slot) this.c.get(i); if (slot != null && slot.a(entityhuman)) { itemstack1 = this.b(entityhuman, i); if (itemstack1 != null) { int i1 = itemstack1.id; itemstack = itemstack1.cloneItemStack(); if (slot != null && slot.getItem() != null && slot.getItem().id == i1) { this.a(i, j, true, entityhuman); } } } } else { if (i < 0) { return null; } slot = (Slot) this.c.get(i); if (slot != null) { itemstack1 = slot.getItem(); ItemStack itemstack3 = playerinventory.getCarried(); if (itemstack1 != null) { itemstack = itemstack1.cloneItemStack(); } if (itemstack1 == null) { if (itemstack3 != null && slot.isAllowed(itemstack3)) { l = j == 0 ? itemstack3.count : 1; if (l > slot.a()) { l = slot.a(); } // CraftBukkit start if (itemstack3.count >= l) { slot.set(itemstack3.a(l)); } // CraftBukkit end if (itemstack3.count == 0) { playerinventory.setCarried((ItemStack) null); } } } else if (slot.a(entityhuman)) { if (itemstack3 == null) { l = j == 0 ? itemstack1.count : (itemstack1.count + 1) / 2; itemstack2 = slot.a(l); playerinventory.setCarried(itemstack2); if (itemstack1.count == 0) { slot.set((ItemStack) null); } slot.a(entityhuman, playerinventory.getCarried()); } else if (slot.isAllowed(itemstack3)) { if (itemstack1.id == itemstack3.id && (!itemstack1.usesData() || itemstack1.getData() == itemstack3.getData()) && ItemStack.equals(itemstack1, itemstack3)) { l = j == 0 ? itemstack3.count : 1; if (l > slot.a() - itemstack1.count) { l = slot.a() - itemstack1.count; } if (l > itemstack3.getMaxStackSize() - itemstack1.count) { l = itemstack3.getMaxStackSize() - itemstack1.count; } itemstack3.a(l); if (itemstack3.count == 0) { playerinventory.setCarried((ItemStack) null); } itemstack1.count += l; } else if (itemstack3.count <= slot.a()) { slot.set(itemstack3); playerinventory.setCarried(itemstack1); } } else if (itemstack1.id == itemstack3.id && itemstack3.getMaxStackSize() > 1 && (!itemstack1.usesData() || itemstack1.getData() == itemstack3.getData()) && ItemStack.equals(itemstack1, itemstack3)) { l = itemstack1.count; if (l > 0 && l + itemstack3.count <= itemstack3.getMaxStackSize()) { itemstack3.count += l; itemstack1 = slot.a(l); if (itemstack1.count == 0) { slot.set((ItemStack) null); } slot.a(entityhuman, playerinventory.getCarried()); } } } slot.e(); } } } else if (k == 2 && j >= 0 && j < 9) { slot = (Slot) this.c.get(i); if (slot.a(entityhuman)) { itemstack1 = playerinventory.getItem(j); boolean flag = itemstack1 == null || slot.inventory == playerinventory && slot.isAllowed(itemstack1); l = -1; if (!flag) { l = playerinventory.i(); flag |= l > -1; } if (slot.d() && flag) { itemstack2 = slot.getItem(); playerinventory.setItem(j, itemstack2); if ((slot.inventory != playerinventory || !slot.isAllowed(itemstack1)) && itemstack1 != null) { if (l > -1) { playerinventory.pickup(itemstack1); slot.set((ItemStack) null); slot.a(entityhuman, itemstack2); } } else { slot.set(itemstack1); slot.a(entityhuman, itemstack2); } } else if (!slot.d() && itemstack1 != null && slot.isAllowed(itemstack1)) { playerinventory.setItem(j, (ItemStack) null); slot.set(itemstack1); } } } else if (k == 3 && entityhuman.abilities.canInstantlyBuild && playerinventory.getCarried() == null && i >= 0) { slot = (Slot) this.c.get(i); if (slot != null && slot.d()) { itemstack1 = slot.getItem().cloneItemStack(); itemstack1.count = itemstack1.getMaxStackSize(); playerinventory.setCarried(itemstack1); } } return itemstack; }