Add multi-signal doors, basic device deployment, and a target trigger.

This commit is contained in:
Signal 2025-11-17 03:04:16 -05:00
parent 1b2199705b
commit 3bf1d5c6a0
24 changed files with 656 additions and 74 deletions

View file

@ -19,9 +19,18 @@ minetest.register_entity(":artifact:lever_display", {
e.object:remove()
return
end
e._name = ""..math.random()
e.object:set_armor_groups{immortal = 1}
extend(e, minetest.deserialize(data) or {})
if not e.rotation then e.rotation = vector.zero() end
e.object:set_properties {
selectionbox = artifact.rotate_selectionbox({
-3/16, -0.5, -4/16,
3/16, -3/16, 4/16
}, e.rotation)
}
levers[e.object:get_pos():round():to_string()] = e
end,
on_deactivte = function(e)
@ -108,7 +117,6 @@ artifact.register_node("lever", {
end,
on_load = function(pos)
local m = minetest.get_meta(pos)
-- Dynamically initialize doors that were mapgen'd in.
if not m:contains("initialized") then
m:set_string("initialized", "true")
local rot = artifact.facedir_to_rotation(minetest.get_node(pos).param2)
@ -127,3 +135,39 @@ artifact.register_node("lever", {
return true
end
})
artifact.register_node("target", {
tiles = {"artifact_target.png"},
on_impact = function(pos)
local receivers = minetest.deserialize(minetest.get_meta(pos):get("receivers") or "return nil")
if receivers then
artifact.dispatch_event(receivers, {type = "pulse"})
end
end
})
artifact.register_node("target_off", {
tiles = {"artifact_target_off.png"},
on_impact = function(pos)
local receivers = minetest.deserialize(minetest.get_meta(pos):get("receivers") or "return nil")
if receivers then
artifact.dispatch_event(receivers, {type = "on"})
end
minetest.swap_node(pos, {name = "target_on"})
end
})
artifact.register_node("target_on", {
tiles = {"artifact_target_on.png"},
on_impact = function(pos)
local receivers = minetest.deserialize(minetest.get_meta(pos):get("receivers") or "return nil")
if receivers then
artifact.dispatch_event(receivers, {type = "off"})
end
minetest.swap_node(pos, {name = "target_off"})
end
})

View file

@ -18,12 +18,25 @@ minetest.register_entity(":artifact:door", {
selectionbox = {
-0.5, -0.5, -0.5,
0.5, 1.5, -6/16
}
},
physical = true
},
_interact_time = 0.2,
_interact_marker_offset = function(e)
return (e._open and vector.new(-0.5, 0.5, 0) or vector.new(0, 0.5, 0.5)):rotate(e.object:get_rotation())
return (e._open and vector.new(e.inverted and 0.5 or -0.5, 0.5, 0) or vector.new(0, 0.5, 0.5)):rotate(e.object:get_rotation())
end,
box_open_normal = {
-0.5, -0.5, -0.5,
-6/16, 1.5, 0.5
},
box_open_inverted = {
0.5, -0.5, -0.5,
6/16, 1.5, 0.5
},
box_closed_normal = {
-0.5, -0.5, 0.5,
0.5, 1.5, 6/16
},
on_activate = function(e, data)
local node = minetest.get_node(e.object:get_pos())
if not node.name:find "door" then
@ -43,12 +56,21 @@ minetest.register_entity(":artifact:door", {
if e.rotation then
e.rotation.y = e.rotation.y +math.pi
e:rotate(e.rotation)
else
e.rotation = vector.zero()
end
local box = artifact.rotate_selectionbox(e.box_closed_normal, e.rotation)
e.object:set_properties {
selectionbox = box,
collisionbox = box
}
e._name = ""..math.random()
local nm = minetest.get_meta(e.object:get_pos())
if (node.name:find "_open") and not e._open then
local open = nm:get("open") == "true"
if open and not e._open then
e:open(true)
elseif not (node.name:find "_open") and e._open then
elseif not open and e._open then
e:close(true)
end
if nm:get_string("locked") == "true" then
@ -57,6 +79,7 @@ minetest.register_entity(":artifact:door", {
if e._locked then
e._no_interact = true
end
if e.inverted then e:invert() end
doors[e.object:get_pos():round():to_string()] = e
end,
on_deactivate = function(e)
@ -78,14 +101,11 @@ minetest.register_entity(":artifact:door", {
e.object:set_animation({x=snap and 0.5 or 0,y=0.5}, 1.5, 0.1, false)
minetest.after(snap and 0 or 0.1, function()
local pos = e.object:get_pos():round()
local node = minetest.get_node(pos)
node.name = "door_"..e.type.."_open"
minetest.swap_node(pos, node)
minetest.get_meta(pos):set_string("open", "true")
local box = artifact.rotate_selectionbox(e.inverted and e.box_open_inverted or e.box_open_normal, e.rotation)
e.object:set_properties {
selectionbox = artifact.rotate_selectionbox({
0.5, -0.5, -0.5,
6/16, 1.5, 0.5
}, e.rotation)
selectionbox = box,
collisionbox = table.copy(box)
}
end)
if not e._locked then
@ -102,14 +122,11 @@ minetest.register_entity(":artifact:door", {
e.object:set_animation({x=snap and 1 or 0.5,y=1}, 1.5, 0.1, false)
minetest.after(snap and 0 or 0.1, function()
local pos = e.object:get_pos():round()
local node = minetest.get_node(pos)
node.name = "door_"..e.type
minetest.swap_node(pos, node)
minetest.get_meta(pos):set_string("open", "false")
local box = artifact.rotate_selectionbox(e.box_closed_normal, e.rotation)
e.object:set_properties {
selectionbox = artifact.rotate_selectionbox({
-0.5, -0.5, -0.5,
0.5, 1.5, -6/16
}, e.rotation)
selectionbox = box,
collisionbox = box
}
end)
if not e._locked then
@ -118,8 +135,17 @@ minetest.register_entity(":artifact:door", {
end)
end
end,
invert = function(e)
e.inverted = true
local box = artifact.rotate_selectionbox(e.box_closed_normal, e.rotation)
e.object:set_properties {
mesh = "artifact_door_inverted.gltf",
selectionbox = box,
collisionbox = box
}
end,
get_staticdata = function(e)
return minetest.serialize{type = e.type, _locked = e._locked, rotation = e.rotation}
return minetest.serialize{type = e.type, _locked = e._locked, rotation = e.rotation, inverted = e.inverted}
end,
unlock = function(e)
if e._locked then
@ -129,11 +155,32 @@ minetest.register_entity(":artifact:door", {
end,
rotate = function(e, rot)
e.object:set_rotation(rot)
rot.y = rot.y -math.pi
e.rotation = rot
e.object:set_properties {
selectionbox = artifact.rotate_selectionbox(e.object:get_properties().selectionbox, e.rotation)
selectionbox = box
}
end,
on_whack = function(e)
if e.type == "wood" then
local pos = e.object:get_pos():round()
minetest.remove_node(pos)
minetest.add_particlespawner {
pos = {
min = pos:offset(-0.5, -0.5, -0.5),
max = pos:offset(0.5, 1.5, 0.5)
},
vel = {
min = vector.new(-1, 0, -1) *1.5,
max = vector.new(1, 2, 1) *1.5
},
acc = vector.new(0,-9.81,0),
collisiondetection = true,
amount = 50,
texture = "artifact_door_wood.png^[sheet:2x8:0,3",
time = 0.1
}
return true
end
end
})
@ -143,15 +190,11 @@ local function register_basic_door(type)
-- 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()
rot.y = rot.y -math.pi
local rot = artifact.facedir_to_rotation(minetest.get_node(pos).param2)
minetest.add_entity(pos, "artifact:door", minetest.serialize{type = type}):get_luaentity():rotate(rot)
end
end
local function ondestruct(pos, reason)
if reason == "whack" then
-- TODO: Particles
end
doors[pos:to_string()].object:remove()
doors[pos:to_string()] = nil
end
@ -176,16 +219,17 @@ local function register_basic_door(type)
end
end
artifact.register_node("door_"..type, {
drawtype = "nodebox",
node_box = {
drawtype = "airlike",
walkable = false,
selection_box = {
type = "fixed",
fixed = {
-0.5, -0.5, -0.5,
0.5, 1.5, -6/16
-0.5, -0.5, 0.5,
0.5, 1.5, 6/16
}
},
paramtype2 = "facedir",
tiles = {"blank.png"},
tiles = {"artifact_door_"..type..".png"},
use_texture_alpha = "clip",
paramtype = "light",
pointable = false,
@ -193,27 +237,22 @@ local function register_basic_door(type)
on_construct = onload,
on_destruct = ondestruct,
on_load = onload,
on_signal = onsignal
})
artifact.register_node("door_"..type.."_open", {
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
0.5, -0.5, -0.5,
6/16, 1.5, 0.5
}
},
paramtype2 = "facedir",
tiles = {"blank.png"},
use_texture_alpha = "clip",
paramtype = "light",
pointable = false,
groups = {call_on_load = 1, whackable = type == "wood" and 1 or nil},
on_construct = onload,
on_destruct = ondestruct,
on_load = onload,
on_signal = onsignal
on_signal = onsignal,
on_place = function(s, p, pt)
local out, pos = minetest.item_place_node(s, p, pt)
if artifact.players[p:get_player_name()].ctl.sneak then
minetest.get_meta(pos):set_string("inverted", "true")
doors[pos:to_string()]:invert()
end
return out
end,
on_rotate = function(pos, node, p, click, param2)
node.param2 = param2
minetest.swap_node(pos, node)
local rot = artifact.facedir_to_rotation(param2)
doors[pos:to_string()]:rotate(rot)
return true
end
})
end

View file

@ -96,6 +96,7 @@ if artifact.debug then
local link_colors = {
"gold",
"red",
"green",
"blue"
}
@ -171,7 +172,7 @@ if artifact.debug then
on_secondary_use = function(s, p, pt)
local m = s:get_meta()
-- Just cycle through the colors list.
local color = link_colors[(table.indexof(link_colors, m:get("color") or "gold") +1) %#link_colors +1]
local color = link_colors[table.indexof(link_colors, m:get("color") or "gold") %#link_colors +1]
m:set_string("color", color)
m:set_string("inventory_image", "[fill:16x16:0,0:"..color.."#00^artifact_linker_tool.png")
return s

View file

@ -0,0 +1,238 @@
local large_doors = {}
minetest.register_entity(":artifact:large_door_display", {
initial_properties = {
visual = "mesh",
mesh = "artifact_door_large.gltf",
textures = {"artifact_door_large.png"},
selectionbox = {
-1.5, -0.5, -2/16,
1.5, 2.5, 2/16
},
pointable = artifact.debug
},
on_activate = function(e, data)
local pos = e.object:get_pos():round()
local node = minetest.get_node(pos)
if not node.name:find "large_door" then
e.object:remove()
return
end
e.object:set_armor_groups{immortal = 1}
extend(e, minetest.deserialize(data) or {})
if e.rotation then
e.rotation.y = e.rotation.y +math.pi
e:rotate(e.rotation)
else
e.rotation = vector.zero()
end
e._name = ""..math.random()
if e._locked == nil then
e._locked = true
end
local nm = minetest.get_meta(e.object:get_pos())
if (node.name:find "_open") and not e._open then
e:open(true)
elseif not (node.name:find "_open") and e._open then
e:close(true)
end
-- In case our saved state differs from the node's stored state, e.g. if a trigger
-- updated an effector in an unloaded area and couldn't get at the display entity,
-- we should always be sure to match the node meta.
if nm:get_string("locked") == "true" then
e._locked = true
end
if nm:contains("locks") then
e.locks = minetest.deserialize(nm:get_string("locks"))
end
if e.locks then
e:set_locks(e.locks)
end
e.collider_a = minetest.add_entity(pos, "display")
e.collider_a:set_properties {
physical = true,
collisionbox = artifact.rotate_selectionbox({
-0.75, -1.5, -2/16,
0.75, 1.5, 2/16
}, e.rotation)
}
e.collider_a:set_attach(e.object, "a")
e.collider_b = minetest.add_entity(pos, "display")
e.collider_b:set_properties {
physical = true,
collisionbox = artifact.rotate_selectionbox({
-0.75, -1.5, -2/16,
0.75, 1.5, 2/16
}, e.rotation)
}
e.collider_b:set_attach(e.object, "b")
large_doors[e.object:get_pos():round():to_string()] = e
end,
on_deactivate = function(e)
large_doors[e.object:get_pos():round():to_string()] = nil
if e.collider_a then
e.collider_a:remove()
e.collider_a = nil
end
if e.collider_b then
e.collider_b:remove()
e.collider_b = nil
end
end,
get_staticdata = function(e)
return minetest.serialize{type = e.type, _locked = e._locked, rotation = e.rotation, locks = e.locks}
end,
open = function(e)
-- We're already open, so there's nothing to do.
if e._open then return end
e._open = true
e._animating = true
e.object:set_animation({x=0,y=1}, 1.25, 0.1, false)
local pos = e.object:get_pos():round()
minetest.get_meta(pos):set_string("open", "true")
minetest.after(0.75, function()
e._animating = nil
end)
end,
close = function(e)
if not e._open then return end
e._open = false
e._animating = true
e.object:set_animation({x=1,y=2}, 1.25, 0.1, false)
local pos = e.object:get_pos():round()
minetest.get_meta(pos):set_string("open", "false")
minetest.after(0.75, function()
e._animating = nil
end)
end,
on_step = function(e)
-- If we're locked or in a transition state, there's no need to run these checks.
if e._locked or e._animating then return end
-- We don't use objects_inside_radius to avoid wasting time finding and ignoring display entities.
-- Instead, we just do a radius check on each player.
local pos = e.object:get_pos()
local found = artifact.sidekick.pos and artifact.sidekick.pos:distance(pos) < 4
for _, m in pairs(artifact.players) do
if m.object:get_pos():distance(pos) < 4 then
found = true
break
end
end
if found and not e._open then
e:open()
elseif not found and e._open then
e:close()
end
end,
rotate = function(e, rot)
e.object:set_rotation(rot)
e.rotation = rot
e.object:set_properties {
selectionbox = artifact.rotate_selectionbox({
-1.5, -0.5, -2/16,
1.5, 2.5, 2/16
}, e.rotation)
}
if e.collider_a then
e.collider_a:set_properties {
collisionbox = artifact.rotate_selectionbox({
-0.75, -1.5, -2/16,
0.75, 1.5, 2/16
}, e.rotation)
}
end
if e.collider_b then
e.collider_b:set_properties {
collisionbox = artifact.rotate_selectionbox({
-0.75, -1.5, -2/16,
0.75, 1.5, 2/16
}, e.rotation)
}
end
end,
-- We include this so we can update the entity's locks without having to unload and reload them.
on_punch = function(e)
local locks = minetest.deserialize(minetest.get_meta(e.object:get_pos():round()):get_string("locks"))
e:set_locks(locks)
end,
set_locks = function(e, locks)
e.locks = locks
local mod = ""
local locked = false
for i, color in ipairs(locks) do
if not locks[color] then locked = true end
mod = mod..":"..((i -1) *5 +74)..",0=artifact_lock_"..color.."_"..(locks[color] and "on" or "off")..".png"
end
e._locked = locked
e.object:set_properties {
textures = {"[combine:128x128:0,0=artifact_door_large.png"..mod}
}
end,
})
local function onload(pos)
local m = minetest.get_meta(pos)
-- Dynamically initialize doors that were mapgen'd in.
if not m:contains("initialized") then
m:set_string("initialized", "true")
local rot = artifact.facedir_to_rotation(minetest.get_node(pos).param2)
local locks = {red = false, blue = false, green = false, "red", "green", "blue"}
minetest.add_entity(pos, "artifact:large_door_display", minetest.serialize{locks = locks}):get_luaentity():rotate(rot)
minetest.get_meta(pos):set_string("locks", minetest.serialize(locks))
end
end
local function ondestruct(pos)
large_doors[pos:to_string()].object:remove()
large_doors[pos:to_string()] = nil
end
local function onsignal(pos, event, channel)
if event.type == "on" or event.type == "pulse" then
local e = large_doors[vector.to_string(pos)]
if e then
local locks = e.locks
if locks[channel] ~= nil then
locks[channel] = true
end
e:set_locks(locks)
minetest.get_meta(pos):set_string("locks", minetest.serialize(locks))
else
local m = minetest.get_meta(pos)
local locks = minetest.deserialize(m:get_string("locks"))
if locks[channel] ~= nil then
locks[channel] = true
end
e:set_locks(locks)
m:set_string("locks", minetest.serialize(locks))
end
end
end
artifact.register_node("large_door", {
drawtype = "airlike",
paramtype = "light",
walkable = false,
selection_box = {
type = "fixed",
fixed = {
-1.5, -0.5, -2/16,
1.5, 3.5, 2/16
}
},
paramtype2 = "facedir",
groups = {call_on_load = 1},
on_construct = onload,
on_load = onload,
on_destruct = ondestruct,
on_signal = onsignal
})

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 178 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 120 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 120 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 B