Vanilla interaction manager: attacks, block/entity/item interactions, block breaking and screen-handler clicks. Goes through vanilla client paths — correct packets, swing timers and sequence numbers. For raw packets see Packets.
Hands: "main" / "off" (default "main"). Sides: "up" · "down" · "north" ·
"south" · "east" · "west" (default "up"). Interactions return
"success" · "fail" · "pass".
| Function | What it does |
|---|---|
interaction.gamemode() |
Current game mode, e.g. "survival" |
interaction.attack(entity_id) |
Attacks an entity (main-hand swing) |
interaction.interact(entity_id[, hand]) |
Right-clicks an entity |
interaction.use_item([hand]) |
Uses the held item |
interaction.attack_with_piercing_weapon([hand]) |
Spear stab/lunge; false when not holding one |
interaction.use_block(pos[, side[, hand]]) |
Right-clicks a block (aims at center) |
interaction.attack_block(pos[, side]) |
Starts breaking a block |
interaction.update_breaking(pos[, side]) |
Continues breaking — call every tick while holding |
interaction.cancel_breaking() |
Aborts current breaking |
interaction.break_block(pos) |
Finishes breaking instantly (creative / fully cracked) |
interaction.breaking() |
true while a block is being broken |
interaction.breaking_progress() |
Breaking stage 0–10, -1 when idle |
interaction.stop_using() |
Releases bow / stops eating / lowers shield |
interaction.swing([hand]) |
Swings an arm (animation + packet) |
interaction.sync_id() |
Sync id of the open screen handler (0 = inventory) |
interaction.click_slot(sync_id, slot, button[, action]) |
Clicks a slot like a mouse click |
interaction.click_button(sync_id, button) |
Clicks a screen-handler button (stonecutter, loom, …) |
interaction.pick_block(pos[, include_data]) |
Pick-block |
interaction.pick_entity(entity_id[, include_data]) |
Pick-block on an entity |
click_slot actions: "pickup" (default), "quick_move" (shift-click), "swap"
(button = hotbar 0–8, 40 = offhand), "clone", "throw", "quick_craft",
"pickup_all".
To close a container screen, use screen.close().
module:event("pre_interaction", function()
for _, p in ipairs(world:players() or {}) do
if not p:is_self() and p:distance() < 3 then
interaction.attack(p:id())
break
end
end
end)