|
|
|
@ -44,6 +44,7 @@ if redo then
|
|
|
|
|
{"farming:barley_7", nil},
|
|
|
|
|
{"farming:oat_8", nil},
|
|
|
|
|
{"farming:rice_8", nil},
|
|
|
|
|
{"farming:rye_8", nil},
|
|
|
|
|
{"farming:blueberry_4", "farming:blueberries", "farming:blueberry"},
|
|
|
|
|
{"farming:carrot_8", nil},
|
|
|
|
|
{"farming:coffee_5", "farming:coffee_beans", "farming:coffee"},
|
|
|
|
@ -63,6 +64,7 @@ if redo then
|
|
|
|
|
{"farming:pea_5", "farming:pea_pod", "farming:pea"},
|
|
|
|
|
{"farming:pepper_5", "farming:peppercorn", "farming:pepper"},
|
|
|
|
|
{"farming:pineapple_8", "farming:pineapple_top", "farming:pineapple"},
|
|
|
|
|
{"farming:mint_4", nil},
|
|
|
|
|
}
|
|
|
|
|
for _, item in pairs(redo_plants) do
|
|
|
|
|
table.insert(target_plants, item[1])
|
|
|
|
@ -132,8 +134,8 @@ 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)
|
|
|
|
|
self.object:setacceleration{x = 0, y = -10, z = 0}
|
|
|
|
|
self.object:setvelocity{x = 0, y = 0, z = 0}
|
|
|
|
|
self.object:set_acceleration{x = 0, y = -10, z = 0}
|
|
|
|
|
self.object:set_velocity{x = 0, y = 0, z = 0}
|
|
|
|
|
self.state = state.WALK_RANDOMLY
|
|
|
|
|
self.time_counters = {}
|
|
|
|
|
self.path = nil
|
|
|
|
@ -141,7 +143,7 @@ local function on_start(self)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function on_stop(self)
|
|
|
|
|
self.object:setvelocity{x = 0, y = 0, z = 0}
|
|
|
|
|
self.object:set_velocity{x = 0, y = 0, z = 0}
|
|
|
|
|
self.state = nil
|
|
|
|
|
self.time_counters = nil
|
|
|
|
|
self.path = nil
|
|
|
|
@ -149,7 +151,7 @@ local function on_stop(self)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function is_near(self, pos, distance)
|
|
|
|
|
local p = self.object:getpos()
|
|
|
|
|
local p = self.object:get_pos()
|
|
|
|
|
-- p.y = p.y + 0.5
|
|
|
|
|
return vector.distance(p, pos) < distance
|
|
|
|
|
end
|
|
|
|
@ -164,9 +166,9 @@ walk_randomly = function(self, dtime)
|
|
|
|
|
local wield_stack = self:get_wield_item_stack()
|
|
|
|
|
if minetest.get_item_group(wield_stack:get_name(), "seed") > 0
|
|
|
|
|
or self:has_item_in_main(function(itemname) return (minetest.get_item_group(itemname, "seed") > 0) end) then
|
|
|
|
|
local destination = _aux.search_surrounding(self.object:getpos(), is_plantable_place, searching_range)
|
|
|
|
|
local destination = _aux.search_surrounding(self.object:get_pos(), is_plantable_place, searching_range)
|
|
|
|
|
if destination ~= nil then
|
|
|
|
|
local path = minetest.find_path(self.object:getpos(), destination, 10, 1, 1, "A*")
|
|
|
|
|
local path = minetest.find_path(self.object:get_pos(), destination, 10, 1, 1, "A*")
|
|
|
|
|
|
|
|
|
|
if path ~= nil then -- to walk to plant state.
|
|
|
|
|
to_walk_to_plant(self, path, destination)
|
|
|
|
@ -175,9 +177,9 @@ walk_randomly = function(self, dtime)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
-- if couldn't find path to plant, try to mow.
|
|
|
|
|
local destination = _aux.search_surrounding(self.object:getpos(), is_mowable_place, searching_range)
|
|
|
|
|
local destination = _aux.search_surrounding(self.object:get_pos(), is_mowable_place, searching_range)
|
|
|
|
|
if destination ~= nil then
|
|
|
|
|
local path = minetest.find_path(self.object:getpos(), destination, 10, 1, 1, "A*")
|
|
|
|
|
local path = minetest.find_path(self.object:get_pos(), destination, 10, 1, 1, "A*")
|
|
|
|
|
if path ~= nil then -- to walk to mow state.
|
|
|
|
|
to_walk_to_mow(self, path, destination)
|
|
|
|
|
return
|
|
|
|
@ -195,7 +197,7 @@ walk_randomly = function(self, dtime)
|
|
|
|
|
self.time_counters[1] = self.time_counters[1] + 1
|
|
|
|
|
self.time_counters[2] = self.time_counters[2] + 1
|
|
|
|
|
|
|
|
|
|
local velocity = self.object:getvelocity()
|
|
|
|
|
local velocity = self.object:get_velocity()
|
|
|
|
|
if velocity.y == 0 then
|
|
|
|
|
local front_node = self:get_front_node()
|
|
|
|
|
|
|
|
|
@ -205,7 +207,7 @@ walk_randomly = function(self, dtime)
|
|
|
|
|
|
|
|
|
|
-- elseif front_node.name ~= "air" and minetest.registered_nodes[front_node.name] ~= nil
|
|
|
|
|
-- and minetest.registered_nodes[front_node.name].walkable then
|
|
|
|
|
-- self.object:setvelocity{x = velocity.x, y = 6, z = velocity.z}
|
|
|
|
|
-- self.object:set_velocity{x = velocity.x, y = 6, z = velocity.z}
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return
|
|
|
|
@ -246,9 +248,9 @@ to_plant = function(self)
|
|
|
|
|
or self:move_main_to_wield(function(itemname) return (minetest.get_item_group(itemname, "seed") > 0) end) then
|
|
|
|
|
self.state = state.PLANT
|
|
|
|
|
self.time_counters[1] = 0
|
|
|
|
|
self.object:setvelocity{x = 0, y = 0, z = 0}
|
|
|
|
|
self.object:set_velocity{x = 0, y = 0, z = 0}
|
|
|
|
|
self:set_animation(maidroid.animation_frames.MINE)
|
|
|
|
|
self:set_yaw_by_direction(vector.subtract(self.destination, self.object:getpos()))
|
|
|
|
|
self:set_yaw_by_direction(vector.subtract(self.destination, self.object:get_pos()))
|
|
|
|
|
return
|
|
|
|
|
else
|
|
|
|
|
to_walk_randomly(self)
|
|
|
|
@ -259,9 +261,9 @@ end
|
|
|
|
|
to_mow = function(self)
|
|
|
|
|
self.state = state.MOW
|
|
|
|
|
self.time_counters[1] = 0
|
|
|
|
|
self.object:setvelocity{x = 0, y = 0, z = 0}
|
|
|
|
|
self.object:set_velocity{x = 0, y = 0, z = 0}
|
|
|
|
|
self:set_animation(maidroid.animation_frames.MINE)
|
|
|
|
|
self:set_yaw_by_direction(vector.subtract(self.destination, self.object:getpos()))
|
|
|
|
|
self:set_yaw_by_direction(vector.subtract(self.destination, self.object:get_pos()))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
walk_to_plant_and_mow_common = function(self, dtime)
|
|
|
|
@ -285,7 +287,7 @@ walk_to_plant_and_mow_common = function(self, dtime)
|
|
|
|
|
|
|
|
|
|
if self.time_counters[1] >= FIND_PATH_TIME_INTERVAL then
|
|
|
|
|
self.time_counters[1] = 0
|
|
|
|
|
local path = minetest.find_path(self.object:getpos(), self.destination, 10, 1, 1, "A*")
|
|
|
|
|
local path = minetest.find_path(self.object:get_pos(), self.destination, 10, 1, 1, "A*")
|
|
|
|
|
if path == nil then
|
|
|
|
|
to_walk_randomly(self)
|
|
|
|
|
return
|
|
|
|
@ -311,13 +313,13 @@ walk_to_plant_and_mow_common = function(self, dtime)
|
|
|
|
|
|
|
|
|
|
-- else
|
|
|
|
|
-- -- if maidroid is stopped by obstacles, the maidroid must jump.
|
|
|
|
|
-- local velocity = self.object:getvelocity()
|
|
|
|
|
-- local velocity = self.object:get_velocity()
|
|
|
|
|
-- if velocity.y == 0 then
|
|
|
|
|
-- local front_node = self:get_front_node()
|
|
|
|
|
-- if front_node.name ~= "air" and minetest.registered_nodes[front_node.name] ~= nil
|
|
|
|
|
-- and minetest.registered_nodes[front_node.name].walkable
|
|
|
|
|
-- and not (minetest.get_item_group(front_node.name, "fence") > 0) then
|
|
|
|
|
-- self.object:setvelocity{x = velocity.x, y = 6, z = velocity.z}
|
|
|
|
|
-- self.object:set_velocity{x = velocity.x, y = 6, z = velocity.z}
|
|
|
|
|
-- end
|
|
|
|
|
-- end
|
|
|
|
|
end
|
|
|
|
@ -334,28 +336,28 @@ plant = function(self, dtime)
|
|
|
|
|
under = vector.add(self.destination, {x = 0, y = -1, z = 0}),
|
|
|
|
|
above = self.destination,
|
|
|
|
|
}
|
|
|
|
|
if redo or plus then
|
|
|
|
|
|
|
|
|
|
if redo or plus then
|
|
|
|
|
local t = string.split(itemname, "seed_")
|
|
|
|
|
if t[2] then
|
|
|
|
|
local newstackname = t[1]..t[2].."_1"
|
|
|
|
|
stack = farming.place_seed(stack, minetest.get_player_by_name(self.owner_name), pointed_thing, newstackname)
|
|
|
|
|
itemname = t[1]..t[2].."_1"
|
|
|
|
|
elseif minetest.get_item_group(itemname, "redo") == 1 then
|
|
|
|
|
if seed_plants[itemname] then
|
|
|
|
|
itemname = seed_plants[itemname]
|
|
|
|
|
end
|
|
|
|
|
stack = farming.place_seed(stack, minetest.get_player_by_name(self.owner_name), pointed_thing, itemname.."_1")
|
|
|
|
|
itemname = itemname.."_1"
|
|
|
|
|
elseif minetest.get_item_group(itemname, "plus") == 1 then
|
|
|
|
|
stack = farming.place_seed(stack, minetest.get_player_by_name(self.owner_name), pointed_thing,
|
|
|
|
|
string.split(itemname, "_seed")[1].."_1")
|
|
|
|
|
else
|
|
|
|
|
stack = farming.place_seed(stack, minetest.get_player_by_name(self.owner_name), pointed_thing, itemname)
|
|
|
|
|
itemname = string.split(itemname, "_seed")[1].."_1"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if not stack or not itemname or not minetest.registered_nodes[itemname] then
|
|
|
|
|
to_walk_randomly(self)
|
|
|
|
|
return
|
|
|
|
|
else
|
|
|
|
|
farming.place_seed(stack, minetest.get_player_by_name(self.owner_name), pointed_thing, itemname)
|
|
|
|
|
stack = farming.place_seed(stack, minetest.get_player_by_name(self.owner_name), pointed_thing, itemname)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
stack:take_item(1)
|
|
|
|
|
if plus then stack:take_item(1) end
|
|
|
|
|
self:set_wield_item_stack(stack)
|
|
|
|
|
end
|
|
|
|
|
to_walk_randomly(self)
|
|
|
|
|