forked from mtcontrib/maidroid
Update farming core
This commit is contained in:
parent
aae13499f1
commit
058665db83
@ -42,37 +42,36 @@ local function is_mowable_place(pos)
|
||||
return false
|
||||
end
|
||||
|
||||
do -- register farming core
|
||||
|
||||
local walk_randomly, walk_to_plant_and_mow_common, plant, mow
|
||||
local to_walk_randomly, to_walk_to_plant, to_walk_to_mow, to_plant, to_mow
|
||||
local walk_randomly, walk_to_plant_and_mow_common, plant, mow
|
||||
local to_walk_randomly, to_walk_to_plant, to_walk_to_mow, to_plant, to_mow
|
||||
|
||||
local function on_start(self)
|
||||
local function on_start(self)
|
||||
self.object:setacceleration{x = 0, y = -10, z = 0}
|
||||
self.object:setvelocity{x = 0, y = 0, z = 0}
|
||||
self.state = state.WALK_RANDOMLY
|
||||
self.time_counters = {}
|
||||
self.path = nil
|
||||
to_walk_randomly(self)
|
||||
end
|
||||
end
|
||||
|
||||
local function on_stop(self)
|
||||
local function on_stop(self)
|
||||
self.object:setvelocity{x = 0, y = 0, z = 0}
|
||||
self.state = nil
|
||||
self.time_counters = nil
|
||||
self.path = nil
|
||||
self:set_animation(maidroid.animation_frames.STAND)
|
||||
end
|
||||
end
|
||||
|
||||
local function is_near(self, pos, distance)
|
||||
local function is_near(self, pos, distance)
|
||||
local p = self.object:getpos()
|
||||
-- p.y = p.y + 0.5
|
||||
return vector.distance(p, pos) < distance
|
||||
end
|
||||
end
|
||||
|
||||
local searching_range = {x = 5, y = 2, z = 5}
|
||||
local searching_range = {x = 5, y = 2, z = 5}
|
||||
|
||||
walk_randomly = function(self, dtime)
|
||||
walk_randomly = function(self, dtime)
|
||||
if self.time_counters[1] >= FIND_PATH_TIME_INTERVAL then
|
||||
self.time_counters[1] = 0
|
||||
self.time_counters[2] = self.time_counters[2] + 1
|
||||
@ -121,17 +120,17 @@ do -- register farming core
|
||||
end
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
to_walk_randomly = function(self)
|
||||
to_walk_randomly = function(self)
|
||||
self.state = state.WALK_RANDOMLY
|
||||
self.time_counters[1] = 0
|
||||
self.time_counters[2] = 0
|
||||
self:change_direction_randomly()
|
||||
self:set_animation(maidroid.animation_frames.WALK)
|
||||
end
|
||||
end
|
||||
|
||||
to_walk_to_plant = function(self, path, destination)
|
||||
to_walk_to_plant = function(self, path, destination)
|
||||
self.state = state.WALK_TO_PLANT
|
||||
self.path = path
|
||||
self.destination = destination
|
||||
@ -139,9 +138,9 @@ do -- register farming core
|
||||
self.time_counters[2] = 0
|
||||
self:change_direction(self.path[1])
|
||||
self:set_animation(maidroid.animation_frames.WALK)
|
||||
end
|
||||
end
|
||||
|
||||
to_walk_to_mow = function(self, path, destination)
|
||||
to_walk_to_mow = function(self, path, destination)
|
||||
self.state = state.WALK_TO_MOW
|
||||
self.path = path
|
||||
self.destination = destination
|
||||
@ -149,9 +148,9 @@ do -- register farming core
|
||||
self.time_counters[2] = 0
|
||||
self:change_direction(self.path[1])
|
||||
self:set_animation(maidroid.animation_frames.WALK)
|
||||
end
|
||||
end
|
||||
|
||||
to_plant = function(self)
|
||||
to_plant = function(self)
|
||||
local wield_stack = self:get_wield_item_stack()
|
||||
if minetest.get_item_group(wield_stack:get_name(), "seed") > 0
|
||||
or self:move_main_to_wield(function(itemname) return (minetest.get_item_group(itemname, "seed") > 0) end) then
|
||||
@ -164,16 +163,16 @@ do -- register farming core
|
||||
to_walk_randomly(self)
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
to_mow = function(self)
|
||||
to_mow = function(self)
|
||||
self.state = state.MOW
|
||||
self.time_counters[1] = 0
|
||||
self.object:setvelocity{x = 0, y = 0, z = 0}
|
||||
self:set_animation(maidroid.animation_frames.MINE)
|
||||
end
|
||||
end
|
||||
|
||||
walk_to_plant_and_mow_common = function(self, dtime)
|
||||
walk_to_plant_and_mow_common = function(self, dtime)
|
||||
if is_near(self, self.destination, 1.5) then
|
||||
if self.state == state.WALK_TO_PLANT then
|
||||
to_plant(self)
|
||||
@ -231,9 +230,9 @@ do -- register farming core
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
plant = function(self, dtime)
|
||||
plant = function(self, dtime)
|
||||
if self.time_counters[1] >= 15 then
|
||||
if is_plantable_place(self.destination) then
|
||||
local stack = self:get_wield_item_stack()
|
||||
@ -247,9 +246,9 @@ do -- register farming core
|
||||
else
|
||||
self.time_counters[1] = self.time_counters[1] + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
mow = function(self, dtime)
|
||||
mow = function(self, dtime)
|
||||
if self.time_counters[1] >= 15 then
|
||||
if is_mowable_place(self.destination) then
|
||||
local destnode = minetest.get_node(self.destination)
|
||||
@ -266,9 +265,9 @@ do -- register farming core
|
||||
else
|
||||
self.time_counters[1] = self.time_counters[1] + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function on_step(self, dtime)
|
||||
local function on_step(self, dtime)
|
||||
if self.state == state.WALK_RANDOMLY then
|
||||
walk_randomly(self, dtime)
|
||||
elseif self.state == state.WALK_TO_PLANT or self.state == state.WALK_TO_MOW then
|
||||
@ -278,9 +277,9 @@ do -- register farming core
|
||||
elseif self.state == state.MOW then
|
||||
mow(self, dtime)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
maidroid.register_core("maidroid_core:farming", {
|
||||
maidroid.register_core("maidroid_core:farming", {
|
||||
description = "maidroid core : farming",
|
||||
inventory_image = "maidroid_core_farming.png",
|
||||
on_start = on_start,
|
||||
@ -288,6 +287,4 @@ do -- register farming core
|
||||
on_resume = on_start,
|
||||
on_pause = on_stop,
|
||||
on_step = on_step,
|
||||
})
|
||||
|
||||
end -- register farming core
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user