moved dig state
parent
21bd5fc6bc
commit
5e1101d4be
|
@ -62,9 +62,25 @@ function working_villages.villager:go_to(pos)
|
|||
end
|
||||
|
||||
function working_villages.villager:dig(pos)
|
||||
self.target = pos
|
||||
self:set_state("dig_target")
|
||||
coroutine.yield()
|
||||
self.object:setvelocity{x = 0, y = 0, z = 0}
|
||||
self:set_animation(working_villages.animation_frames.MINE)
|
||||
self:set_yaw_by_direction(vector.subtract(pos, self.object:getpos()))
|
||||
for _=0,30 do coroutine.yield() end --wait 30 steps
|
||||
local destnode = minetest.get_node(pos)
|
||||
minetest.remove_node(pos)
|
||||
local stacks = minetest.get_node_drops(destnode.name)
|
||||
for _, stack in ipairs(stacks) do
|
||||
local leftover = self:add_item_to_main(stack)
|
||||
minetest.add_item(pos, leftover)
|
||||
end
|
||||
local sounds = minetest.registered_nodes[destnode.name].sounds
|
||||
if sounds then
|
||||
local sound = sounds.dug
|
||||
if sound then
|
||||
minetest.sound_play(sound,{object=self.object, max_hear_distance = 10})
|
||||
end
|
||||
end
|
||||
self:set_animation(working_villages.animation_frames.STAND)
|
||||
end
|
||||
|
||||
function working_villages.villager:place(itemname,pos)
|
||||
|
|
|
@ -64,6 +64,39 @@ working_villages.register_state("goto_dest",{
|
|||
end
|
||||
})
|
||||
|
||||
working_villages.register_state("dig_target",{
|
||||
on_start = function(self)
|
||||
self:set_timer("dig_target:animation",0)
|
||||
self.object:setvelocity{x = 0, y = 0, z = 0}
|
||||
self:set_animation(working_villages.animation_frames.MINE)
|
||||
self:set_yaw_by_direction(vector.subtract(self.target, self.object:getpos()))
|
||||
end,
|
||||
on_step = function(self)
|
||||
if self:timer_exceeded("dig_target:animation",30) then
|
||||
local destnode = minetest.get_node(self.target)
|
||||
minetest.remove_node(self.target)
|
||||
local stacks = minetest.get_node_drops(destnode.name)
|
||||
for _, stack in ipairs(stacks) do
|
||||
local leftover = self:add_item_to_main(stack)
|
||||
minetest.add_item(self.target, leftover)
|
||||
end
|
||||
local sounds = minetest.registered_nodes[destnode.name].sounds
|
||||
if sounds then
|
||||
local sound = sounds.dug
|
||||
if sound then
|
||||
minetest.sound_play(sound,{object=self.object, max_hear_distance = 10})
|
||||
end
|
||||
end
|
||||
self:set_state("job")
|
||||
else
|
||||
self:count_timer("dig_target:animation")
|
||||
end
|
||||
end,
|
||||
on_finish = function(self)
|
||||
self:set_animation(working_villages.animation_frames.STAND)
|
||||
end
|
||||
})
|
||||
|
||||
local func = working_villages.func
|
||||
|
||||
function working_villages.func.villager_state_machine_job(job_name,job_description,actions, sprop)
|
||||
|
|
33
states.lua
33
states.lua
|
@ -26,39 +26,6 @@ working_villages.register_state("job",{
|
|||
end
|
||||
})
|
||||
|
||||
working_villages.register_state("dig_target",{
|
||||
on_start = function(self)
|
||||
self:set_timer("dig_target:animation",0)
|
||||
self.object:setvelocity{x = 0, y = 0, z = 0}
|
||||
self:set_animation(working_villages.animation_frames.MINE)
|
||||
self:set_yaw_by_direction(vector.subtract(self.target, self.object:getpos()))
|
||||
end,
|
||||
on_step = function(self)
|
||||
if self:timer_exceeded("dig_target:animation",30) then
|
||||
local destnode = minetest.get_node(self.target)
|
||||
minetest.remove_node(self.target)
|
||||
local stacks = minetest.get_node_drops(destnode.name)
|
||||
for _, stack in ipairs(stacks) do
|
||||
local leftover = self:add_item_to_main(stack)
|
||||
minetest.add_item(self.target, leftover)
|
||||
end
|
||||
local sounds = minetest.registered_nodes[destnode.name].sounds
|
||||
if sounds then
|
||||
local sound = sounds.dug
|
||||
if sound then
|
||||
minetest.sound_play(sound,{object=self.object, max_hear_distance = 10})
|
||||
end
|
||||
end
|
||||
self:set_state("job")
|
||||
else
|
||||
self:count_timer("dig_target:animation")
|
||||
end
|
||||
end,
|
||||
on_finish = function(self)
|
||||
self:set_animation(working_villages.animation_frames.STAND)
|
||||
end
|
||||
})
|
||||
|
||||
working_villages.register_state("place_wield", {
|
||||
on_start = function(self)
|
||||
if type(self.target)~="table" then
|
||||
|
|
Loading…
Reference in New Issue