Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mt-mods/wield_events
Events for wield item switching
https://github.com/mt-mods/wield_events
Last synced: 8 days ago
JSON representation
Events for wield item switching
- Host: GitHub
- URL: https://github.com/mt-mods/wield_events
- Owner: mt-mods
- License: mit
- Created: 2023-06-21T15:26:57.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2023-10-28T09:33:04.000Z (about 1 year ago)
- Last Synced: 2024-11-08T17:13:27.934Z (2 months ago)
- Language: Lua
- Size: 116 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
Events for wield item switching
Provides callbacks for `on_select`, `on_step` and `on_deselect` on wielded items
![luacheck](https://github.com/mt-mods/technic/workflows/luacheck/badge.svg)
[![License](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
[![ContentDB](https://content.minetest.net/packages/mt-mods/wield_events/shields/downloads/)](https://content.minetest.net/packages/mt-mods/wield_events/)# Api
## Item parameter
```lua
minetest.register_tool("my_mod:my_tool", {
description = "My tool",
inventory_image = "my_mod.png",
stack_max = 1,
range = 0,
on_select = function(itemstack, player)
-- called when the player switches to the item
end,
on_step = function(itemstack, player)
-- called on every globalstep while the item is selected
end,
on_deselect = function(itemstack, player)
-- called when the player switches away from the item
end
})
```## Global callback
```lua
wield_events.register_on_select(function(itemstack, player)
-- called when the player switches any item
end)wield_events.register_on_step(function(itemstack, player)
-- called on every globalstep while any item is selected
end)wield_events.register_on_deselect(function(itemstack, player)
-- called when the player switches away from any item
end)
```# Demo
* `pick_and_place` https://github.com/BuckarooBanzay/pick_and_place/blob/master/place_tool.lua
# License
MIT