Search in sources :

Example 1 with IBauble

use of baubles.api.IBauble in project Witchworks by Um-Mitternacht.

the class ItemBauble method onItemRightClick.

@SuppressWarnings("deprecation")
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
    ItemStack toEquip = player.getHeldItem(hand).copy();
    toEquip.setCount(1);
    if (canEquip(toEquip, player)) {
        IInventory baubles = BaublesApi.getBaubles(player);
        for (int i = 0; i < baubles.getSizeInventory(); i++) {
            if (baubles.isItemValidForSlot(i, toEquip)) {
                ItemStack stackInSlot = baubles.getStackInSlot(i);
                if (stackInSlot.isEmpty() || ((IBauble) stackInSlot.getItem()).canUnequip(stackInSlot, player)) {
                    if (!world.isRemote) {
                        baubles.setInventorySlotContents(i, toEquip);
                        stackInSlot.shrink(1);
                    }
                    if (!stackInSlot.isEmpty()) {
                        ((IBauble) stackInSlot.getItem()).onUnequipped(stackInSlot, player);
                        return ActionResult.newResult(EnumActionResult.SUCCESS, stackInSlot.copy());
                    }
                    break;
                }
            }
        }
    }
    return ActionResult.newResult(EnumActionResult.PASS, player.getHeldItem(hand));
}
Also used : IInventory(net.minecraft.inventory.IInventory) IBauble(baubles.api.IBauble) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IBauble (baubles.api.IBauble)1 IInventory (net.minecraft.inventory.IInventory)1 ItemStack (net.minecraft.item.ItemStack)1