1
0
mirror of https://codeberg.org/tenplus1/farming.git synced 2024-12-26 10:40:20 +01:00

improve code

This commit is contained in:
tenplus1 2015-05-11 19:07:21 +01:00
parent e1df7aab7a
commit 9d1c49d2e7

View File

@ -1,34 +1,35 @@
--[[ --[[
Minetest Farming Redo Mod 1.14 (19th April 2015) Minetest Farming Redo Mod 1.14 (11th May 2015)
by TenPlus1 by TenPlus1
]] ]]
farming = {} farming = {}
farming.mod = "redo" farming.mod = "redo"
farming.path = minetest.get_modpath("farming")
farming.hoe_on_use = default.hoe_on_use farming.hoe_on_use = default.hoe_on_use
dofile(minetest.get_modpath("farming").."/soil.lua") dofile(farming.path.."/soil.lua")
dofile(minetest.get_modpath("farming").."/hoes.lua") dofile(farming.path.."/hoes.lua")
dofile(minetest.get_modpath("farming").."/grass.lua") dofile(farming.path.."/grass.lua")
dofile(minetest.get_modpath("farming").."/wheat.lua") dofile(farming.path.."/wheat.lua")
dofile(minetest.get_modpath("farming").."/cotton.lua") dofile(farming.path.."/cotton.lua")
dofile(minetest.get_modpath("farming").."/carrot.lua") dofile(farming.path.."/carrot.lua")
dofile(minetest.get_modpath("farming").."/potato.lua") dofile(farming.path.."/potato.lua")
dofile(minetest.get_modpath("farming").."/tomato.lua") dofile(farming.path.."/tomato.lua")
dofile(minetest.get_modpath("farming").."/cucumber.lua") dofile(farming.path.."/cucumber.lua")
dofile(minetest.get_modpath("farming").."/corn.lua") dofile(farming.path.."/corn.lua")
dofile(minetest.get_modpath("farming").."/coffee.lua") dofile(farming.path.."/coffee.lua")
dofile(minetest.get_modpath("farming").."/melon.lua") dofile(farming.path.."/melon.lua")
dofile(minetest.get_modpath("farming").."/sugar.lua") dofile(farming.path.."/sugar.lua")
dofile(minetest.get_modpath("farming").."/pumpkin.lua") dofile(farming.path.."/pumpkin.lua")
dofile(minetest.get_modpath("farming").."/cocoa.lua") dofile(farming.path.."/cocoa.lua")
dofile(minetest.get_modpath("farming").."/raspberry.lua") dofile(farming.path.."/raspberry.lua")
dofile(minetest.get_modpath("farming").."/blueberry.lua") dofile(farming.path.."/blueberry.lua")
dofile(minetest.get_modpath("farming").."/rhubarb.lua") dofile(farming.path.."/rhubarb.lua")
dofile(minetest.get_modpath("farming").."/beanpole.lua") dofile(farming.path.."/beanpole.lua")
dofile(minetest.get_modpath("farming").."/donut.lua") dofile(farming.path.."/donut.lua")
dofile(minetest.get_modpath("farming").."/mapgen.lua") dofile(farming.path.."/mapgen.lua")
dofile(minetest.get_modpath("farming").."/compatibility.lua") -- Farming Plus compatibility dofile(farming.path.."/compatibility.lua") -- Farming Plus compatibility
-- Place Seeds on Soil -- Place Seeds on Soil
@ -81,31 +82,23 @@ minetest.register_abm({
action = function(pos, node) 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 plant = node.name:split("_")[1].."_"
local numb = node.name:split("_")[2] local numb = node.name:split("_")[2]
-- check if fully grown -- fully grown ?
if not minetest.registered_nodes[plant..(numb + 1)] then return end if not minetest.registered_nodes[plant..(numb + 1)] then return end
-- Check for Cocoa Pod -- cocoa pod on jungle tree ?
if plant == "farming:cocoa_" if plant ~= "farming:cocoa_" then
and minetest.find_node_near(pos, 1, {"default:jungletree", "moretrees:jungletree_leaves_green"}) then
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
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
end end
-- enough light ?
if minetest.get_node_light(pos) < 13 then return end
-- grow -- grow
minetest.set_node(pos, {name=plant..(numb + 1)}) minetest.set_node(pos, {name=plant..(numb + 1)})