Add chests, doors, and levers, and improve progressive interaction.

This commit is contained in:
Signal 2025-11-11 01:29:41 -05:00
parent 6439f11c2f
commit 8f98a7fa2d
18 changed files with 692 additions and 107 deletions

View file

@ -1,14 +1,94 @@
local function make_lever_entity(pos)
end
local levers = {}
minetest.register_entity(":artifact:lever_display", {
initial_properties = {
visual = "mesh",
mesh = "artifact_lever.gltf",
textures = {"artifact_lever_wood.png"},
seelctionbox = {
}
},
_interact_time = 0.3,
_interact_marker_offset = function(e)
return vector.new(0, -0.4, 0):rotate(e.rotation)
end,
on_activate = function(e, data)
if not minetest.get_node(e.object:get_pos()).name:find "lever" then
e.object:remove()
return
end
e.object:set_armor_groups{immortal = 1}
extend(e, minetest.deserialize(data) or {})
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}
end,
on_interact = function(e)
if e._active then
e._active = false
e._no_interact = true
e.object:set_animation({x=1,y=2}, 2, 0.1, false)
minetest.after(0.5, function()
e._no_interact = nil
end)
else
e._active = true
e._no_interact = true
e.object:set_animation({x=0,y=1}, 2, 0.1, false)
minetest.after(0.5, function()
e._no_interact = nil
end)
end
end,
rotate = function(e, rot)
e.object:set_rotation(rot)
e.rotation = rot
e.object:set_properties {
selectionbox = artifact.rotate_selectionbox({
-3/16, -0.5, -4/16,
3/16, -3/16, 4/16
}, e.rotation)
}
end
})
artifact.register_node("lever", {
drawtype = "airlike",
paramtype = "light",
sunlight_propagates = true,
paramtype2 = "facedir",
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)
end,
on_destruct = function(pos)
levers[pos:to_string()].object:remove()
levers[pos:to_string()] = nil
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 = 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)
end
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()
levers[pos:to_string()]:rotate(rot)
return true
end
})