Add farming_redo and farming_plus compatibility
Add maidroid_core dependence and compatibility Add README.md
This commit is contained in:
parent
b417847147
commit
fa82ad69aa
58
README.md
Normal file
58
README.md
Normal file
@ -0,0 +1,58 @@
|
||||
# morefarming
|
||||
by sys4
|
||||
|
||||
A Minetest mod that extend the default farming mod of minetest_game
|
||||
|
||||
This mod add more things to do farming, make it more realistic, more harder and make it compatible with maidroid core farming.
|
||||
|
||||
Dependencies:
|
||||
- moreflowers, by me (https://github.com/sys4-fr/moreflowers)
|
||||
- farming
|
||||
- farming_redo, by TenPlus1 (optional)
|
||||
- farming_plus, by PilzAdam (optional)
|
||||
- maidroid_core, by tacigar (optional)
|
||||
|
||||
Why another farming mod ?
|
||||
1- I want to have a more realistic farming mod because when you spawn into a blank world, i think it's a non-sense if you found "domestic" vegetables wich already populate the world IMHO.
|
||||
2- So, it's your own work to make your "domestic" vegetables in a slow process of natural selection from harvested seed originate from wild homolog plant.
|
||||
3- The other existing farming mods (farming_plus, farming_redo) seems to not use the original farming library provided by MT_game (keep in mind I respect this choice). This implies possible incompatibilities with mods that uses original farming mod (ie: maidroid).
|
||||
4- Anyway i don't criticize the other farming mods (I still use it, even I maked it compatible with this mod), but i wanted to do a mod with a different way of looking at things.
|
||||
|
||||
General way of utilization:
|
||||
1- First of all, found and harvest a wild plant or flower.
|
||||
2- With more or less chance, you can get seeds of this plant.
|
||||
3- Plant the seeds into a tilled soil.
|
||||
4- Leave your plant growing up until maturity.
|
||||
5- Harvest it.
|
||||
6- If you have chance, you can get seeds from the "domestic" counterpart vegetable (rarely) else you get seeds of the original wild plant (by chance too, but more often) or the wild plant herself (the most often) or a rustic vegetable (by chance) or a mix of this items with a maximum of 3 items at once.
|
||||
7- Repeat from point 1 (or 3, depending what you get)
|
||||
|
||||
A concrete example with Wild carrot:
|
||||
1- Found a wild carrot flower and harvest it until you get seeds.
|
||||
2- Plant the seeds in a tilled soil (as if you plant wheat seeds).
|
||||
3- Leave your plant growing up until maturity.
|
||||
4- Harvest it and suppose you get in return only the original wild plant,
|
||||
5- re-plant it and harvest it until you get seeds again,
|
||||
6- (Repeat from 2 to 3)
|
||||
7- Harvest it and this time you get a rustic vegetable (a wild carrot with plenty of roots) and seeds but this time this seeds seems to be different (except if farming_redo is loaded without farming_plus, if this is the case you get directly a carrot).
|
||||
8- You eat your wild carrot but his nutritional power is very weak so,
|
||||
9- with your new seeds (or carrot from farming_redo) repeat from 2 to 3,
|
||||
10- Oh! you harvest a beautiful carrot and in addition you get the same different seeds ! (or carrots from farming_redo)
|
||||
11- Good you have a new variety of carrots, you taste it and you realize that his nutritional power is much better than the wild version.
|
||||
|
||||
For now this mod add:
|
||||
- Wild Carrot
|
||||
- Carrot (domestic)
|
||||
- Golden Carrot
|
||||
|
||||
Behaviour with optional mods loaded (for now):
|
||||
- farming_redo: Domestic and golden carrots are provided by farming_redo. There is no carrot seeds.
|
||||
- farming_plus: Domestic carrots and carrots seeds are provided by farming_plus.
|
||||
- farming_redo and farming_plus together: Domestic carrots and carrots seeds provided by farming_plus, golden carrot by farming_redo.
|
||||
- maidroid_core: The core farming was modified so that your robot has ability to harvest and plant wild carrots (flowers and seeds) and domestic carrots.
|
||||
WARNING: If farming_redo or farming_plus is loaded then maidroid_core will not load due to incompatibility.
|
||||
|
||||
LICENCES:
|
||||
- Code: GPLv3
|
||||
- Code of maidroid_core_morefarming.lua: GPLv2.1+
|
||||
- Textures: WTFPL v2
|
@ -1,2 +1,4 @@
|
||||
moreflowers
|
||||
farming
|
||||
farming_plus?
|
||||
maidroid_core?
|
||||
|
95
init.lua
95
init.lua
@ -1,3 +1,11 @@
|
||||
--------------------------------------------------------------------------------
|
||||
-- morefarming mod
|
||||
-- by sys4
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
local redo = farming.mod and farming.mod == "redo"
|
||||
local plus = minetest.get_modpath("farming_plus")
|
||||
|
||||
-- Wild carrot
|
||||
minetest.override_item("moreflowers:wild_carrot", {
|
||||
drop = {
|
||||
@ -18,12 +26,16 @@ farming.register_plant("morefarming:wild_carrot", {
|
||||
groups = {flammable = 4},
|
||||
})
|
||||
|
||||
local carrot_seed = "morefarming:seed_carrot"
|
||||
if redo then carrot_seed = "farming:carrot" end
|
||||
if plus then carrot_seed = "farming_plus:carrot_seed" end
|
||||
|
||||
minetest.override_item("morefarming:wild_carrot_8", {
|
||||
drop = {
|
||||
max_items = 3,
|
||||
items = {
|
||||
{ items = {"morefarming:seed_wild_carrot"}, rarity = 6},
|
||||
{ items = {"morefarming:seed_carrot"}, rarity = 8},
|
||||
{ items = {carrot_seed}, rarity = 8},
|
||||
{ items = {"morefarming:wild_carrot"}, rarity = 2},
|
||||
{ items = {"moreflowers:wild_carrot"}},
|
||||
}
|
||||
@ -33,35 +45,56 @@ minetest.override_item("morefarming:wild_carrot", {
|
||||
on_use = minetest.item_eat(1)
|
||||
})
|
||||
|
||||
-- Carrot
|
||||
farming.register_plant("morefarming:carrot", {
|
||||
description = "Carrot seed",
|
||||
paramtype2 = "meshoptions",
|
||||
inventory_image = "morefarming_carrot_seed.png",
|
||||
steps = 8,
|
||||
minlight = 13,
|
||||
maxlight = default.LIGHT_MAX,
|
||||
fertility = {"grassland"},
|
||||
groups = {flammable = 4},
|
||||
place_param2 = 3,
|
||||
})
|
||||
if not redo and not plus then
|
||||
-- Carrot
|
||||
farming.register_plant("morefarming:carrot", {
|
||||
description = "Carrot seed",
|
||||
paramtype2 = "meshoptions",
|
||||
inventory_image = "morefarming_carrot_seed.png",
|
||||
steps = 8,
|
||||
minlight = 13,
|
||||
maxlight = default.LIGHT_MAX,
|
||||
fertility = {"grassland"},
|
||||
groups = {flammable = 4},
|
||||
place_param2 = 3,
|
||||
})
|
||||
|
||||
minetest.override_item("morefarming:carrot", {
|
||||
on_use = minetest.item_eat(4)
|
||||
})
|
||||
end
|
||||
|
||||
minetest.override_item("morefarming:carrot", {
|
||||
on_use = minetest.item_eat(4)
|
||||
})
|
||||
local carrot_item = "morefarming:carrot"
|
||||
if plus then carrot_item = "farming_plus:carrot_item" end
|
||||
|
||||
-- golden carrot
|
||||
minetest.register_craftitem("morefarming:carrot_gold", {
|
||||
description = "Golden Carrot",
|
||||
inventory_image = "morefarming_carrot_gold.png",
|
||||
on_use = minetest.item_eat(6),
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "morefarming:carrot_gold",
|
||||
recipe = {
|
||||
{"", "default:gold_lump", ""},
|
||||
{"default:gold_lump", "morefarming:carrot", "default:gold_lump"},
|
||||
{"", "default:gold_lump", ""},
|
||||
}
|
||||
})
|
||||
if not redo then
|
||||
-- golden carrot
|
||||
minetest.register_craftitem("morefarming:carrot_gold", {
|
||||
description = "Golden Carrot",
|
||||
inventory_image = "morefarming_carrot_gold.png",
|
||||
on_use = minetest.item_eat(6),
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "morefarming:carrot_gold",
|
||||
recipe = {
|
||||
{"", "default:gold_lump", ""},
|
||||
{"default:gold_lump", carrot_item, "default:gold_lump"},
|
||||
{"", "default:gold_lump", ""},
|
||||
}
|
||||
})
|
||||
elseif plus then
|
||||
minetest.register_craft({
|
||||
output = "farming:carrot_gold",
|
||||
recipe = {
|
||||
{"", "default:gold_lump", ""},
|
||||
{"default:gold_lump", carrot_item, "default:gold_lump"},
|
||||
{"", "default:gold_lump", ""},
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
if not redo and not plus and minetest.get_modpath("maidroid_core") then
|
||||
minetest.registered_items["moreflowers:wild_carrot"].groups["seed"] = 1
|
||||
dofile(minetest.get_modpath("morefarming").."/maidroid_core_morefarming.lua")
|
||||
end
|
||||
|
304
maidroid_core_morefarming.lua
Normal file
304
maidroid_core_morefarming.lua
Normal file
@ -0,0 +1,304 @@
|
||||
------------------------------------------------------------
|
||||
-- Copyright (c) 2016 tacigar. All rights reserved.
|
||||
-- https://github.com/tacigar/maidroid
|
||||
------------------------------------------------------------
|
||||
-- Modified file by sys4 for morefarming mod
|
||||
------------------------------------------------------------
|
||||
|
||||
local state = {
|
||||
WALK_RANDOMLY = 0,
|
||||
WALK_TO_PLANT = 1,
|
||||
WALK_TO_MOW = 2,
|
||||
PLANT = 3,
|
||||
MOW = 4,
|
||||
}
|
||||
|
||||
local target_plants = {
|
||||
"farming:wheat_8",
|
||||
"farming:cotton_8",
|
||||
"moreflowers:wild_carrot",
|
||||
"morefarming:wild_carrot_8",
|
||||
"morefarming:carrot_8",
|
||||
}
|
||||
|
||||
local _aux = maidroid_core._aux
|
||||
|
||||
local FIND_PATH_TIME_INTERVAL = 20
|
||||
local CHANGE_DIRECTION_TIME_INTERVAL = 30
|
||||
local MAX_WALK_TIME = 120
|
||||
|
||||
-- is_plantable_place reports whether maidroid can plant any seed.
|
||||
local function is_plantable_place(pos)
|
||||
local node = minetest.get_node(pos)
|
||||
local lpos = vector.add(pos, {x = 0, y = -1, z = 0})
|
||||
local lnode = minetest.get_node(lpos)
|
||||
return node.name == "air"
|
||||
and minetest.get_item_group(lnode.name, "soil") > 1
|
||||
end
|
||||
|
||||
-- is_mowable_place reports whether maidroid can mow.
|
||||
local function is_mowable_place(pos)
|
||||
local node = minetest.get_node(pos)
|
||||
for _, plant in ipairs(target_plants) do
|
||||
if plant == node.name then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
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.state = state.WALK_RANDOMLY
|
||||
self.time_counters = {}
|
||||
self.path = nil
|
||||
to_walk_randomly(self)
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
local searching_range = {x = 5, y = 2, z = 5}
|
||||
|
||||
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
|
||||
|
||||
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)
|
||||
if destination ~= nil then
|
||||
local path = minetest.find_path(self.object:getpos(), destination, 10, 1, 1, "A*")
|
||||
|
||||
if path ~= nil then -- to walk to plant state.
|
||||
to_walk_to_plant(self, path, destination)
|
||||
return
|
||||
end
|
||||
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)
|
||||
if destination ~= nil then
|
||||
local path = minetest.find_path(self.object:getpos(), destination, 10, 1, 1, "A*")
|
||||
if path ~= nil then -- to walk to mow state.
|
||||
to_walk_to_mow(self, path, destination)
|
||||
return
|
||||
end
|
||||
end
|
||||
-- else do nothing.
|
||||
return
|
||||
|
||||
elseif self.time_counters[2] >= CHANGE_DIRECTION_TIME_INTERVAL then
|
||||
self.time_counters[1] = self.time_counters[1] + 1
|
||||
self.time_counters[2] = 0
|
||||
self:change_direction_randomly()
|
||||
return
|
||||
else
|
||||
self.time_counters[1] = self.time_counters[1] + 1
|
||||
self.time_counters[2] = self.time_counters[2] + 1
|
||||
|
||||
local velocity = self.object:getvelocity()
|
||||
if velocity.y == 0 then
|
||||
local front_node = self:get_front_node()
|
||||
|
||||
if minetest.get_item_group(front_node.name, "fence") > 0 then
|
||||
self:change_direction_randomly()
|
||||
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}
|
||||
end
|
||||
end
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
to_walk_to_plant = function(self, path, destination)
|
||||
self.state = state.WALK_TO_PLANT
|
||||
self.path = path
|
||||
self.destination = destination
|
||||
self.time_counters[1] = 0 -- find path interval
|
||||
self.time_counters[2] = 0
|
||||
self:change_direction(self.path[1])
|
||||
self:set_animation(maidroid.animation_frames.WALK)
|
||||
end
|
||||
|
||||
to_walk_to_mow = function(self, path, destination)
|
||||
self.state = state.WALK_TO_MOW
|
||||
self.path = path
|
||||
self.destination = destination
|
||||
self.time_counters[1] = 0 -- find path interval
|
||||
self.time_counters[2] = 0
|
||||
self:change_direction(self.path[1])
|
||||
self:set_animation(maidroid.animation_frames.WALK)
|
||||
end
|
||||
|
||||
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
|
||||
self.state = state.PLANT
|
||||
self.time_counters[1] = 0
|
||||
self.object:setvelocity{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()))
|
||||
return
|
||||
else
|
||||
to_walk_randomly(self)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
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)
|
||||
self:set_yaw_by_direction(vector.subtract(self.destination, self.object:getpos()))
|
||||
end
|
||||
|
||||
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)
|
||||
return
|
||||
elseif self.state == state.WALK_TO_MOW then
|
||||
to_mow(self)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
if self.time_counters[2] >= MAX_WALK_TIME then -- time over.
|
||||
to_walk_randomly(self)
|
||||
return
|
||||
end
|
||||
|
||||
self.time_counters[1] = self.time_counters[1] + 1
|
||||
self.time_counters[2] = self.time_counters[2] + 1
|
||||
|
||||
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*")
|
||||
if path == nil then
|
||||
to_walk_randomly(self)
|
||||
return
|
||||
end
|
||||
self.path = path
|
||||
end
|
||||
|
||||
-- follow path
|
||||
if is_near(self, self.path[1], 0.5) then
|
||||
table.remove(self.path, 1)
|
||||
|
||||
if #self.path == 0 then -- end of path
|
||||
if self.state == state.WALK_TO_PLANT then
|
||||
to_plant(self)
|
||||
return
|
||||
elseif self.state == state.WALK_TO_MOW then
|
||||
to_mow(self)
|
||||
return
|
||||
end
|
||||
else -- else next step, follow next path.
|
||||
self:change_direction(self.path[1])
|
||||
end
|
||||
|
||||
else
|
||||
-- if maidroid is stopped by obstacles, the maidroid must jump.
|
||||
local velocity = self.object:getvelocity()
|
||||
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}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
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()
|
||||
local itemname = stack:get_name()
|
||||
|
||||
local pointed_thing = {
|
||||
type = "node",
|
||||
under = vector.add(self.destination, {x = 0, y = -1, z = 0}),
|
||||
above = self.destination,
|
||||
}
|
||||
farming.place_seed(stack, minetest.get_player_by_name(self.owner_name), pointed_thing, stack:get_name())
|
||||
|
||||
stack:take_item(1)
|
||||
self:set_wield_item_stack(stack)
|
||||
end
|
||||
to_walk_randomly(self)
|
||||
return
|
||||
else
|
||||
self.time_counters[1] = self.time_counters[1] + 1
|
||||
end
|
||||
end
|
||||
|
||||
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)
|
||||
minetest.remove_node(self.destination)
|
||||
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.destination, leftover)
|
||||
end
|
||||
end
|
||||
to_walk_randomly(self)
|
||||
return
|
||||
else
|
||||
self.time_counters[1] = self.time_counters[1] + 1
|
||||
end
|
||||
end
|
||||
|
||||
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
|
||||
walk_to_plant_and_mow_common(self, dtime)
|
||||
elseif self.state == state.PLANT then
|
||||
plant(self, dtime)
|
||||
elseif self.state == state.MOW then
|
||||
mow(self, dtime)
|
||||
end
|
||||
end
|
||||
|
||||
local core = maidroid.registered_cores["maidroid_core:farming"]
|
||||
core.on_start = on_start
|
||||
core.on_stop = on_stop
|
||||
core.on_resume = on_start
|
||||
core.on_pause = on_stop
|
||||
core.on_step = on_step
|
||||
|
Loading…
Reference in New Issue
Block a user