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

The parameter "Item itemInHand" on hooks that have it does not work properly #81

Closed BluXDragon closed 11 years ago

BluXDragon commented 11 years ago

The best I can explain this is via examples. Take onItemUse for example;

https://github.com/FallenMoonNetwork/CanaryMod/blob/crow/src/PluginListener.java#L629

There we can see the variable "itemInHand", which in this case is the item used.

Here is the most recent code that has failed with this item;

    public boolean onItemUse(Player player, Block placed, Block clicked, Item itemInHand){
        player.getInventory().setSlot(null, itemInHand.getSlot()); //this clears the slot
        player.getInventory().update();
        return false;
    }

The code did absolutely nothing. But I have been using a fix that makes it function as intented;

    public boolean onItemUse(Player player, Block placed, Block clicked, Item itemInHandDoNotUse){
        Item itemInHand = player.getItemStackInHand();
        player.getInventory().setSlot(null, itemInHand.getSlot()); //this clears the slot
        player.getInventory().update();
        return false;
    }

See what I did there? Simply obtaining the item via getItemStackInHand results in the removal code working just fine, when it should have been already.

WWOL commented 11 years ago

Looking into it. Edit: Seams to be because the slot isn't set, looking for a way to do that now.

WWOL

BluXDragon commented 11 years ago

No, I don't think so. I've been doing this workaround for a while now, I only just came up with a good example.

gregcarlin commented 11 years ago

@WWOL Couldn't you just use player.getItemInHand() when you call the hook?

WWOL commented 11 years ago

Probably the best way actually, I was just adding a slot argument.

WWOL

BluXDragon commented 11 years ago

player.getItemStackInHand(), yes. ItemInHand just gets the ID

gregcarlin commented 11 years ago

@BluXDragon That's what I meant :P

BluXDragon commented 11 years ago

I feel I should point out that I said "on hooks that have it", not just onItemUse. So this includes BLOCK_PLACE, BLOCK_RIGHTCLICK and ENTITY_RIGHTCLICK. Maybe others I missed.