From f3fc61923ed87e964a3023ea2db2b2cbe9f34877 Mon Sep 17 00:00:00 2001 From: Coder12a <38924418+Coder12a@users.noreply.github.com> Date: Mon, 29 Oct 2018 16:32:52 -0500 Subject: [PATCH] Add files --- README.md | 5 +- api.txt | 4 + depends.txt | 0 description.txt | 1 + init.lua | 202 ++++++++++++++++++++++++++++++++++++++++++++++++ mod.conf | 1 + 6 files changed, 212 insertions(+), 1 deletion(-) create mode 100644 api.txt create mode 100644 depends.txt create mode 100644 description.txt create mode 100644 init.lua create mode 100644 mod.conf diff --git a/README.md b/README.md index 5144dfd..57616e5 100644 --- a/README.md +++ b/README.md @@ -1 +1,4 @@ -# extended_api \ No newline at end of file +# extended_api +mod for minetest + +This mod adds more functions and features to the minetest api. \ No newline at end of file diff --git a/api.txt b/api.txt new file mode 100644 index 0000000..691d3e3 --- /dev/null +++ b/api.txt @@ -0,0 +1,4 @@ +Function happens when a nodes constructer function is ran near by. +on_construct_node_near_by(pos,other_pos) +Function happens when a nodes destructer function is ran near by. +on_destruct_node_near_by(pos,other_pos) \ No newline at end of file diff --git a/depends.txt b/depends.txt new file mode 100644 index 0000000..e69de29 diff --git a/description.txt b/description.txt new file mode 100644 index 0000000..0c22f63 --- /dev/null +++ b/description.txt @@ -0,0 +1 @@ +This mod adds more functions and features to the minetest api. \ No newline at end of file diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..c64ddcd --- /dev/null +++ b/init.lua @@ -0,0 +1,202 @@ +-- on_construct_node_near_by(pos,constructed_pos) +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() + 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) + 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() + 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) + end + else + node.exa_old_on_construct(lpos) + end + end + end + end +end +-- End + +-- on_destruct_node_near_by(pos,destructed_pos) +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() + 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) + 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() + 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) + 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) + 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) + 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_con + minetest.register_node(":"..n,cn) + end +end) \ No newline at end of file diff --git a/mod.conf b/mod.conf new file mode 100644 index 0000000..0367cf5 --- /dev/null +++ b/mod.conf @@ -0,0 +1 @@ +name = extended_api \ No newline at end of file