mirror of
https://github.com/minetest-mods/towercrane.git
synced 2024-11-26 01:03:45 +01:00
v0.06: free space check bug fix, settingtypes added
This commit is contained in:
parent
bcc049cb65
commit
6970100281
10
config.lua
10
config.lua
@ -1,14 +1,14 @@
|
|||||||
-- Maximum crane height in blocks (12..n)
|
-- Maximum crane height in blocks (12..n)
|
||||||
towercrane.max_height = 24
|
towercrane.max_height = tonumber(minetest.setting_get("towercrane_max_height")) or 24
|
||||||
|
|
||||||
-- Maximum crane width in blocks (12..n)
|
-- Maximum crane width in blocks (12..n)
|
||||||
towercrane.max_width = 24
|
towercrane.max_width = tonumber(minetest.setting_get("towercrane_max_width")) or 24
|
||||||
|
|
||||||
-- Crane rope lenght in block (max_height .. max_height+x)
|
-- Crane rope lenght in block (max_height .. max_height+x)
|
||||||
towercrane.rope_length = 24
|
towercrane.rope_length = tonumber(minetest.setting_get("towercrane_rope_length")) or 24
|
||||||
|
|
||||||
-- Gain factor for the crane sound (0.0 to 1)
|
-- Gain factor for the crane sound (0.0 to 1)
|
||||||
towercrane.gain = 1
|
towercrane.gain = tonumber(minetest.setting_get("towercrane_gain")) or 1
|
||||||
|
|
||||||
-- Recipe available (true/false)
|
-- Recipe available (true/false)
|
||||||
towercrane.recipe = true
|
towercrane.recipe = tonumber(minetest.setting_get("towercrane_recipe")) or true
|
||||||
|
131
init.lua
131
init.lua
@ -3,7 +3,7 @@
|
|||||||
Tower Crane Mod
|
Tower Crane Mod
|
||||||
===============
|
===============
|
||||||
|
|
||||||
v0.05 by JoSt
|
v0.06 by JoSt
|
||||||
|
|
||||||
Copyright (C) 2017 Joachim Stolberg
|
Copyright (C) 2017 Joachim Stolberg
|
||||||
LGPLv2.1+
|
LGPLv2.1+
|
||||||
@ -15,6 +15,7 @@
|
|||||||
2017-06-07 v0.03 fixed 2 bugs, added config.lua and sound
|
2017-06-07 v0.03 fixed 2 bugs, added config.lua and sound
|
||||||
2017-06-08 v0.04 recipe and rope length now configurable
|
2017-06-08 v0.04 recipe and rope length now configurable
|
||||||
2017-06-10 v0.05 resizing bugfix, area protection added
|
2017-06-10 v0.05 resizing bugfix, area protection added
|
||||||
|
2017-07-11 v0.06 fixed the space check bug, settingtypes added
|
||||||
|
|
||||||
]]--
|
]]--
|
||||||
|
|
||||||
@ -169,103 +170,86 @@ local function turnleft(dir)
|
|||||||
end
|
end
|
||||||
|
|
||||||
----------------------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------------
|
||||||
-- Check space for mast and arm
|
-- generic function for contruction and removement
|
||||||
----------------------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------------
|
||||||
local function check_space(pos, dir, height, width)
|
local function crane_body_plan(pos, dir, height, width, clbk, tArg)
|
||||||
for i = 1,height+2 do
|
|
||||||
pos.y = pos.y + 1
|
pos.y = pos.y + 1
|
||||||
if minetest.get_node_or_nil(pos).name ~= "air" then
|
clbk(pos, "towercrane:mast_ctrl_off", tArg)
|
||||||
return false
|
|
||||||
|
for i = 1,height+1 do
|
||||||
|
pos.y = pos.y + 1
|
||||||
|
clbk(pos, "towercrane:mast", tArg)
|
||||||
|
end
|
||||||
|
|
||||||
|
pos.y = pos.y - 2
|
||||||
|
pos.x = pos.x - dir.x
|
||||||
|
pos.z = pos.z - dir.z
|
||||||
|
clbk(pos, "towercrane:arm2", tArg)
|
||||||
|
pos.x = pos.x - dir.x
|
||||||
|
pos.z = pos.z - dir.z
|
||||||
|
clbk(pos, "towercrane:arm", tArg)
|
||||||
|
pos.x = pos.x - dir.x
|
||||||
|
pos.z = pos.z - dir.z
|
||||||
|
clbk(pos, "towercrane:balance", tArg)
|
||||||
|
pos.x = pos.x + 3 * dir.x
|
||||||
|
pos.z = pos.z + 3 * dir.z
|
||||||
|
|
||||||
|
for i = 1,width do
|
||||||
|
pos.x = pos.x + dir.x
|
||||||
|
pos.z = pos.z + dir.z
|
||||||
|
if i % 2 == 0 then
|
||||||
|
clbk(pos, "towercrane:arm2", tArg)
|
||||||
|
else
|
||||||
|
clbk(pos, "towercrane:arm", tArg)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
pos.x = pos.x + dir.x*2
|
----------------------------------------------------------------------------------------------------
|
||||||
pos.z = pos.z + dir.z*2
|
-- Check space for mast and arm
|
||||||
for i = 1,width+3 do
|
----------------------------------------------------------------------------------------------------
|
||||||
pos.x = pos.x + dir.x
|
local function check_space(pos, dir, height, width)
|
||||||
pos.z = pos.z + dir.z
|
local remove = function(pos, node_name, tArg)
|
||||||
if minetest.get_node_or_nil(pos).name ~= "air" then
|
if minetest.get_node_or_nil(pos).name ~= "air" then
|
||||||
return false
|
tArg.res = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return true
|
|
||||||
|
local tArg = {res = true}
|
||||||
|
crane_body_plan(pos, dir, height, width, remove, tArg)
|
||||||
|
return tArg.res
|
||||||
end
|
end
|
||||||
|
|
||||||
----------------------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------------
|
||||||
-- Constuct mast and arm
|
-- Constuct mast and arm
|
||||||
----------------------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------------
|
||||||
local function construct_crane(pos, dir, height, width, owner)
|
local function construct_crane(pos, dir, height, width, owner)
|
||||||
|
local add = function(pos, node_name, tArg)
|
||||||
|
minetest.add_node(pos, {name=node_name, param2=minetest.dir_to_facedir(tArg.dir)})
|
||||||
|
end
|
||||||
|
|
||||||
|
local tArg = {dir = dir}
|
||||||
|
crane_body_plan(table.copy(pos), dir, height, width, add, tArg)
|
||||||
|
|
||||||
pos.y = pos.y + 1
|
pos.y = pos.y + 1
|
||||||
minetest.env:add_node(pos, {name="towercrane:mast_ctrl_off", param2=minetest.dir_to_facedir(dir)})
|
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
meta:set_string("dir", minetest.pos_to_string(dir))
|
meta:set_string("dir", minetest.pos_to_string(dir))
|
||||||
meta:set_string("owner", owner)
|
meta:set_string("owner", owner)
|
||||||
meta:set_int("height", height)
|
meta:set_int("height", height)
|
||||||
meta:set_int("width", width)
|
meta:set_int("width", width)
|
||||||
|
|
||||||
for i = 1,height+1 do
|
|
||||||
pos.y = pos.y + 1
|
|
||||||
minetest.env:add_node(pos, {name="towercrane:mast"})
|
|
||||||
end
|
|
||||||
|
|
||||||
pos.y = pos.y - 2
|
|
||||||
pos.x = pos.x - dir.x
|
|
||||||
pos.z = pos.z - dir.z
|
|
||||||
minetest.env:add_node(pos, {name="towercrane:arm2"})
|
|
||||||
pos.x = pos.x - dir.x
|
|
||||||
pos.z = pos.z - dir.z
|
|
||||||
minetest.env:add_node(pos, {name="towercrane:arm"})
|
|
||||||
pos.x = pos.x - dir.x
|
|
||||||
pos.z = pos.z - dir.z
|
|
||||||
minetest.env:add_node(pos, {name="towercrane:balance"})
|
|
||||||
pos.x = pos.x + 3 * dir.x
|
|
||||||
pos.z = pos.z + 3 * dir.z
|
|
||||||
|
|
||||||
for i = 1,width do
|
|
||||||
pos.x = pos.x + dir.x
|
|
||||||
pos.z = pos.z + dir.z
|
|
||||||
if i % 2 == 0 then
|
|
||||||
minetest.env:add_node(pos, {name="towercrane:arm2"})
|
|
||||||
else
|
|
||||||
minetest.env:add_node(pos, {name="towercrane:arm"})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
----------------------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------------
|
||||||
-- Remove the crane
|
-- Remove the crane
|
||||||
----------------------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------------
|
||||||
local function remove_crane(pos, dir, height, width)
|
local function remove_crane(pos, dir, height, width)
|
||||||
pos.y = pos.y + 1
|
local remove = function(pos, node_name, tArg)
|
||||||
minetest.env:remove_node(pos, {name="towercrane:mast_ctrl_off"})
|
if minetest.get_node_or_nil(pos).name == node_name then
|
||||||
|
minetest.remove_node(pos)
|
||||||
for i = 1,height+1 do
|
|
||||||
pos.y = pos.y + 1
|
|
||||||
minetest.env:remove_node(pos, {name="towercrane:mast"})
|
|
||||||
end
|
|
||||||
|
|
||||||
pos.y = pos.y - 2
|
|
||||||
pos.x = pos.x - dir.x
|
|
||||||
pos.z = pos.z - dir.z
|
|
||||||
minetest.env:remove_node(pos, {name="towercrane:arm2"})
|
|
||||||
pos.x = pos.x - dir.x
|
|
||||||
pos.z = pos.z - dir.z
|
|
||||||
minetest.env:remove_node(pos, {name="towercrane:arm"})
|
|
||||||
pos.x = pos.x - dir.x
|
|
||||||
pos.z = pos.z - dir.z
|
|
||||||
minetest.env:remove_node(pos, {name="towercrane:balance"})
|
|
||||||
pos.x = pos.x + 3 * dir.x
|
|
||||||
pos.z = pos.z + 3 * dir.z
|
|
||||||
|
|
||||||
for i = 1,width do
|
|
||||||
pos.x = pos.x + dir.x
|
|
||||||
pos.z = pos.z + dir.z
|
|
||||||
if i % 2 == 0 then
|
|
||||||
minetest.env:remove_node(pos, {name="towercrane:arm2"})
|
|
||||||
else
|
|
||||||
minetest.env:remove_node(pos, {name="towercrane:arm"})
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
crane_body_plan(pos, dir, height, width, remove, {})
|
||||||
end
|
end
|
||||||
|
|
||||||
----------------------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------------
|
||||||
@ -343,9 +327,11 @@ local function check_input(fields)
|
|||||||
local height = tonumber(size[1])
|
local height = tonumber(size[1])
|
||||||
local width = tonumber(size[2])
|
local width = tonumber(size[2])
|
||||||
if height ~= nil and width ~= nil then
|
if height ~= nil and width ~= nil then
|
||||||
height = math.max(height, 8)
|
--height = math.max(height, 8)
|
||||||
|
height = math.max(height, 2)
|
||||||
height = math.min(height, towercrane.max_height)
|
height = math.min(height, towercrane.max_height)
|
||||||
width = math.max(width, 8)
|
--width = math.max(width, 8)
|
||||||
|
width = math.max(width, 2)
|
||||||
width = math.min(width, towercrane.max_width)
|
width = math.min(width, towercrane.max_width)
|
||||||
return height, width
|
return height, width
|
||||||
end
|
end
|
||||||
@ -370,7 +356,6 @@ minetest.register_node("towercrane:base", {
|
|||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
is_ground_content = false,
|
is_ground_content = false,
|
||||||
groups = {cracky=2},
|
groups = {cracky=2},
|
||||||
formspec = set_formspec,
|
|
||||||
|
|
||||||
-- set meta data (form for crane height and width, dir of the arm)
|
-- set meta data (form for crane height and width, dir of the arm)
|
||||||
after_place_node = function(pos, placer)
|
after_place_node = function(pos, placer)
|
||||||
|
@ -4,7 +4,9 @@ towercrane_max_height (maximum crane height) int 24
|
|||||||
# Maximum crane width in blocks (12..n)
|
# Maximum crane width in blocks (12..n)
|
||||||
towercrane_max_width (maximum crane width) int 24
|
towercrane_max_width (maximum crane width) int 24
|
||||||
|
|
||||||
# Crane rope lenght in block (max_height .. max_height+x)
|
# Crane rope lenght in blocks (max_height .. max_height+x)
|
||||||
|
# If the rope length is larger than the crane height, the crane
|
||||||
|
# can be placed on buildings and the hook still reaches the ground.
|
||||||
towercrane_rope_length (crane rope lenght) int 24
|
towercrane_rope_length (crane rope lenght) int 24
|
||||||
|
|
||||||
# Gain factor for the crane sound (0.0 to 1)
|
# Gain factor for the crane sound (0.0 to 1)
|
||||||
|
Loading…
Reference in New Issue
Block a user