Search in sources :

Example 1 with IItemActivationListener

use of com.builtbroken.mc.api.items.listeners.IItemActivationListener in project Engine by VoltzEngine-Project.

the class ItemBase method doesSneakBypassUse.

@Override
public boolean doesSneakBypassUse(World world, int x, int y, int z, EntityPlayer player) {
    boolean clicked = false;
    ItemListenerIterator it = new ItemListenerIterator(this, "activation");
    while (it.hasNext()) {
        IItemEventListener next = it.next();
        if (next instanceof IItemActivationListener) {
            if (((IItemActivationListener) next).doesSneakBypassUse(world, x, y, z, player)) {
                clicked = true;
            }
        }
    }
    return clicked;
}
Also used : IItemEventListener(com.builtbroken.mc.api.items.listeners.IItemEventListener) IItemActivationListener(com.builtbroken.mc.api.items.listeners.IItemActivationListener) ItemListenerIterator(com.builtbroken.mc.prefab.items.listeners.ItemListenerIterator)

Example 2 with IItemActivationListener

use of com.builtbroken.mc.api.items.listeners.IItemActivationListener in project Engine by VoltzEngine-Project.

the class ItemBase method onItemRightClick.

@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
    try {
        if (stack != null) {
            ItemStack copy = stack.copy();
            ItemListenerIterator it = new ItemListenerIterator(this, "activation");
            while (it.hasNext()) {
                IItemEventListener next = it.next();
                if (next instanceof IItemActivationListener) {
                    copy = ((IItemActivationListener) next).onItemRightClick(copy, world, player);
                }
            }
            return copy;
        }
    } catch (Exception e) {
        player.addChatComponentMessage(new ChatComponentText(Colors.RED.code + "Unexpected error using item, see logs for error details"));
        Engine.logger().error("ItemBase: Unexpected error triggering listeners during onItemRightClick(" + stack + ", " + player + ", " + world + ")");
    }
    return stack;
}
Also used : IItemEventListener(com.builtbroken.mc.api.items.listeners.IItemEventListener) IItemActivationListener(com.builtbroken.mc.api.items.listeners.IItemActivationListener) ItemListenerIterator(com.builtbroken.mc.prefab.items.listeners.ItemListenerIterator) ItemStack(net.minecraft.item.ItemStack) ChatComponentText(net.minecraft.util.ChatComponentText)

Example 3 with IItemActivationListener

use of com.builtbroken.mc.api.items.listeners.IItemActivationListener in project Engine by VoltzEngine-Project.

the class ItemBase method onItemUse.

@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hit_x, float hit_y, float hit_z) {
    try {
        if (stack != null) {
            boolean clicked = false;
            ItemListenerIterator it = new ItemListenerIterator(this, "activation");
            while (it.hasNext()) {
                IItemEventListener next = it.next();
                if (next instanceof IItemActivationListener) {
                    if (((IItemActivationListener) next).onItemUse(stack, player, world, x, y, z, side, hit_x, hit_y, hit_z)) {
                        clicked = true;
                    }
                }
            }
            return clicked;
        }
    } catch (Exception e) {
        player.addChatComponentMessage(new ChatComponentText(Colors.RED.code + "Unexpected error using item, see logs for error details"));
        Engine.logger().error("ItemBase: Unexpected error triggering listeners during onItemUse(" + stack + ", " + player + ", " + world + ", " + x + ", " + y + ", " + z + ", " + side, e);
    }
    return false;
}
Also used : IItemEventListener(com.builtbroken.mc.api.items.listeners.IItemEventListener) IItemActivationListener(com.builtbroken.mc.api.items.listeners.IItemActivationListener) ItemListenerIterator(com.builtbroken.mc.prefab.items.listeners.ItemListenerIterator) ChatComponentText(net.minecraft.util.ChatComponentText)

Example 4 with IItemActivationListener

use of com.builtbroken.mc.api.items.listeners.IItemActivationListener in project Engine by VoltzEngine-Project.

the class ItemBase method onItemUseFirst.

@Override
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hit_x, float hit_y, float hit_z) {
    try {
        if (stack != null) {
            boolean clicked = false;
            ItemListenerIterator it = new ItemListenerIterator(this, "activation");
            while (it.hasNext()) {
                IItemEventListener next = it.next();
                if (next instanceof IItemActivationListener) {
                    clicked = ((IItemActivationListener) next).onItemUseFirst(stack, player, world, x, y, z, side, hit_x, hit_y, hit_z);
                }
            }
            return clicked;
        }
    } catch (Exception e) {
        player.addChatComponentMessage(new ChatComponentText(Colors.RED.code + "Unexpected error using item, see logs for error details"));
        Engine.logger().error("ItemBase: Unexpected error triggering listeners during onItemUseFirst(" + stack + ", " + player + ", " + world + ", " + x + ", " + y + ", " + z + ", " + side, e);
    }
    return false;
}
Also used : IItemEventListener(com.builtbroken.mc.api.items.listeners.IItemEventListener) IItemActivationListener(com.builtbroken.mc.api.items.listeners.IItemActivationListener) ItemListenerIterator(com.builtbroken.mc.prefab.items.listeners.ItemListenerIterator) ChatComponentText(net.minecraft.util.ChatComponentText)

Aggregations

IItemActivationListener (com.builtbroken.mc.api.items.listeners.IItemActivationListener)4 IItemEventListener (com.builtbroken.mc.api.items.listeners.IItemEventListener)4 ItemListenerIterator (com.builtbroken.mc.prefab.items.listeners.ItemListenerIterator)4 ChatComponentText (net.minecraft.util.ChatComponentText)3 ItemStack (net.minecraft.item.ItemStack)1