Add multi-signal doors, basic device deployment, and a target trigger.
This commit is contained in:
parent
1b2199705b
commit
3bf1d5c6a0
24 changed files with 656 additions and 74 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue