Remove: all extend_api names from repo

This commit is contained in:
Coder12a 2019-05-13 14:22:21 -05:00
parent 89ea46c854
commit bc3125b34a
9 changed files with 8 additions and 415 deletions

View File

@ -1,14 +1,14 @@
extended_api
async
===========
extended_api mod is a library pack.
async mod is a library pack.
It adds two new node events and contains async functions.
Usage Async
===========
1. create a async instance.
```lua
async = extended_api.Async()
async = async.Async()
```
2. set the priority of the async pool to high.
```lua
@ -67,49 +67,3 @@ async.single_task(function()
minetest.log("Hello World!")
end)
```
New Node Events
===========
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,
})
```
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)
```

39
api.txt
View File

@ -1,39 +0,0 @@
-- node_funcs
-- Function happens when a node's constructer function is ran near by.
on_construct_node_near_by(pos,other_pos,name)
-- Function happens when a node's destructer function is ran near by.
on_destruct_node_near_by(pos,other_pos,name)
-- async
-- Create's a async pool.
extended_api.Async.create_async_pool() --- return pool
-- Set the priority of the given async pool.
-- resting is the delay between resuming threads.
-- maxtime is how long a thread will work before yield.
extended_api.Async.priority(pool,resting,maxtime)
-- Async for loop.
-- from is the starting value for the loop.
-- to is the ending value to will break the loop.
-- func(i) is the function that is ran in the for loop. func can break the loop if it returns false.
-- callback() function is ran when the for loop ends. callback can be nil.
extended_api.Async.iterate(pool,from,to,func,callback)
-- Async foreach loop.
-- array is the list to loop throught.
-- func(k,v) is the function that is ran in the foreach loop. func can break the loop if it returns false.
-- callback() function is ran when the foreach loop ends. callback can be nil.
extended_api.Async.foreach(pool,array, func, callback)
-- Async do while loop.
-- condition_func() returns the condition.
-- func() is the function that is ran in the do while loop. func can break the loop if it returns false.
-- callback() function is ran when the do while loop ends. callback can be nil.
extended_api.Async.do_while(pool,condition_func, func, callback)
-- Async globalstep loop. this can never be shutdown like in the minetest version. happens every 0.05 seconds.
-- func(dtime) is the function that is ran in the globalstep.
extended_api.Async.register_globalstep(pool,func)
-- Async chain task.
-- tasks is a table of functions that ran in order.
-- callback(arg) function is ran when the chain_task ends. callback can be nil.
extended_api.Async.chain_task(pool,tasks,callback)
-- Async task queue.
-- func is a single function that gets added to the queue list.
-- callback(arg) function is ran when the queue_task ends. callback can be nil.
extended_api.Async.queue_task(pool,func,callback)

View File

@ -1,4 +1,4 @@
function extended_api.Async()
function async.Async()
local self = {}
self.task_queue = {}

View File

View File

@ -1 +0,0 @@
This mod is a library that adds more functions and features.

View File

@ -1,7 +1,5 @@
modpath = minetest.get_modpath("extended_api")
modpath = minetest.get_modpath("async")
extended_api = {}
async = {}
dofile(string.format("%s/node_funcs.lua", modpath))
dofile(string.format("%s/async.lua", modpath))
dofile(string.format("%s/register.lua", modpath))

View File

@ -1 +1,2 @@
name = extended_api
name = async
description = This mod is a library that adds asynchronous functions and features.

View File

