FallenMoonNetwork / CanaryMod

Server administration mod and API for Minecraft beta multiplayer server
http://canarymod.net
GNU Lesser General Public License v3.0
20 stars 14 forks source link

Inventory class issues (hasItem and removeItem methods) #76

Closed BluXDragon closed 11 years ago

BluXDragon commented 11 years ago

Inventory hasItem() and removeItem() methods should adhere to damage values.

It would also be nice if they adhered to enchantments, names, lore, and any (other) form of NBT tag, including metadata, but naturally the priority of that is much lower.

I'll outline an issue with the damage values; Hotbar Using plugin code to try and gather and remove the item in the third (highlighted) slot, it will attempt to remove an item from the first slot instead. What's more, if you try to obtain the item in slot 3 and only remove one of them, it will remove one of the items in the first slot, and set the damage value for the remaining items to zero.

In this example, I try to remove one bonemeal, but instead it removes one orange dye and turns the rest into an ink sack.

Item item = new Item(Item.Type.InkSack);
item.setDamage(15);
item.setAmount(1);
player.getInventory().remove(item);
player.getInventory().update();

The issue is similar when handling enchanted/special NBT'd items. If a player has two diamond swords, one enchanted in slot 1, one clean in slot 2, trying to remove the diamond sword in slot 2 will instead remove the enchanted one.