Added auto-refill routine and fixed a few bugs

This commit is contained in:
TenPlus1 2015-08-29 09:27:01 +01:00
parent e6babd6486
commit a14fc6f3ad
4 changed files with 64 additions and 2 deletions

View File

@ -13,6 +13,7 @@ This mod works by adding your new plant to the {growing=1} group and numbering t
Changelog: 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.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.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) 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)

View File

@ -17,6 +17,15 @@ minetest.register_craftitem("farming:beans", {
end end
if not minetest.setting_getbool("creative_mode") then if not minetest.setting_getbool("creative_mode") then
itemstack:take_item() 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 end
return itemstack return itemstack
end end

View File

@ -25,6 +25,15 @@ function place_cocoa(itemstack, placer, pointed_thing, plantname)
minetest.add_node(pt.above, {name = plantname}) minetest.add_node(pt.above, {name = plantname})
if not minetest.setting_getbool("creative_mode") then if not minetest.setting_getbool("creative_mode") then
itemstack:take_item() 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 end
return itemstack return itemstack
end end

View File

@ -1,7 +1,8 @@
--[[ --[[
Minetest Farming Redo Mod 1.20b (26th August 2015) Minetest Farming Redo Mod 1.21 (29th August 2015)
by TenPlus1 by TenPlus1
NEW growing routine by prestidigitator NEW growing routine by prestidigitator
auto-refill by crabman77
]] ]]
farming = {} farming = {}
@ -71,7 +72,7 @@ dofile(farming.path.."/compatibility.lua") -- Farming Plus compatibility
-- Utility Functions -- Utility Functions
local time_speed = tonumber(minetest.setting_get("time_speed")) or 72 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) local function clamp(x, min, max)
return (x < min and min) or (x > max and max) or x return (x < min and min) or (x > max and max) or x
@ -391,6 +392,38 @@ if farming.DEBUG then
end end
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 -- Place Seeds on Soil
function farming.place_seed(itemstack, placer, pointed_thing, plantname) 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}) minetest.add_node(pt.above, {name = plantname, param2 = 1})
if not minetest.setting_getbool("creative_mode") then if not minetest.setting_getbool("creative_mode") then
itemstack:take_item() 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 end
return itemstack return itemstack
end end