Allow mechanisms to be linked, and allow storing links in schematics.
This commit is contained in:
parent
8f98a7fa2d
commit
8a8fa943c5
9 changed files with 438 additions and 104 deletions
|
|
@ -21,13 +21,14 @@ minetest.register_entity(":artifact:lever_display", {
|
|||
end
|
||||
e.object:set_armor_groups{immortal = 1}
|
||||
extend(e, minetest.deserialize(data) or {})
|
||||
if not e.rotation then e.rotation = vector.zero() end
|
||||
levers[e.object:get_pos():round():to_string()] = e
|
||||
end,
|
||||
on_deactivte = function(e)
|
||||
levers[e.object:get_pos():round():to_string()] = nil
|
||||
end,
|
||||
get_staticdata = function(e)
|
||||
return {rotation = e.rotation}
|
||||
return minetest.serialize{rotation = e.rotation}
|
||||
end,
|
||||
on_interact = function(e)
|
||||
if e._active then
|
||||
|
|
@ -36,6 +37,7 @@ minetest.register_entity(":artifact:lever_display", {
|
|||
e.object:set_animation({x=1,y=2}, 2, 0.1, false)
|
||||
minetest.after(0.5, function()
|
||||
e._no_interact = nil
|
||||
e:trigger(false)
|
||||
end)
|
||||
else
|
||||
e._active = true
|
||||
|
|
@ -43,10 +45,21 @@ minetest.register_entity(":artifact:lever_display", {
|
|||
e.object:set_animation({x=0,y=1}, 2, 0.1, false)
|
||||
minetest.after(0.5, function()
|
||||
e._no_interact = nil
|
||||
e:trigger(true)
|
||||
end)
|
||||
end
|
||||
end,
|
||||
trigger = function(e, state)
|
||||
local receivers = minetest.deserialize(minetest.get_meta(e.object:get_pos():round()):get("receivers") or "return nil")
|
||||
if receivers then
|
||||
artifact.dispatch_event(receivers, {type = state and "on" or "off"})
|
||||
end
|
||||
end,
|
||||
rotate = function(e, rot)
|
||||
if not rot then
|
||||
say "!"
|
||||
return
|
||||
end
|
||||
e.object:set_rotation(rot)
|
||||
e.rotation = rot
|
||||
e.object:set_properties {
|
||||
|
|
@ -58,6 +71,7 @@ minetest.register_entity(":artifact:lever_display", {
|
|||
end
|
||||
})
|
||||
|
||||
|
||||
artifact.register_node("lever", {
|
||||
drawtype = "airlike",
|
||||
paramtype = "light",
|
||||
|
|
@ -66,9 +80,13 @@ artifact.register_node("lever", {
|
|||
pointable = false,
|
||||
on_construct = function(pos)
|
||||
local m = minetest.get_meta(pos)
|
||||
m:set_string("initialized", "true")
|
||||
local rot = minetest.facedir_to_dir(minetest.get_node(pos).param2):dir_to_rotation()
|
||||
minetest.add_entity(pos, "artifact:lever_display", minetest.serialize{type = "wood"}):get_luaentity():rotate(rot)
|
||||
local rot = artifact.facedir_to_rotation(minetest.get_node(pos).param2)
|
||||
if m:contains("initialized") then
|
||||
levers[pos:to_string()]:rotate(rot)
|
||||
else
|
||||
m:set_string("initialized", "true")
|
||||
minetest.add_entity(pos, "artifact:lever_display", minetest.serialize{type = "wood"}):get_luaentity():rotate(rot)
|
||||
end
|
||||
end,
|
||||
on_destruct = function(pos)
|
||||
levers[pos:to_string()].object:remove()
|
||||
|
|
@ -79,15 +97,18 @@ artifact.register_node("lever", {
|
|||
-- Dynamically initialize doors that were mapgen'd in.
|
||||
if not m:contains("initialized") then
|
||||
m:set_string("initialized", "true")
|
||||
local rot = minetest.facedir_to_dir(minetest.get_node(pos).param2):dir_to_rotation()
|
||||
local rot = artifact.facedir_to_rotation(minetest.get_node(pos).param2)
|
||||
minetest.add_entity(pos, "artifact:lever_display", minetest.serialize{type = "wood"}):get_luaentity():rotate(rot)
|
||||
end
|
||||
end,
|
||||
on_rightclick = function(pos)
|
||||
local rot = artifact.facedir_to_rotation(minetest.get_node(pos).param2)
|
||||
levers[pos:to_string()]:rotate(rot)
|
||||
end,
|
||||
on_rotate = function(pos, node, p, click, param2)
|
||||
local node = minetest.get_node(pos)
|
||||
node.param2 = param2
|
||||
minetest.swap_node(pos, node)
|
||||
local rot = minetest.facedir_to_dir(node.param2):dir_to_rotation()
|
||||
local rot = artifact.facedir_to_rotation(param2)
|
||||
levers[pos:to_string()]:rotate(rot)
|
||||
return true
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue