summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortenplus1 <kinsellaja@yahoo.com>2015-05-11 19:07:21 +0100
committertenplus1 <kinsellaja@yahoo.com>2015-05-11 19:07:21 +0100
commit9d1c49d2e7e32c5b7a5b363fa84528ac84c2ec2d (patch)
treef4c156c513bcba2e9bc3986d8ce6c4e383792b92
parente1df7aab7ad99e6f20cb90f637e56f5762bceb90 (diff)
improve code
-rw-r--r--init.lua75
1 files changed, 34 insertions, 41 deletions
diff --git a/init.lua b/init.lua
index 2692b88..aee9976 100644
--- a/init.lua
+++ b/init.lua
@@ -1,34 +1,35 @@
--[[
- Minetest Farming Redo Mod 1.14 (19th April 2015)
+ Minetest Farming Redo Mod 1.14 (11th May 2015)
by TenPlus1
]]
farming = {}
farming.mod = "redo"
+farming.path = minetest.get_modpath("farming")
farming.hoe_on_use = default.hoe_on_use
-dofile(minetest.get_modpath("farming").."/soil.lua")
-dofile(minetest.get_modpath("farming").."/hoes.lua")
-dofile(minetest.get_modpath("farming").."/grass.lua")
-dofile(minetest.get_modpath("farming").."/wheat.lua")
-dofile(minetest.get_modpath("farming").."/cotton.lua")
-dofile(minetest.get_modpath("farming").."/carrot.lua")
-dofile(minetest.get_modpath("farming").."/potato.lua")
-dofile(minetest.get_modpath("farming").."/tomato.lua")
-dofile(minetest.get_modpath("farming").."/cucumber.lua")
-dofile(minetest.get_modpath("farming").."/corn.lua")
-dofile(minetest.get_modpath("farming").."/coffee.lua")
-dofile(minetest.get_modpath("farming").."/melon.lua")
-dofile(minetest.get_modpath("farming").."/sugar.lua")
-dofile(minetest.get_modpath("farming").."/pumpkin.lua")
-dofile(minetest.get_modpath("farming").."/cocoa.lua")
-dofile(minetest.get_modpath("farming").."/raspberry.lua")
-dofile(minetest.get_modpath("farming").."/blueberry.lua")
-dofile(minetest.get_modpath("farming").."/rhubarb.lua")
-dofile(minetest.get_modpath("farming").."/beanpole.lua")
-dofile(minetest.get_modpath("farming").."/donut.lua")
-dofile(minetest.get_modpath("farming").."/mapgen.lua")
-dofile(minetest.get_modpath("farming").."/compatibility.lua") -- Farming Plus compatibility
+dofile(farming.path.."/soil.lua")
+dofile(farming.path.."/hoes.lua")
+dofile(farming.path.."/grass.lua")
+dofile(farming.path.."/wheat.lua")
+dofile(farming.path.."/cotton.lua")
+dofile(farming.path.."/carrot.lua")
+dofile(farming.path.."/potato.lua")
+dofile(farming.path.."/tomato.lua")
+dofile(farming.path.."/cucumber.lua")
+dofile(farming.path.."/corn.lua")
+dofile(farming.path.."/coffee.lua")
+dofile(farming.path.."/melon.lua")
+dofile(farming.path.."/sugar.lua")
+dofile(farming.path.."/pumpkin.lua")
+dofile(farming.path.."/cocoa.lua")
+dofile(farming.path.."/raspberry.lua")
+dofile(farming.path.."/blueberry.lua")
+dofile(farming.path.."/rhubarb.lua")
+dofile(farming.path.."/beanpole.lua")
+dofile(farming.path.."/donut.lua")
+dofile(farming.path.."/mapgen.lua")
+dofile(farming.path.."/compatibility.lua") -- Farming Plus compatibility
-- Place Seeds on Soil
@@ -81,31 +82,23 @@ minetest.register_abm({
action = function(pos, node)
- -- get node type (e.g. farming:wheat_1)
+ -- split plant name (e.g. farming:wheat_1)
local plant = node.name:split("_")[1].."_"
local numb = node.name:split("_")[2]
- -- check if fully grown
+ -- fully grown ?
if not minetest.registered_nodes[plant..(numb + 1)] then return end
- -- Check for Cocoa Pod
- if plant == "farming:cocoa_"
- and minetest.find_node_near(pos, 1, {"default:jungletree", "moretrees:jungletree_leaves_green"}) then
+ -- cocoa pod on jungle tree ?
+ if plant ~= "farming:cocoa_" then
- if minetest.get_node_light(pos) < 13 then return end
-
- else
-
- -- check if on wet soil
- pos.y = pos.y-1
- if minetest.get_node(pos).name ~= "farming:soil_wet" then return end
- pos.y = pos.y+1
-
- -- check light
- if minetest.get_node_light(pos) < 13 then return end
-
+ -- growing on wet soil ?
+ if minetest.get_node({x=pos.x,y=pos.y-1,z=pos.z}).name ~= "farming:soil_wet" then return end
end
-
+
+ -- enough light ?
+ if minetest.get_node_light(pos) < 13 then return end
+
-- grow
minetest.set_node(pos, {name=plant..(numb + 1)})