@ -1,216 +0,0 @@
local function on_construct_override(pos)
local lpos = pos
local pos1 = {x=lpos.x-1,y=lpos.y-1,z=lpos.z-1}
local pos2 = {x=lpos.x+1,y=lpos.y+1,z=lpos.z+1}
local vm = minetest.get_voxel_manip()
local emin, emax = vm:read_from_map(pos1, pos2)
local a = VoxelArea:new{
MinEdge = emin,
MaxEdge = emax
}
local nx = lpos.x
local ny = lpos.y
local nz = lpos.z
local n1x = pos1.x
local n1y = pos1.y
local n1z = pos1.z
local n2x = pos2.x
local n2y = pos2.y
local n2z = pos2.z
local data = vm:get_data()
local m_vi = a:index(nx, ny, nz)
local myname = minetest.get_name_from_content_id(data[m_vi])
for z = n1z, n2z do
for y = n1y, n2y do
for x = n1x, n2x do
if x ~= nx or y ~= ny or z ~= nz then
local vi = a:index(x, y, z)
local name = minetest.get_name_from_content_id(data[vi])
local node = minetest.registered_nodes[name]
if node.on_construct_node_near_by then
node.on_construct_node_near_by({x=x,y=y,z=z},lpos,myname)
end
end
end
end
end
end
local function on_construct_override2(pos)
local lpos = pos
local pos1 = {x=lpos.x-1,y=lpos.y-1,z=lpos.z-1}
local pos2 = {x=lpos.x+1,y=lpos.y+1,z=lpos.z+1}
local vm = minetest.get_voxel_manip()
local emin, emax = vm:read_from_map(pos1, pos2)
local a = VoxelArea:new{
MinEdge = emin,
MaxEdge = emax
}
local nx = lpos.x
local ny = lpos.y
local nz = lpos.z
local n1x = pos1.x
local n1y = pos1.y
local n1z = pos1.z
local n2x = pos2.x
local n2y = pos2.y
local n2z = pos2.z
local data = vm:get_data()
local m_vi = a:index(nx, ny, nz)
local myname = minetest.get_name_from_content_id(data[m_vi])
for z = n1z, n2z do
for y = n1y, n2y do
for x = n1x, n2x do
local vi = a:index(x, y, z)
local name = minetest.get_name_from_content_id(data[vi])
local node = minetest.registered_nodes[name]
if x ~= nx or y ~= ny or z ~= nz then
if node.on_construct_node_near_by then
node.on_construct_node_near_by({x=x,y=y,z=z},lpos,myname)
end
else
node.exa_old_on_construct(lpos)
end
end
end
end
end
-- End
local function on_destruct_override(pos)
local lpos = pos
local pos1 = {x=lpos.x-1,y=lpos.y-1,z=lpos.z-1}
local pos2 = {x=lpos.x+1,y=lpos.y+1,z=lpos.z+1}
local vm = minetest.get_voxel_manip()
local emin, emax = vm:read_from_map(pos1, pos2)
local a = VoxelArea:new{
MinEdge = emin,
MaxEdge = emax
}
local nx = lpos.x
local ny = lpos.y
local nz = lpos.z
local n1x = pos1.x
local n1y = pos1.y
local n1z = pos1.z
local n2x = pos2.x
local n2y = pos2.y
local n2z = pos2.z
local data = vm:get_data()
local m_vi = a:index(nx, ny, nz)
local myname = minetest.get_name_from_content_id(data[m_vi])
for z = n1z, n2z do
for y = n1y, n2y do
for x = n1x, n2x do
if x ~= nx or y ~= ny or z ~= nz then
local vi = a:index(x, y, z)
local name = minetest.get_name_from_content_id(data[vi])
local node = minetest.registered_nodes[name]
if node.on_destruct_node_near_by then
node.on_destruct_node_near_by({x=x,y=y,z=z},lpos,myname)
end
end
end
end
end
end
local function on_destruct_override2(pos)
local lpos = pos
local pos1 = {x=lpos.x-1,y=lpos.y-1,z=lpos.z-1}
local pos2 = {x=lpos.x+1,y=lpos.y+1,z=lpos.z+1}
local vm = minetest.get_voxel_manip()
local emin, emax = vm:read_from_map(pos1, pos2)
local a = VoxelArea:new{
MinEdge = emin,
MaxEdge = emax
}
local nx = lpos.x
local ny = lpos.y
local nz = lpos.z
local n1x = pos1.x
local n1y = pos1.y
local n1z = pos1.z
local n2x = pos2.x
local n2y = pos2.y
local n2z = pos2.z
local data = vm:get_data()
local m_vi = a:index(nx, ny, nz)
local myname = minetest.get_name_from_content_id(data[m_vi])
for z = n1z, n2z do
for y = n1y, n2y do
for x = n1x, n2x do
local vi = a:index(x, y, z)
local name = minetest.get_name_from_content_id(data[vi])
local node = minetest.registered_nodes[name]
if x ~= nx or y ~= ny or z ~= nz then
if node.on_destruct_node_near_by then
node.on_destruct_node_near_by({x=x,y=y,z=z},lpos,myname)
end
else
node.exa_old_on_destruct(lpos)
end
end
end
end
end
-- End
minetest.after(0,
function()
for n, d in pairs(minetest.registered_nodes) do
local cn = {}
for k,v in pairs(minetest.registered_nodes[n]) do cn[k] = v end
-- on_construct_node_near_by(pos,other_pos,name)
local on_con = cn.on_construct
if on_con then
cn.exa_old_on_construct = on_con
on_con = on_construct_override2
else
on_con = on_construct_override
end
cn.on_construct = on_con
-- on_destruct_node_near_by(pos,other_pos,name)
local on_dis = cn.on_destruct
if on_dis then
cn.exa_old_on_destruct = on_dis
on_dis = on_destruct_override2
else
on_dis = on_destruct_override
end
cn.on_destruct = on_dis
minetest.register_node(":"..n,cn)
end
end)

