mirror of
https://github.com/minetest-mods/towercrane.git
synced 2024-11-26 09:13:53 +01:00
hook bugfix
This commit is contained in:
parent
d19e401fb5
commit
37479a77b7
350
init.lua
350
init.lua
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
History:
|
History:
|
||||||
2017-06-04 v0.01 first version
|
2017-06-04 v0.01 first version
|
||||||
|
2017-06-06 v0.02 Hook bugfix
|
||||||
]]--
|
]]--
|
||||||
|
|
||||||
|
|
||||||
@ -20,12 +21,12 @@ towercrane = {}
|
|||||||
--## Tower Crane Hook
|
--## Tower Crane Hook
|
||||||
--##################################################################################################
|
--##################################################################################################
|
||||||
local hook = {
|
local hook = {
|
||||||
physical = true,
|
physical = true,
|
||||||
collisionbox = {-0.2, -0.2, -0.2, 0.2, 0.2, 0.2},
|
collisionbox = {-0.2, -0.2, -0.2, 0.2, 0.2, 0.2},
|
||||||
collide_with_objects = false,
|
collide_with_objects = false,
|
||||||
visual = "cube",
|
visual = "cube",
|
||||||
visual_size = {x=0.4, y=0.4},
|
visual_size = {x=0.4, y=0.4},
|
||||||
textures = {
|
textures = {
|
||||||
"towercrane_hook.png",
|
"towercrane_hook.png",
|
||||||
"towercrane_hook.png",
|
"towercrane_hook.png",
|
||||||
"towercrane_hook.png",
|
"towercrane_hook.png",
|
||||||
@ -35,7 +36,7 @@ local hook = {
|
|||||||
},
|
},
|
||||||
groups = {cracky=1},
|
groups = {cracky=1},
|
||||||
-- local variabels
|
-- local variabels
|
||||||
driver = nil,
|
driver = nil,
|
||||||
speed_forward=0,
|
speed_forward=0,
|
||||||
speed_right=0,
|
speed_right=0,
|
||||||
speed_up=0,
|
speed_up=0,
|
||||||
@ -44,13 +45,13 @@ local hook = {
|
|||||||
-- Enter/leave the Hook
|
-- Enter/leave the Hook
|
||||||
----------------------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------------
|
||||||
function hook:on_rightclick(clicker)
|
function hook:on_rightclick(clicker)
|
||||||
if self.driver and clicker == self.driver then -- leave?
|
if self.driver and clicker == self.driver then -- leave?
|
||||||
clicker:set_detach()
|
clicker:set_detach()
|
||||||
self.driver = nil
|
self.driver = nil
|
||||||
elseif not self.driver then -- enter?
|
elseif not self.driver then -- enter?
|
||||||
self.driver = clicker
|
self.driver = clicker
|
||||||
clicker:set_attach(self.object, "", {x=0,y=0,z=0}, {x=0,y=0,z=0})
|
clicker:set_attach(self.object, "", {x=0,y=0,z=0}, {x=0,y=0,z=0})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
----------------------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------------
|
||||||
@ -311,9 +312,16 @@ minetest.register_node("towercrane:base", {
|
|||||||
local height = meta:get_int("height")
|
local height = meta:get_int("height")
|
||||||
local width = meta:get_int("width")
|
local width = meta:get_int("width")
|
||||||
|
|
||||||
|
-- remove crane
|
||||||
if dir ~= nil and height ~= nil and width ~= nil then
|
if dir ~= nil and height ~= nil and width ~= nil then
|
||||||
dig_crane(pos, dir, height, width)
|
dig_crane(pos, dir, height, width)
|
||||||
end
|
end
|
||||||
|
-- remove hook
|
||||||
|
local id = minetest.hash_node_position(pos)
|
||||||
|
if towercrane.id then
|
||||||
|
towercrane.id:remove()
|
||||||
|
towercrane.id = nil
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -321,205 +329,203 @@ minetest.register_node("towercrane:base", {
|
|||||||
-- Register Crane balance
|
-- Register Crane balance
|
||||||
----------------------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------------
|
||||||
minetest.register_node("towercrane:balance", {
|
minetest.register_node("towercrane:balance", {
|
||||||
description = "Tower Crane Balance",
|
description = "Tower Crane Balance",
|
||||||
tiles = {
|
tiles = {
|
||||||
"towercrane_base.png",
|
"towercrane_base.png",
|
||||||
"towercrane_base.png",
|
"towercrane_base.png",
|
||||||
"towercrane_base.png",
|
"towercrane_base.png",
|
||||||
"towercrane_base.png",
|
"towercrane_base.png",
|
||||||
"towercrane_base.png",
|
"towercrane_base.png",
|
||||||
"towercrane_base.png",
|
"towercrane_base.png",
|
||||||
},
|
},
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
is_ground_content = false,
|
is_ground_content = false,
|
||||||
groups = {crumbly=0, not_in_creative_inventory=1},
|
groups = {crumbly=0, not_in_creative_inventory=1},
|
||||||
})
|
})
|
||||||
|
|
||||||
----------------------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------------
|
||||||
-- Register Crane mast
|
-- Register Crane mast
|
||||||
----------------------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------------
|
||||||
minetest.register_node("towercrane:mast", {
|
minetest.register_node("towercrane:mast", {
|
||||||
description = "Tower Crane Mast",
|
description = "Tower Crane Mast",
|
||||||
drawtype = "glasslike_framed",
|
drawtype = "glasslike_framed",
|
||||||
tiles = {
|
tiles = {
|
||||||
"towercrane_mast.png",
|
"towercrane_mast.png",
|
||||||
"towercrane_mast.png",
|
"towercrane_mast.png",
|
||||||
"towercrane_mast.png",
|
"towercrane_mast.png",
|
||||||
"towercrane_mast.png",
|
"towercrane_mast.png",
|
||||||
"towercrane_mast.png",
|
"towercrane_mast.png",
|
||||||
"towercrane_mast.png",
|
"towercrane_mast.png",
|
||||||
},
|
},
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
is_ground_content = false,
|
is_ground_content = false,
|
||||||
groups = {crumbly=0, not_in_creative_inventory=1},
|
groups = {crumbly=0, not_in_creative_inventory=1},
|
||||||
})
|
})
|
||||||
|
|
||||||
----------------------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------------
|
||||||
-- Register Crane Switch (on)
|
-- Register Crane Switch (on)
|
||||||
----------------------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------------
|
||||||
minetest.register_node("towercrane:mast_ctrl_on", {
|
minetest.register_node("towercrane:mast_ctrl_on", {
|
||||||
description = "Tower Crane Mast Ctrl On",
|
description = "Tower Crane Mast Ctrl On",
|
||||||
drawtype = "node",
|
drawtype = "node",
|
||||||
tiles = {
|
tiles = {
|
||||||
"towercrane_mast_ctrl.png",
|
"towercrane_mast_ctrl.png",
|
||||||
"towercrane_mast_ctrl.png",
|
"towercrane_mast_ctrl.png",
|
||||||
"towercrane_mast_ctrl_on.png",
|
"towercrane_mast_ctrl_on.png",
|
||||||
"towercrane_mast_ctrl_on.png",
|
"towercrane_mast_ctrl_on.png",
|
||||||
"towercrane_mast_ctrl.png",
|
"towercrane_mast_ctrl.png",
|
||||||
"towercrane_mast_ctrl.png",
|
"towercrane_mast_ctrl.png",
|
||||||
},
|
},
|
||||||
on_rightclick = function (pos, node, clicker)
|
on_rightclick = function (pos, node, clicker)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
if not clicker or not clicker:is_player() then
|
if not clicker or not clicker:is_player() then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if clicker:get_player_name() ~= meta:get_string("owner") then
|
if clicker:get_player_name() ~= meta:get_string("owner") then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
node.name = "towercrane:mast_ctrl_off"
|
node.name = "towercrane:mast_ctrl_off"
|
||||||
minetest.swap_node(pos, node)
|
minetest.swap_node(pos, node)
|
||||||
|
|
||||||
local id = minetest.hash_node_position(pos)
|
local id = minetest.hash_node_position(pos)
|
||||||
if towercrane.id then
|
if towercrane.id then
|
||||||
towercrane.id:remove()
|
towercrane.id:remove()
|
||||||
towercrane.id = nil
|
towercrane.id = nil
|
||||||
else
|
end
|
||||||
|
end,
|
||||||
|
|
||||||
end
|
on_construct = function(pos)
|
||||||
end,
|
local meta = minetest.get_meta(pos)
|
||||||
|
meta:set_string("infotext", "Switch crane on/off")
|
||||||
|
end,
|
||||||
|
|
||||||
on_construct = function(pos)
|
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
meta:set_string("infotext", "Switch crane on/off")
|
local owner = placer:get_player_name()
|
||||||
end,
|
meta:set_string("owner", owner)
|
||||||
|
end,
|
||||||
|
|
||||||
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
paramtype2 = "facedir",
|
||||||
local meta = minetest.get_meta(pos)
|
is_ground_content = false,
|
||||||
local owner = placer:get_player_name()
|
groups = {crumbly=0, not_in_creative_inventory=1},
|
||||||
meta:set_string("owner", owner)
|
|
||||||
end,
|
|
||||||
|
|
||||||
paramtype2 = "facedir",
|
|
||||||
is_ground_content = false,
|
|
||||||
groups = {crumbly=0, not_in_creative_inventory=1},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
----------------------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------------
|
||||||
-- Register Crane Switch (off)
|
-- Register Crane Switch (off)
|
||||||
----------------------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------------
|
||||||
minetest.register_node("towercrane:mast_ctrl_off", {
|
minetest.register_node("towercrane:mast_ctrl_off", {
|
||||||
description = "Tower Crane Mast Ctrl Off",
|
description = "Tower Crane Mast Ctrl Off",
|
||||||
drawtype = "node",
|
drawtype = "node",
|
||||||
tiles = {
|
tiles = {
|
||||||
|
"towercrane_mast_ctrl.png",
|
||||||
|
"towercrane_mast_ctrl.png",
|
||||||
|
"towercrane_mast_ctrl_off.png",
|
||||||
|
"towercrane_mast_ctrl_off.png",
|
||||||
|
"towercrane_mast_ctrl.png",
|
||||||
"towercrane_mast_ctrl.png",
|
"towercrane_mast_ctrl.png",
|
||||||
"towercrane_mast_ctrl.png",
|
},
|
||||||
"towercrane_mast_ctrl_off.png",
|
on_rightclick = function (pos, node, clicker)
|
||||||
"towercrane_mast_ctrl_off.png",
|
-- switch switch on, calculate the construction area, and place the hook
|
||||||
"towercrane_mast_ctrl.png",
|
local meta = minetest.get_meta(pos)
|
||||||
"towercrane_mast_ctrl.png",
|
-- only the owner is allowed to switch
|
||||||
},
|
if not clicker or not clicker:is_player() then
|
||||||
on_rightclick = function (pos, node, clicker)
|
return
|
||||||
-- switch switch on, calculate the construction area, and place the hook
|
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
-- only the owner is allowed to switch
|
|
||||||
if not clicker or not clicker:is_player() then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
if clicker:get_player_name() ~= meta:get_string("owner") then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
-- swap to the other node
|
|
||||||
node.name = "towercrane:mast_ctrl_on"
|
|
||||||
minetest.swap_node(pos, node)
|
|
||||||
local dir = minetest.string_to_pos(meta:get_string("dir"))
|
|
||||||
if pos ~= nil and dir ~= nil then
|
|
||||||
-- store hook instance in 'towercrane'
|
|
||||||
local id = minetest.hash_node_position(pos)
|
|
||||||
towercrane.id = place_hook(table.copy(pos), dir)
|
|
||||||
|
|
||||||
-- calculate the construction area dimension (pos, pos2)
|
|
||||||
local height = meta:get_int("height")
|
|
||||||
local width = meta:get_int("width")
|
|
||||||
|
|
||||||
-- pos1 = close/right
|
|
||||||
dir = turnright(dir)
|
|
||||||
local pos1 = vector.add(pos, vector.multiply(dir, width/2))
|
|
||||||
dir = turnleft(dir)
|
|
||||||
local pos1 = vector.add(pos1, vector.multiply(dir, 1))
|
|
||||||
pos1.y = pos.y - 1
|
|
||||||
|
|
||||||
-- pos2 = far/left
|
|
||||||
local pos2 = vector.add(pos1, vector.multiply(dir, width-1))
|
|
||||||
dir = turnleft(dir)
|
|
||||||
pos2 = vector.add(pos2, vector.multiply(dir, width))
|
|
||||||
pos2.y = pos.y - 4 + height
|
|
||||||
|
|
||||||
-- normalize x/z so that pos2 > pos1
|
|
||||||
if pos2.x < pos1.x then
|
|
||||||
pos2.x, pos1.x = pos1.x, pos2.x
|
|
||||||
end
|
end
|
||||||
if pos2.z < pos1.z then
|
if clicker:get_player_name() ~= meta:get_string("owner") then
|
||||||
pos2.z, pos1.z = pos1.z, pos2.z
|
return
|
||||||
end
|
end
|
||||||
|
-- swap to the other node
|
||||||
|
node.name = "towercrane:mast_ctrl_on"
|
||||||
|
minetest.swap_node(pos, node)
|
||||||
|
local dir = minetest.string_to_pos(meta:get_string("dir"))
|
||||||
|
if pos ~= nil and dir ~= nil then
|
||||||
|
-- store hook instance in 'towercrane'
|
||||||
|
local id = minetest.hash_node_position(pos)
|
||||||
|
towercrane.id = place_hook(table.copy(pos), dir)
|
||||||
|
|
||||||
-- store pos1/pos2 in the hook (LuaEntitySAO)
|
-- calculate the construction area dimension (pos, pos2)
|
||||||
towercrane.id:get_luaentity().pos1 = pos1
|
local height = meta:get_int("height")
|
||||||
towercrane.id:get_luaentity().pos2 = pos2
|
local width = meta:get_int("width")
|
||||||
end
|
|
||||||
end,
|
|
||||||
|
|
||||||
on_construct = function(pos)
|
-- pos1 = close/right
|
||||||
-- add infotext
|
dir = turnright(dir)
|
||||||
local meta = minetest.get_meta(pos)
|
local pos1 = vector.add(pos, vector.multiply(dir, width/2))
|
||||||
meta:set_string("infotext", "Switch crane on/off")
|
dir = turnleft(dir)
|
||||||
end,
|
local pos1 = vector.add(pos1, vector.multiply(dir, 1))
|
||||||
|
pos1.y = pos.y - 1
|
||||||
|
|
||||||
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
-- pos2 = far/left
|
||||||
-- store owner for dig protection
|
local pos2 = vector.add(pos1, vector.multiply(dir, width-1))
|
||||||
local meta = minetest.get_meta(pos)
|
dir = turnleft(dir)
|
||||||
local owner = placer:get_player_name()
|
pos2 = vector.add(pos2, vector.multiply(dir, width))
|
||||||
meta:set_string("owner", owner)
|
pos2.y = pos.y - 4 + height
|
||||||
end,
|
|
||||||
|
|
||||||
paramtype2 = "facedir",
|
-- normalize x/z so that pos2 > pos1
|
||||||
is_ground_content = false,
|
if pos2.x < pos1.x then
|
||||||
groups = {crumbly=0, not_in_creative_inventory=1},
|
pos2.x, pos1.x = pos1.x, pos2.x
|
||||||
|
end
|
||||||
|
if pos2.z < pos1.z then
|
||||||
|
pos2.z, pos1.z = pos1.z, pos2.z
|
||||||
|
end
|
||||||
|
|
||||||
|
-- store pos1/pos2 in the hook (LuaEntitySAO)
|
||||||
|
towercrane.id:get_luaentity().pos1 = pos1
|
||||||
|
towercrane.id:get_luaentity().pos2 = pos2
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
|
||||||
|
on_construct = function(pos)
|
||||||
|
-- add infotext
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
meta:set_string("infotext", "Switch crane on/off")
|
||||||
|
end,
|
||||||
|
|
||||||
|
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
||||||
|
-- store owner for dig protection
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
local owner = placer:get_player_name()
|
||||||
|
meta:set_string("owner", owner)
|
||||||
|
end,
|
||||||
|
|
||||||
|
paramtype2 = "facedir",
|
||||||
|
is_ground_content = false,
|
||||||
|
groups = {crumbly=0, not_in_creative_inventory=1},
|
||||||
})
|
})
|
||||||
|
|
||||||
----------------------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------------
|
||||||
-- Register Crane arm 1
|
-- Register Crane arm 1
|
||||||
----------------------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------------
|
||||||
minetest.register_node("towercrane:arm", {
|
minetest.register_node("towercrane:arm", {
|
||||||
description = "Tower Crane Arm",
|
description = "Tower Crane Arm",
|
||||||
drawtype = "glasslike_framed",
|
drawtype = "glasslike_framed",
|
||||||
tiles = {
|
tiles = {
|
||||||
"towercrane_arm.png",
|
"towercrane_arm.png",
|
||||||
"towercrane_arm.png",
|
"towercrane_arm.png",
|
||||||
"towercrane_arm.png",
|
"towercrane_arm.png",
|
||||||
"towercrane_arm.png",
|
"towercrane_arm.png",
|
||||||
"towercrane_arm.png",
|
"towercrane_arm.png",
|
||||||
"towercrane_arm.png",
|
"towercrane_arm.png",
|
||||||
},
|
},
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
is_ground_content = false,
|
is_ground_content = false,
|
||||||
groups = {crumbly=0, not_in_creative_inventory=1},
|
groups = {crumbly=0, not_in_creative_inventory=1},
|
||||||
})
|
})
|
||||||
|
|
||||||
----------------------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------------
|
||||||
-- Register Crane arm 2
|
-- Register Crane arm 2
|
||||||
----------------------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------------
|
||||||
minetest.register_node("towercrane:arm2", {
|
minetest.register_node("towercrane:arm2", {
|
||||||
description = "Tower Crane Arm2",
|
description = "Tower Crane Arm2",
|
||||||
drawtype = "glasslike_framed",
|
drawtype = "glasslike_framed",
|
||||||
tiles = {
|
tiles = {
|
||||||
"towercrane_arm2.png",
|
"towercrane_arm2.png",
|
||||||
"towercrane_arm2.png",
|
"towercrane_arm2.png",
|
||||||
"towercrane_arm2.png",
|
"towercrane_arm2.png",
|
||||||
"towercrane_arm2.png",
|
"towercrane_arm2.png",
|
||||||
"towercrane_arm2.png",
|
"towercrane_arm2.png",
|
||||||
"towercrane_arm2.png",
|
"towercrane_arm2.png",
|
||||||
},
|
},
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
is_ground_content = false,
|
is_ground_content = false,
|
||||||
groups = {crumbly=0, not_in_creative_inventory=1},
|
groups = {crumbly=0, not_in_creative_inventory=1},
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user