minetest mod.
api.txt | ||
async.lua | ||
depends.txt | ||
description.txt | ||
init.lua | ||
LICENSE | ||
mod.conf | ||
node_funcs.lua | ||
README.md | ||
register.lua |
extended_api
extended_api mod is a library pack. It adds two new node events and contains async functions.
Usage Async
- create a async instance.
async = extended_api.Async()
- set the priority of the async pool to high.
async.priority(50, 500)
- iterate from 1 to 50 and log the value i.
async.iterate(1, 50, function(i)
minetest.log(i)
end)
- run throught each element in a table.
local array = {"start", "text2", "text3", "text4", "text5", "end"}
async.foreach(array, function(k,v)
minetest.log(v)
end)
- async do while loop.
local c = 50
async.do_while(function() return c>0 end, function()
minetest.log(c)
c = c - 1
end)
- register a async globalstep. this one spams the chat with the word spam.
async.register_globalstep(function(dtime)
minetest.chat_send_all("spam")
end)
- chain task runs a group of functions from a table.
async.chain_task({
function(args)
args.count = 1
minetest.log(args.count)
return args
end,
function(args)
args.count = args.count + 1
minetest.log(args.count)
return args
end})
- adds a single function to the task queue. This is a sort of waiting list.
async.queue_task(function()
minetest.log("Hello World!")
end)
- Same as queue_task but the task does not go into a queue.
async.single_task(function()
minetest.log("Hello World!")
end)
New Node Events
- this covers both functions. I made this for a way to awake node timers without abms.
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,
})
New Registers
- register_playerloop iterates through all players online.
extended_api.register_playerloop(function(dtime, _, player)
-- Empty
end)
- register_step excutes the given function in one minetest globalstep.
extended_api.register_step(function(dtime)
minetest.chat_send_all("spam")
end)
- functions on_wield and on_wield_switch happen when a player wields a item.
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)