2018-11-09 22:54:41 +01:00
|
|
|
extended_api
|
|
|
|
===========
|
|
|
|
|
2018-11-10 14:08:56 +01:00
|
|
|
extended_api mod is a library pack.
|
2018-11-09 22:54:41 +01:00
|
|
|
It adds two new node events and contains async functions.
|
|
|
|
|
|
|
|
Usage Async
|
|
|
|
===========
|
2018-12-26 06:08:44 +01:00
|
|
|
1. create a async instance.
|
2018-11-09 22:54:41 +01:00
|
|
|
```lua
|
2018-12-26 06:08:44 +01:00
|
|
|
async = extended_api.Async()
|
2018-11-09 22:54:41 +01:00
|
|
|
```
|
|
|
|
2. set the priority of the async pool to high.
|
|
|
|
```lua
|
2018-12-26 06:08:44 +01:00
|
|
|
async.priority(50, 500)
|
2018-11-09 22:54:41 +01:00
|
|
|
```
|
|
|
|
3. iterate from 1 to 50 and log the value i.
|
|
|
|
```lua
|
2018-12-26 06:08:44 +01:00
|
|
|
async.iterate(1, 50, function(i)
|
2018-11-09 22:54:41 +01:00
|
|
|
minetest.log(i)
|
|
|
|
end)
|
|
|
|
```
|
|
|
|
4. run throught each element in a table.
|
|
|
|
```lua
|
2018-12-26 06:08:44 +01:00
|
|
|
local array = {"start", "text2", "text3", "text4", "text5", "end"}
|
|
|
|
async.foreach(array, function(k,v)
|
2018-11-09 22:54:41 +01:00
|
|
|
minetest.log(v)
|
|
|
|
end)
|
|
|
|
```
|
|
|
|
5. async do while loop.
|
|
|
|
```lua
|
|
|
|
local c = 50
|
2018-12-26 06:08:44 +01:00
|
|
|
async.do_while(function() return c>0 end, function()
|
2018-11-09 22:54:41 +01:00
|
|
|
minetest.log(c)
|
|
|
|
c = c - 1
|
|
|
|
end)
|
|
|
|
```
|
|
|
|
6. register a async globalstep. this one spams the chat with the word spam.
|
|
|
|
```lua
|
2018-12-26 06:08:44 +01:00
|
|
|
async.register_globalstep(function(dtime)
|
2018-11-09 22:54:41 +01:00
|
|
|
minetest.chat_send_all("spam")
|
|
|
|
end)
|
|
|
|
```
|
|
|
|
7. chain task runs a group of functions from a table.
|
|
|
|
```lua
|
2018-12-26 06:08:44 +01:00
|
|
|
async.chain_task({
|
2018-11-09 22:54:41 +01:00
|
|
|
function(args)
|
2018-11-10 14:08:56 +01:00
|
|
|
args.count = 1
|
|
|
|
minetest.log(args.count)
|
|
|
|
return args
|
2018-11-09 22:54:41 +01:00
|
|
|
end,
|
|
|
|
function(args)
|
2018-11-10 14:08:56 +01:00
|
|
|
args.count = args.count + 1
|
|
|
|
minetest.log(args.count)
|
|
|
|
return args
|
2018-11-09 23:04:48 +01:00
|
|
|
end})
|
2018-11-09 22:54:41 +01:00
|
|
|
```
|
|
|
|
8. adds a single function to the task queue. This is a sort of waiting list.
|
|
|
|
```lua
|
2018-12-26 06:08:44 +01:00
|
|
|
async.queue_task(function()
|
2018-11-09 23:04:48 +01:00
|
|
|
minetest.log("Hello World!")
|
|
|
|
end)
|
2018-11-09 22:54:41 +01:00
|
|
|
```
|
2018-12-26 06:08:44 +01:00
|
|
|
9. Same as queue_task but the task does not go into a queue.
|
|
|
|
```lua
|
|
|
|
async.single_task(function()
|
|
|
|
minetest.log("Hello World!")
|
|
|
|
end)
|
|
|
|
```
|
|
|
|
New Node Events
|
2018-11-09 22:54:41 +01:00
|
|
|
===========
|
|
|
|
1. this covers both functions. I made this for a way to awake node timers without abms.
|
|
|
|
```lua
|
|
|
|
minetest.register_node("default:stone", {
|
|
|
|
description = "Stone",
|
|
|
|
tiles = {"default_stone.png"},
|
|
|
|
groups = {cracky = 3, stone = 1},
|
|
|
|
drop = 'default:cobble',
|
|
|
|
legacy_mineral = true,
|
|
|
|
sounds = default.node_sound_stone_defaults(),
|
|
|
|
on_construct_node_near_by = function(pos,other_pos,name)
|
|
|
|
if name == "tnt:tnt" then
|
|
|
|
minetest.chat_send_all("Do not place tnt near me thank you!")
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
on_destruct_node_near_by = function(pos,other_pos,name)
|
|
|
|
if name == "default:dirt" then
|
|
|
|
minetest.chat_send_all("I hate dirt too!")
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|
2018-12-26 06:08:44 +01:00
|
|
|
```
|
|
|
|
New Registers
|
|
|
|
===========
|
|
|
|
1. register_playerloop iterates through all players online.
|
|
|
|
```lua
|
|
|
|
extended_api.register_playerloop(function(dtime, _, player)
|
|
|
|
-- Empty
|
|
|
|
end)
|
|
|
|
```
|
|
|
|
2. register_step excutes the given function in one minetest globalstep.
|
|
|
|
```lua
|
|
|
|
extended_api.register_step(function(dtime)
|
|
|
|
minetest.chat_send_all("spam")
|
|
|
|
end)
|
|
|
|
```
|
|
|
|
3. functions on_wield and on_wield_switch happen when a player wields a item.
|
|
|
|
```lua
|
|
|
|
extended_api.register_on_wield("default:torch", function(item, itemname, player)
|
|
|
|
minetest.chat_send_all("You are wielding " .. itemname)
|
|
|
|
end)
|
|
|
|
extended_api.register_on_wield_switch("default:torch", function(item, itemname, player)
|
|
|
|
minetest.chat_send_all("You un-wielded " .. itemname)
|
|
|
|
end)
|
|
|
|
```
|