Wand Trigger System

The wand trigger system allows wands to interact with blocks in the world without requiring the blocks to implement IWandable. This is useful for adding wand interactions to third-party blocks or vanilla Minecraft blocks.

WandTriggerRegistry

thaumcraft.api.wands.WandTriggerRegistry

Central registry for wand-to-block trigger mappings. Triggers are invoked via the wand’s onItemUseFirst method.

Registration

public static void registerWandBlockTrigger(
    IWandTriggerManager manager,
    int event,
    Block block,
    int meta,
    String modid
)
Parameter Description
manager The IWandTriggerManager that handles the trigger.
event A logical event ID passed to the manager’s performTrigger. Use to differentiate multiple trigger types on the same block.
block The target block.
meta Specific metadata value. Pass -1 as a wildcard for all metadata values.
modid Your mod’s unique identifier. Use to avoid conflicts with other mods triggering the same block.

Legacy Registration

public static void registerWandBlockTrigger(
    IWandTriggerManager manager,
    int event,
    Block block,
    int meta
)

Uses the "default" modid namespace. Provided for legacy compatibility.

Checking for Triggers

public static boolean hasTrigger(Block block, int meta)
public static boolean hasTrigger(Block block, int meta, String modid)

Returns true if a trigger is registered for the given block and metadata.

Performing Triggers

public static boolean performTrigger(
    World world,
    ItemStack wand,
    EntityPlayer player,
    int x, int y, int z,
    int side,
    Block block,
    int meta
)

public static boolean performTrigger(
    World world,
    ItemStack wand,
    EntityPlayer player,
    int x, int y, int z,
    int side,
    Block block,
    int meta,
    String modid
)

Called by the wand’s onItemUseFirst method. Looks up the registered manager and calls its performTrigger. Returns true if a trigger was found and consumed the interaction.


IWandTriggerManager

thaumcraft.api.wands.IWandTriggerManager

Interface that must be implemented by trigger handler classes.

public interface IWandTriggerManager {
    boolean performTrigger(
        World world,
        ItemStack wand,
        EntityPlayer player,
        int x, int y, int z,
        int side,
        int event
    );
}
Parameter Description
world The world where the interaction occurred.
wand The wand ItemStack being used.
player The player wielding the wand.
x, y, z Coordinates of the targeted block.
side The face of the block that was clicked (ForgeDirection ordinal).
event The event ID passed during registration.

Return true to consume the interaction (prevent default behavior), false to allow normal block interaction to proceed.


IWandable

thaumcraft.api.wands.IWandable

Interface for TileEntities that wands can interact with. This is a separate mechanism from WandTriggerRegistry — implemented directly on tile entities rather than registered globally.

public interface IWandable {
    int onWandRightClick(
        World world,
        ItemStack wandstack,
        EntityPlayer player,
        int x, int y, int z,
        int side,
        int md
    );

    ItemStack onWandRightClick(
        World world,
        ItemStack wandstack,
        EntityPlayer player
    );

    void onUsingWandTick(
        ItemStack wandstack,
        EntityPlayer player,
        int count
    );

    void onWandStoppedUsing(
        ItemStack wandstack,
        World world,
        EntityPlayer player,
        int count
    );
}

Methods

Method Description
onWandRightClick(World, ItemStack, EntityPlayer, x, y, z, side, md) Called when right-clicking a block face. Return metadata value or -1 to use the block’s current metadata.
onWandRightClick(World, ItemStack, EntityPlayer) Called on the tile entity when right-clicking with the wand. Return a modified ItemStack (or the original).
onUsingWandTick(ItemStack, EntityPlayer, count) Called every tick while the player is holding right-click with the wand.
onWandStoppedUsing(ItemStack, World, EntityPlayer, count) Called when the player stops holding right-click.

Usage

Add implements IWandable to your TileEntity class and implement the methods. The wand will automatically detect and call these methods when a player right-clicks the tile entity with a casting wand.


Comparison

Feature WandTriggerRegistry IWandable
Target Any Block (registered globally) TileEntity only
Registration Static call in mod init Implement interface on TileEntity
Mod control External mod registers triggers Block owner implements directly
Use case Third-party/vanilla blocks Custom mod blocks
Conflicts Possible (solved via modid namespacing) Not applicable

Example: Registering a Trigger

// In your mod's init
public static IWandTriggerManager myTriggerHandler = new IWandTriggerManager() {
    @Override
    public boolean performTrigger(World world, ItemStack wand, EntityPlayer player,
            int x, int y, int z, int side, int event) {
        if (event == 0) {
            // Crafting event: do something with the bookshelf
            return true;
        }
        return false;
    }
};

// Register for all metadata values of the bookshelf block
WandTriggerRegistry.registerWandBlockTrigger(
    myTriggerHandler,
    0,                  // event ID
    Blocks.bookshelf,
    -1,                 // wildcard metadata
    "mymodid"           // your mod's modid
);