Callbacks implemented
parent
8f4c369985
commit
7a32634ddc
11
README.md
11
README.md
|
@ -7,9 +7,11 @@ Teleport system for Minetest (yes, GUI aspect will be improved)
|
|||
<img src="https://content.minetest.net/uploads/pt68Gn7BjL.png"/>
|
||||
|
||||
### How to use it
|
||||
Look for the "Magic Compass" item in your inventory, put it in your hand and left click it to open the locations menu
|
||||
Look for the "Magic Compass" item in your creative inventory, put it in your hand and left click it to open the locations menu
|
||||
|
||||
### Customisation
|
||||
|
||||
##### Create new locations
|
||||
Every icon in the menu is a location. Locations must be declared in a .txt document inside the `locations` folder like so:
|
||||
```
|
||||
Red Forest -- the name you want to show in the menu when hovering the icon
|
||||
|
@ -22,7 +24,12 @@ HIDE -- (optional) whether to hide the icon to players who don't have the
|
|||
The file name is important too, as it must start with a number followed by an underscore like `5_whatever name.txt`.
|
||||
The number indicates the position of the associated item in the grid (which scales according to the highest number declared), and empty spaces are generated automatically if the numbers of the items don't represent a full sequence.
|
||||
|
||||
Also, don't forget to edit `config.txt` to suit your needs!
|
||||
##### Callbacks
|
||||
* `magic_compass.register_on_use(function(player, ID, item_name, pos))`: use it to run more checks BEFORE using the item. If it returns nil or false, the action is cancelled. If true, it keeps going
|
||||
* `magic_compass.register_on_after_use(function(player, ID, item_name, pos))`: use it to run additional code AFTER having been teleported
|
||||
|
||||
##### Graphic aspect
|
||||
Edit `config.txt` to suit your needs!
|
||||
|
||||
### Want to help?
|
||||
Feel free to:
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
-- I had no idea how to do it, so, uhm... this is how Minetest handles callbacks
|
||||
local function make_registration()
|
||||
local t = {}
|
||||
local registerfunc = function(func)
|
||||
t[#t+1] = func
|
||||
end
|
||||
return t, registerfunc
|
||||
end
|
||||
|
||||
magic_compass.registered_on_use, magic_compass.register_on_use = make_registration()
|
||||
magic_compass.registered_on_after_use, magic_compass.register_on_after_use = make_registration()
|
|
@ -1,4 +1,3 @@
|
|||
magic_compass = {}
|
||||
magic_compass.items = {}
|
||||
|
||||
local S = minetest.get_translator("magic_compass")
|
||||
|
|
6
init.lua
6
init.lua
|
@ -1,9 +1,11 @@
|
|||
local version = "1.2.0"
|
||||
magic_compass = {}
|
||||
local version = "1.3.0"
|
||||
|
||||
dofile(minetest.get_modpath("magic_compass") .. "/callbacks.lua")
|
||||
dofile(minetest.get_modpath("magic_compass") .. "/deserializer.lua")
|
||||
dofile(minetest.get_modpath("magic_compass") .. "/formspec.lua")
|
||||
dofile(minetest.get_modpath("magic_compass") .. "/items.lua")
|
||||
dofile(minetest.get_modpath("magic_compass") .. "/load_config.lua")
|
||||
dofile(minetest.get_modpath("magic_compass") .. "/player_manager.lua")
|
||||
|
||||
minetest.log("action", "[MAGIC_COMPASS] Mod initialised, running version " .. version)
|
||||
minetest.log("action", "[MAGIC COMPASS] Mod initialised, running version " .. version)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# version 1.2.0
|
||||
# version 1.3.0
|
||||
# author(s): Zughy
|
||||
# reviewer(s):
|
||||
# textdomain: magic_compass
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# version 1.2.0
|
||||
# version 1.3.0
|
||||
# author(s):
|
||||
# reviewer(s):
|
||||
# textdomain: magic_compass
|
||||
|
|
|
@ -34,12 +34,27 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||
})
|
||||
return end
|
||||
|
||||
-- se non passa gli eventuali callback, annullo
|
||||
for _, callback in ipairs(magic_compass.registered_on_use) do
|
||||
if not callback(player, ID, item.desc, item.pos) then
|
||||
minetest.sound_play("magiccompass_teleport_deny", {
|
||||
to_player = p_name
|
||||
})
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
-- teletrasporto
|
||||
player:set_pos(minetest.string_to_pos(item.pos))
|
||||
minetest.sound_play("magiccompass_teleport", {
|
||||
to_player = p_name
|
||||
})
|
||||
|
||||
-- eventuali callback dopo l'uso
|
||||
for _, callback in ipairs(magic_compass.registered_on_after_use) do
|
||||
callback(player, ID, item.desc, item.pos)
|
||||
end
|
||||
|
||||
-- eventuale cooldown
|
||||
if item.cooldown then
|
||||
|
||||
|
|
Loading…
Reference in New Issue