Actions: Default doors and cottages' mod doors are fully supported now.
Default bed and cottages' mod beds fully supported now.
This commit is contained in:
parent
641bdd8874
commit
e69272c359
@ -342,20 +342,26 @@ function npc.actions.use_bed(self, pos, action)
|
||||
|
||||
if action == npc.actions.const.beds.LAY then
|
||||
-- Get position
|
||||
local bed_pos = npc.actions.nodes.beds[node.name].get_lay_pos(pos)
|
||||
local bed_pos = npc.actions.nodes.beds[node.name].get_lay_pos(pos, dir)
|
||||
-- Sit down on bed, rotate to correct direction
|
||||
npc.add_action(self, npc.actions.sit, {self=self, pos=bed_pos, dir=(node.param2 + 2) % 4})
|
||||
-- Lay down
|
||||
npc.add_action(self, npc.actions.lay, {self=self})
|
||||
else
|
||||
-- Calculate position to get up
|
||||
local bed_pos = {x = pos.x, y = pos.y + 1, z = pos.z}
|
||||
local bed_pos_y = npc.actions.nodes.beds[node.name].get_lay_pos(pos, dir).y
|
||||
local bed_pos = {x = pos.x, y = bed_pos_y, z = pos.z}
|
||||
-- Sit up
|
||||
npc.add_action(self, npc.actions.sit, {self=self, pos=bed_pos})
|
||||
-- Initialize direction: Default is front of bottom of bed
|
||||
local dir = (node.param2 + 2) % 4
|
||||
-- Find empty node around node
|
||||
local empty_nodes = npc.places.find_node_orthogonally(bed_pos, {"air", "cottages:bench"}, -1)
|
||||
-- Take into account that mats are close to the floor, so y adjustmen is zero
|
||||
local y_adjustment = -1
|
||||
if npc.actions.nodes.beds[node.name].type == "mat" then
|
||||
y_adjustment = 0
|
||||
end
|
||||
local empty_nodes = npc.places.find_node_orthogonally(bed_pos, {"air", "cottages:bench"}, y_adjustment)
|
||||
if empty_nodes ~= nil then
|
||||
-- Get direction to the empty node
|
||||
dir = npc.actions.get_direction(bed_pos, empty_nodes[1].pos)
|
||||
|
53
actions/node_registry.lua
Normal file
53
actions/node_registry.lua
Normal file
@ -0,0 +1,53 @@
|
||||
-- Node functionality registry for NPC actions by Zorman2000
|
||||
---------------------------------------------------------------------------------------
|
||||
-- In this script, some functionality and information required for nodes
|
||||
-- to be used correctly by an NPC is described.
|
||||
-- To avoid as many definitions as possible, the names of the nodes
|
||||
-- can actually be prefixes.
|
||||
|
||||
-- This table will contain the registered nodes
|
||||
npc.actions.nodes = {
|
||||
doors = {},
|
||||
beds = {},
|
||||
sittable = {}
|
||||
}
|
||||
|
||||
|
||||
---------------------------------------------------------------------------------------
|
||||
-- Beds functionality supported by default
|
||||
---------------------------------------------------------------------------------------
|
||||
-- Functionality for default beds. Since other mods may be used in the
|
||||
-- same way as the default beds, this one is a global registration
|
||||
npc.actions.nodes.default_bed_registration = {
|
||||
get_lay_pos = function(pos, dir)
|
||||
return {x = pos.x + dir.x / 2, y = pos.y + 1, z = pos.z + dir.z / 2}
|
||||
end,
|
||||
type = "bed"
|
||||
}
|
||||
|
||||
-- The code used in get_lay_pos is from cottages mod and slightly modified.
|
||||
local cottages_bed_registration = {
|
||||
get_lay_pos = function(pos, dir)
|
||||
return {x = pos.x + dir.x / 2, y = pos.y + 1.4, z = pos.z + dir.z / 2}
|
||||
end,
|
||||
type = "bed"
|
||||
}
|
||||
|
||||
local cottages_mat_registration = {
|
||||
get_lay_pos = function(pos, dir)
|
||||
return {x = pos.x + dir.x / 2, y = pos.y + 1, z = pos.z + dir.z / 2}
|
||||
end,
|
||||
type = "mat"
|
||||
}
|
||||
|
||||
---------------------------------------------------------------------------------------
|
||||
-- Beds
|
||||
---------------------------------------------------------------------------------------
|
||||
-- Default beds.
|
||||
npc.actions.nodes.beds["beds:bed_bottom"] = npc.actions.nodes.default_bed_registration
|
||||
npc.actions.nodes.beds["beds:fancy_bed_bottom"] = npc.actions.nodes.default_bed_registration
|
||||
|
||||
-- Cottages beds
|
||||
npc.actions.nodes.beds["cottages:bed_foot"] = cottages_bed_registration
|
||||
npc.actions.nodes.beds["cottages:sleeping_mat"] = cottages_mat_registration
|
||||
npc.actions.nodes.beds["cottages:straw_mat"] = cottages_mat_registration
|
@ -1,25 +0,0 @@
|
||||
-- Node functionality for actions by Zorman2000
|
||||
-- In this script, some functionality and information required for nodes
|
||||
-- to be used correctly by an NPC is described.
|
||||
|
||||
-- Attempt to keep a register of how to use some nodes
|
||||
npc.actions.nodes = {
|
||||
doors = {},
|
||||
beds = {},
|
||||
sittable = {}
|
||||
}
|
||||
|
||||
-- Register default beds. Always register bottom node only
|
||||
npc.actions.nodes.beds["beds:bed_bottom"] = {
|
||||
get_lay_pos = function(pos)
|
||||
return {x = pos.x + dir.x / 2, y = pos.y + 1, z = pos.z + dir.z / 2}
|
||||
end
|
||||
}
|
||||
|
||||
npc.actions.nodes.beds["beds:fancy_bed_bottom"] = {
|
||||
get_lay_pos = function(pos)
|
||||
return {x = pos.x + dir.x / 2, y = pos.y + 1, z = pos.z + dir.z / 2}
|
||||
end
|
||||
}
|
||||
|
||||
npc.actions.nodes.beds[""]
|
4
npc.lua
4
npc.lua
@ -350,7 +350,7 @@ local function npc_spawn(self, pos)
|
||||
ent.places_map = {}
|
||||
|
||||
-- Temporary initialization of actions for testing
|
||||
local nodes = npc.places.find_node_nearby(ent, {"beds:bed_bottom"}, 30)
|
||||
local nodes = npc.places.find_node_nearby(ent, {"beds:fancy_bed_bottom"}, 30)
|
||||
minetest.log("Found nodes: "..dump(nodes))
|
||||
|
||||
--local path = pathfinder.find_path(ent.object:getpos(), nodes[1], 20)
|
||||
@ -358,7 +358,7 @@ local function npc_spawn(self, pos)
|
||||
--npc.add_action(ent, npc.actions.use_door, {self = ent, pos = nodes[1], action = npc.actions.door_action.OPEN})
|
||||
--npc.add_action(ent, npc.actions.stand, {self = ent})
|
||||
--npc.add_action(ent, npc.actions.stand, {self = ent})
|
||||
npc.actions.walk_to_pos(ent, nodes[1], {"cottages:bench"})
|
||||
npc.actions.walk_to_pos(ent, nodes[1], {})
|
||||
npc.actions.use_bed(ent, nodes[1], npc.actions.const.beds.LAY)
|
||||
npc.add_action(ent, npc.actions.lay, {self = ent})
|
||||
-- npc.add_action(ent, npc.actions.lay, {self = ent})
|
||||
|
Loading…
Reference in New Issue
Block a user