Added Function to scaffolding

wooden platform can be used on iron scaffolding
Cleaned Up Code
This commit is contained in:
Infinatum 2017-01-11 17:58:37 -01:00
förälder 0154a67673
incheckning 2ec270e1a1
2 ändrade filer med 107 tillägg och 237 borttagningar

Visa fil

@ -1,81 +1,4 @@
scaffolding_nodenames={"scaffolding:scaffolding","scaffolding:iron_scaffolding"}
minetest.register_on_dignode(function(pos, node)
local i=1
while scaffolding_nodenames[i]~=nil do
if node.name==scaffolding_nodenames[i] then
np={x=pos.x, y=pos.y+1, z=pos.z}
while minetest.env:get_node(np).name==scaffolding_nodenames[i] do
minetest.env:remove_node(np)
minetest.env:add_item(np, scaffolding_nodenames[i])
np={x=np.x, y=np.y+1, z=np.z}
end
end
i=i+1
end
end)
iron_scaffolding_nodenames={"scaffolding:platform","scaffolding:iron_platform"}
minetest.register_on_dignode(function(pos, node)
local i=1
while iron_scaffolding_nodenames[i]~=nil do
if node.name==iron_scaffolding_nodenames[i] then
np={x=pos.x, y=pos.y, z=pos.z+1}
while minetest.env:get_node(np).name==iron_scaffolding_nodenames[i] do
minetest.env:remove_node(np)
minetest.env:add_item(np, iron_scaffolding_nodenames[i])
np={x=np.x, y=np.y, z=np.z+1}
end
end
i=i+1
end
end)
minetest.register_on_dignode(function(pos, node)
local i=1
while iron_scaffolding_nodenames[i]~=nil do
if node.name==iron_scaffolding_nodenames[i] then
np={x=pos.x, y=pos.y, z=pos.z-1}
while minetest.env:get_node(np).name==iron_scaffolding_nodenames[i] do
minetest.env:remove_node(np)
minetest.env:add_item(np, iron_scaffolding_nodenames[i])
np={x=np.x, y=np.y, z=np.z-1}
end
end
i=i-1
end
end)
minetest.register_on_dignode(function(pos, node)
local i=1
while iron_scaffolding_nodenames[i]~=nil do
if node.name==iron_scaffolding_nodenames[i] then
np={x=pos.x+1, y=pos.y, z=pos.z}
while minetest.env:get_node(np).name==iron_scaffolding_nodenames[i] do
minetest.env:remove_node(np)
minetest.env:add_item(np, iron_scaffolding_nodenames[i])
np={x=np.x+1, y=np.y, z=np.z}
end
end
i=i+1
end
end)
minetest.register_on_dignode(function(pos, node)
local i=1
while iron_scaffolding_nodenames[i]~=nil do
if node.name==iron_scaffolding_nodenames[i] then
np={x=pos.x-1, y=pos.y, z=pos.z}
while minetest.env:get_node(np).name==iron_scaffolding_nodenames[i] do
minetest.env:remove_node(np)
minetest.env:add_item(np, iron_scaffolding_nodenames[i])
np={x=np.x-1, y=np.y, z=np.z}
end
end
i=i-1
end
end)
-- falling nodes go into pocket --
@ -114,5 +37,3 @@ function default.dig_horz2(pos, node, digger)
minetest.node_dig(np, nn, digger)
end
end

265
init.lua
Visa fil

