summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.txt1
-rw-r--r--beanpole.lua9
-rw-r--r--cocoa.lua9
-rw-r--r--init.lua47
4 files changed, 64 insertions, 2 deletions
diff --git a/README.txt b/README.txt
index e8425f1..12ea62d 100644
--- a/README.txt
+++ b/README.txt
@@ -13,6 +13,7 @@ This mod works by adding your new plant to the {growing=1} group and numbering t
Changelog:
+1.21 - Added auto-refill code for planting crops (thanks crabman77), also fixed a few bugs
1.20b- Tidied code, made api compatible with new 0.4.13 changes and changed to soil texture overlays
1.20 - NEW growing routine added that allows crops to grow while player is away doing other things (thanks prestidigitator)
1.14 - Added Green Beans from Crops mod (thanks sofar), little bushels in the wild but need to be grown using beanpoles crafted with 4 sticks (2 either side)
diff --git a/beanpole.lua b/beanpole.lua
index f9ba132..ba61543 100644
--- a/beanpole.lua
+++ b/beanpole.lua
@@ -17,6 +17,15 @@ minetest.register_craftitem("farming:beans", {
end
if not minetest.setting_getbool("creative_mode") then
itemstack:take_item()
+ -- check for refill
+ if itemstack:get_count() == 0 then
+ minetest.after(0.20,
+ farming.refill_plant,
+ placer,
+ "farming:beans",
+ placer:get_wield_index()
+ )
+ end -- END refill
end
return itemstack
end
diff --git a/cocoa.lua b/cocoa.lua
index c68a0d3..26adc68 100644
--- a/cocoa.lua
+++ b/cocoa.lua
@@ -25,6 +25,15 @@ function place_cocoa(itemstack, placer, pointed_thing, plantname)
minetest.add_node(pt.above, {name = plantname})
if not minetest.setting_getbool("creative_mode") then
itemstack:take_item()
+ -- check for refill
+ if itemstack:get_count() == 0 then
+ minetest.after(0.20,
+ farming.refill_plant,
+ placer,
+ "farming:cocoa_beans",
+ placer:get_wield_index()
+ )
+ end -- END refill
end
return itemstack
end
diff --git a/init.lua b/init.lua
index 7d96f1d..d26b8d4 100644
--- a/init.lua
+++ b/init.lua
@@ -1,7 +1,8 @@
--[[
- Minetest Farming Redo Mod 1.20b (26th August 2015)
+ Minetest Farming Redo Mod 1.21 (29th August 2015)
by TenPlus1
NEW growing routine by prestidigitator
+ auto-refill by crabman77
]]
farming = {}
@@ -71,7 +72,7 @@ dofile(farming.path.."/compatibility.lua") -- Farming Plus compatibility
-- Utility Functions
local time_speed = tonumber(minetest.setting_get("time_speed")) or 72
-local SECS_PER_CYCLE = (time_speed > 0 and 24 * 60 * 60 / time_speed) or nil
+local SECS_PER_CYCLE = (time_speed > 0 and 24 * 60 * 60 / time_speed) or 0 --nil
local function clamp(x, min, max)
return (x < min and min) or (x > max and max) or x
@@ -391,6 +392,38 @@ if farming.DEBUG then
end
end
+-- refill placed plant by crabman (26/08/2015)
+local can_refill_plant = {
+ ["farming:blueberry_1"] = "farming:blueberries",
+ ["farming:carrot_1"] = "farming:carrot",
+ ["farming:coffee_1"] = "farming:coffee_beans",
+ ["farming:corn_1"] = "farming:corn",
+ ["farming:cotton_1"] = "farming:seed_cotton",
+ ["farming:cucumber_1"] = "farming:cucumber",
+ ["farming:melon_1"] = "farming:melon_slice",
+ ["farming:potato_1"] = "farming:potato",
+ ["farming:pumpkin_1"] = "farming:pumpkin_slice",
+ ["farming:raspberry_1"] = "farming:raspberries",
+ ["farming:rhubarb_1"] = "farming:rhubarb",
+ ["farming:tomato_1"] = "farming:tomato",
+ ["farming:wheat_1"] = "farming:seed_wheat"
+}
+
+function farming.refill_plant(player, plantname, index)
+ local inv = player:get_inventory()
+ local old_stack = inv:get_stack("main", index)
+ if old_stack:get_name() ~= "" then return end
+ for i,stack in ipairs(inv:get_list("main")) do
+ if stack:get_name() == plantname and i ~= index then
+ inv:set_stack("main", index, stack)
+ stack:clear()
+ inv:set_stack("main", i, stack)
+ --minetest.log("action", "farming: refilled stack("..plantname..") of " .. player:get_player_name() )
+ return
+ end
+ end
+end -- END refill
+
-- Place Seeds on Soil
function farming.place_seed(itemstack, placer, pointed_thing, plantname)
@@ -428,6 +461,16 @@ function farming.place_seed(itemstack, placer, pointed_thing, plantname)
minetest.add_node(pt.above, {name = plantname, param2 = 1})
if not minetest.setting_getbool("creative_mode") then
itemstack:take_item()
+ -- check for refill
+ if itemstack:get_count() == 0
+ and can_refill_plant[plantname] then
+ minetest.after(0.10,
+ farming.refill_plant,
+ placer,
+ can_refill_plant[plantname],
+ placer:get_wield_index()
+ )
+ end -- END refill
end
return itemstack
end