View File

@ -1,104 +0,0 @@
extended_api.p_loop = {}
extended_api.step = {}
local wield_list = {}
local wield_switch_list = {}
minetest.register_globalstep(function(dtime)
local a1 = extended_api.p_loop
local a2 = extended_api.step
local count1 = #a1
for _, player in pairs(minetest.get_connected_players()) do
for i=1, count1 do
a1[i](dtime, _, player)
end
end
local count2 = #a2
for i=1, count2 do
a2[i](dtime)
end
end)
function extended_api.register_playerloop(func)
table.insert(extended_api.p_loop, func)
end
function extended_api.register_step(func)
table.insert(extended_api.step, func)
end
function extended_api.register_on_wield(itemname, func)
if wield_list[itemname] then
local old = wield_list[itemname]
wield_list[itemname] = function(item, itemname, player)
func(item, itemname, player)
old(item, itemname, player)
end
else
wield_list[itemname] = func
end
end
function extended_api.register_on_wield_switch(itemname, func)
if wield_switch_list[itemname] then
local old = wield_switch_list[itemname]
wield_switch_list[itemname] = function(item, itemname, player)
func(item, itemname, player)
old(item, itemname, player)
end
else
wield_switch_list[itemname] = func
end
end
local wield_timer = 0
local wield_limit = 0.2
local players = {}
local function create_wield_step()
extended_api.register_playerloop(function(dtime, _, player)
if wield_timer < wield_limit then
return
end
local item = player:get_wielded_item()
local item_name = item:get_name()
local pname = player:get_player_name()
local ply = players[pname]
if not ply then
players[pname] = item
local wlf = wield_list[item_name]
if wlf then
wlf(item, item_name, player)
end
elseif ply:get_name() ~= item_name then
local old = ply:get_name()
players[pname] = item
local wlf = wield_switch_list[old]
if wlf then
wlf(item, old, player)
end
wlf = wield_list[item_name]
if wlf then
wlf(item, item_name, player)
end
end
end)
extended_api.register_step(function(dtime)
if wield_timer < wield_limit then
wield_timer = wield_timer + dtime
return
else
wield_timer = 0
end
end)
end
minetest.register_on_leaveplayer(function(player)
players[player:get_player_name()] = nil
end)
create_wield_step()