@ -1,3 +1,67 @@
local buildPlatform = function(node, pos, itemstack)
-- code for the building platforms
posZ = {'1', '0', '-1', '-1', '0', '0', '1', '1' };
posX = {'0', '-1', '0', '0', '1', '1', '0', '0' };
for nameCount = 1, 8 do
pos.z = pos.z + posZ[nameCount];
pos.x = pos.x + posX[nameCount];
local current_node = minetest.get_node(pos);
if current_node.name == "air" then
minetest.set_node(pos, {name = node} )
itemstack:take_item(1); --//and remove one if its the correct one
break;
end
end
-- end of function
end
local buildScaffolding = function(node, pos, itemstack, player)
-- many thanks to addi for improveing (rewriteing) my crappy code --
-- code for the building scaffolding
height = 0;
depth = 0; -- !!Note!! depth is not needed at the moment
minetest.chat_send_all(string.format("Hello"))
--[[ debug stuff ]]
minetest.chat_send_all(string.format("node: %s",name))
minetest.chat_send_all(string.format("node: %s %s %s ",pos.x, pos.y, pos.z ))
-- set pos at bottom of scafolding tower.
repeat
pos.y = pos.y - 1; --every run get one node up
depth = depth - 1
local current_node = minetest.get_node(pos); --get the node of the new position
minetest.chat_send_all(string.format("found %q at location: %s",
current_node.name,
minetest.pos_to_string(pos)
))
until current_node.name ~= node -- will repeat untill it dose not find a scaffolding node
minetest.chat_send_all(string.format("exit loop"))
-- check height of scaffolding tower --
repeat
pos.y = pos.y + 1; --every run get one node up
height = height + 1
local current_node = minetest.get_node(pos); --get the node of the new position
minetest.chat_send_all(string.format("found %q at location: %s",
current_node.name,
minetest.pos_to_string(pos)
))
if current_node.name == "air" then
minetest.set_node(pos, {name = node } )
itemstack:take_item(1); --//and remove one if its the correct one
player:set_wielded_item(itemstack);--//update inventory of the player
end
until current_node.name ~= node or height >= 32 --we repeat until we find something else then "scaffolding:scaffolding"
--maybe there should be also another limit, because its currently possible to build infinite towers
minetest.chat_send_all(string.format("exit loop"))
end
print("scaffolding: Loading 'functions.lua'")
dofile(minetest.get_modpath("scaffolding").."/functions.lua")
@ -28,78 +92,23 @@ minetest.register_node("scaffolding:scaffolding", {
end
end,
on_rightclick = function(pos, node, player, itemstack, pointed_thing)
-- if user hits scaffolding with platform then --
-- if user hits scaffolding with platform Wooden scaffolding then --
if itemstack:get_name() == "scaffolding:platform" then
--arrayZ ( 1, 0, -1, -1, 0, 0, 1, 1 );
-- arrayX( 0, -1, 0, 0, 1, 1, 0, 0 );
local name = minetest.get_node(pos).name
posZ = {'1', '0', '-1', '-1', '0', '0', '1', '1' };
posX = {'0', '-1', '0', '0', '1', '1', '0', '0' };
for nameCount = 1, 8 do
pos.z = pos.z + posZ[nameCount];
pos.x = pos.x + posX[nameCount];
local current_node = minetest.get_node(pos);
if current_node.name == "air" then
minetest.set_node(pos, {name = "scaffolding:platform"} )
itemstack:take_item(1); --//and remove one if its the correct one
break;
end
end
node = "scaffolding:platform";
buildPlatform(node, pos, itemstack)
end
-- if user hits scaffolding with platform Iron scaffolding then --
if itemstack:get_name() == "scaffolding:iron_platform" then
node = "scaffolding:iron_platform";
buildPlatform(node, pos, itemstack)
end
-- if user hits scaffolding with scaffolding then --
if itemstack:get_name() == "scaffolding:scaffolding" then
-- many thanks to addi for improveing (rewriteing) my crappy code --
node = "scaffolding:scaffolding";
local name = minetest.get_node(pos).name -- get loacation of node
height = 0;
depth = 0; -- !!Note!! depth is not needed at the moment
--[[ debug stuff ]]
minetest.chat_send_all(string.format("node: %s",name))
minetest.chat_send_all(string.format("node: %s %s %s ",pos.x, pos.y, pos.z ))
-- set pos at bottom of scafolding tower.
repeat
pos.y = pos.y - 1; --every run get one node up
depth = depth - 1
local current_node = minetest.get_node(pos); --get the node of the new position
minetest.chat_send_all(string.format("found %q at location: %s",
current_node.name,
minetest.pos_to_string(pos)
))
until current_node.name ~= "scaffolding:scaffolding" -- will repeat untill it dose not find a scaffolding node
minetest.chat_send_all(string.format("exit loop"))
-- check height of scaffolding tower --
repeat
pos.y = pos.y + 1; --every run get one node up
height = height + 1
local current_node = minetest.get_node(pos); --get the node of the new position
minetest.chat_send_all(string.format("found %q at location: %s",
current_node.name,
minetest.pos_to_string(pos)
))
if current_node.name == "air" then
minetest.set_node(pos, {name = "scaffolding:scaffolding"} )
itemstack:take_item(1); --//and remove one if its the correct one
player:set_wielded_item(itemstack);--//update inventory of the player
end
until current_node.name ~= "scaffolding:scaffolding" or height >= 32 --we repeat until we find something else then "scaffolding:scaffolding"
--maybe there should be also another limit, because its currently possible to build infinite towers
minetest.chat_send_all(string.format("exit loop"))
end
end,
buildScaffolding(node, pos, itemstack, player)
end
end,
node_box = {
type = "fixed",
fixed = {
@ -139,21 +148,18 @@ minetest.register_node("scaffolding:reinforced_scaffolding", {
puncher:get_inventory():add_item("main", ItemStack("scaffolding:scaffolding"))
end
end,
--[[ on_rightclick = function(pos, node, puncher)
local tool = puncher:get_wielded_item():get_name()
if tool and tool == "scaffolding:scaffolding_wrench" then
node.name = "scaffolding:scaffolding"
minetest.env:set_node(pos, node)
on_rightclick = function(pos, node, player, itemstack, pointed_thing)
-- if user hits scaffolding with platform Wooden scaffolding then --
if itemstack:get_name() == "scaffolding:platform" then
node = "scaffolding:platform";
buildPlatform(node, pos, itemstack)
end
-- if user hits scaffolding with platform Iron scaffolding then --
if itemstack:get_name() == "scaffolding:iron_platform" then
node = "scaffolding:iron_platform";
buildPlatform(node, pos, itemstack)
end
end,
on_punch = function(pos, node, puncher)
local tool = puncher:get_wielded_item():get_name()
if tool and tool == "scaffolding:scaffolding_wrench" then
node.name = "air"
minetest.env:set_node(pos, node)
puncher:get_inventory():add_item("main", ItemStack("scaffolding:scaffolding"))
end
end,]]
node_box = {
type = "fixed",
fixed = {
@ -273,74 +279,21 @@ minetest.register_node("scaffolding:reinforced_scaffolding", {
end
end,
on_rightclick = function(pos, node, player, itemstack, pointed_thing)
-- if user hits scaffolding with platform then --
-- if user hits scaffolding with platform Iron scaffolding then --
if itemstack:get_name() == "scaffolding:iron_platform" then
--arrayZ ( 1, 0, -1, -1, 0, 0, 1, 1 );
-- arrayX( 0, -1, 0, 0, 1, 1, 0, 0 );
local name = minetest.get_node(pos).name
posZ = {'1', '0', '-1', '-1', '0', '0', '1', '1' };
posX = {'0', '-1', '0', '0', '1', '1', '0', '0' };
for nameCount = 1, 8 do
pos.z = pos.z + posZ[nameCount];
pos.x = pos.x + posX[nameCount];
local current_node = minetest.get_node(pos);
if current_node.name == "air" then
minetest.set_node(pos, {name = "scaffolding:iron_platform"} )
itemstack:take_item(1); --//and remove one if its the correct one
break;
end
end
node = "scaffolding:iron_platform";
buildPlatform(node, pos, itemstack)
end
-- if user hits scaffolding with platform Wooden scaffolding then --
if itemstack:get_name() == "scaffolding:platform" then
node = "scaffolding:platform";
buildPlatform(node, pos, itemstack)
end
-- if user hits scaffolding with scaffolding then --
if itemstack:get_name() == "scaffolding:iron_scaffolding" then
-- many thanks to addi for improveing (rewriteing) my crappy code --
node = "scaffolding:iron_scaffolding";
local name = minetest.get_node(pos).name -- get loacation of node
height = 0;
depth = 0; -- !!Note!! depth is not deeded at the moment
--[[ debug stuff ]]
minetest.chat_send_all(string.format("node: %s",name))
minetest.chat_send_all(string.format("node: %s %s %s ",pos.x, pos.y, pos.z ))
-- set pos at bottom of scafolding tower.
repeat
pos.y = pos.y - 1; --every run get one node up
depth = depth - 1 -- !!Note!! depth is not needed at the moment
local current_node = minetest.get_node(pos); --get the node of the new position
minetest.chat_send_all(string.format("found %q at location: %s",
current_node.name,
minetest.pos_to_string(pos)
))
until current_node.name ~= "scaffolding:iron_scaffolding" -- will repeat untill it dose not find a scaffolding node
minetest.chat_send_all(string.format("exit loop"))
-- check height of scaffolding tower --
repeat
pos.y = pos.y + 1; --every run get one node up
height = height + 1
local current_node = minetest.get_node(pos); --get the node of the new position
minetest.chat_send_all(string.format("found %q at location: %s",
current_node.name,
minetest.pos_to_string(pos)
))
if current_node.name == "air" then
minetest.set_node(pos, {name = "scaffolding:iron_scaffolding"} )
itemstack:take_item(1); --//and remove one if its the correct one
player:set_wielded_item(itemstack);--//update inventory of the player
end
until current_node.name ~= "scaffolding:iron_scaffolding" or height >= 32 --we repeat until we find something else then "scaffolding:scaffolding"
--maybe there should be also another limit, because its currently possible to build infinite towers
minetest.chat_send_all(string.format("exit loop"))
buildScaffolding(node, pos, itemstack, player)
end
end,
@ -371,22 +324,18 @@ minetest.register_node("scaffolding:reinforced_scaffolding", {
puncher:get_inventory():add_item("main", ItemStack("scaffolding:scaffolding"))
end
end,
--[[on_rightclick = function(pos, node, puncher)
local tool = puncher:get_wielded_item():get_name()
if tool and tool == "scaffolding:scaffolding_wrench" then
node.name = "scaffolding:iron_scaffolding"
minetest.env:set_node(pos, node)
on_rightclick = function(pos, node, player, itemstack, pointed_thing)
-- if user hits scaffolding with platform Iron scaffolding then --
if itemstack:get_name() == "scaffolding:iron_platform" then
node = "scaffolding:iron_platform";
buildPlatform(node, pos, itemstack)
end
-- if user hits scaffolding with platform Wooden scaffolding then --
if itemstack:get_name() == "scaffolding:platform" then
node = "scaffolding:platform";
buildPlatform(node, pos, itemstack)
end
end,
on_punch = function(pos, node, puncher)
local tool = puncher:get_wielded_item():get_name()
if tool and tool == "scaffolding:scaffolding_wrench" then
node.name = "air"
minetest.env:set_node(pos, node)
--puncher:get_inventory():remove_item("main", ItemStack("beer_test:tankard"))
puncher:get_inventory():add_item("main", ItemStack("scaffolding:scaffolding"))
end
end,]]
node_box = {
type = "fixed",
fixed = {