diff options
| author | Auke Kok <auke-jan.h.kok@intel.com> | 2015-05-02 19:03:17 -0700 | 
|---|---|---|
| committer | Auke Kok <auke-jan.h.kok@intel.com> | 2015-05-02 19:03:37 -0700 | 
| commit | 7dbea2deb5335faebdb3f80ce4bb301434e0b775 (patch) | |
| tree | 2b3428b6f15ff1adb857442141f1f1c570d5e27d | |
| parent | 30b3b143129af0182f0f2e20a7f9dc6fd6580a3f (diff) | |
Start of getting humidity to work for potatoes.
| -rw-r--r-- | init.lua | 8 | ||||
| -rw-r--r-- | potato.lua | 35 | ||||
| -rw-r--r-- | textures/crops_potato_plant_5.png | bin | 0 -> 424 bytes | 
3 files changed, 34 insertions, 9 deletions
| @@ -41,6 +41,7 @@ local find_plant = function(node)  			return crops.plants[i]  		end  	end +	minetest.log("error", "Unable to find plant \"" .. node.name .. "\" in crops table")  	return nil  end @@ -68,7 +69,8 @@ crops.can_grow = function(pos)  			return false  		end  	end -	local plant = find_plant(pos) +	local node = minetest.get_node(pos) +	local plant = find_plant(node)  	if not plant then  		return false  	end @@ -213,7 +215,8 @@ dofile(modpath .. "/polebean.lua")  -- water handling code  minetest.register_abm({  	nodenames = { -		"crops:tomato_plant_1", "crops:tomato_plant_2", "crops:tomato_plant_3", "crops:tomato_plant_4", "crops:tomato_plant_5" +		"crops:tomato_plant_1", "crops:tomato_plant_2", "crops:tomato_plant_3", "crops:tomato_plant_4", "crops:tomato_plant_5", +		"crops:potato_plant_1", "crops:potato_plant_2", "crops:potato_plant_3", "crops:potato_plant_4"  	},  	interval = crops.interval,  	chance = crops.chance, @@ -225,7 +228,6 @@ minetest.register_abm({  		-- get plant specific data  		local plant = find_plant(node)  		if plant == nil then -			-- FIXME - throw error?  			return  		end @@ -28,7 +28,7 @@ minetest.register_node("crops:potato_eyes", {  		if minetest.get_item_group(under.name, "soil") <= 1 then  			return  		end -		minetest.set_node(pointed_thing.above, {name="crops:potato_plant_1"}) +		crops.plant(pointed_thing.above, {name="crops:potato_plant_1"})  		if not minetest.setting_getbool("creative_mode") then  			itemstack:take_item()  		end @@ -36,7 +36,7 @@ minetest.register_node("crops:potato_eyes", {  	end  }) -for stage = 1, 4 do +for stage = 1, 5 do  minetest.register_node("crops:potato_plant_" .. stage , {  	description = "potato plant",  	tiles = { "crops_potato_plant_" .. stage .. ".png" }, @@ -89,6 +89,7 @@ minetest.register_node("crops:soil_with_potatoes", {  	sounds = default.node_sound_dirt_defaults(),  	on_dig = function(pos, node, digger)  		local drops = {} +		-- fixme account for damage  		for i = 1, math.random(3, 5) do  			table.insert(drops, "crops:potato")  		end @@ -110,17 +111,22 @@ minetest.register_abm({  	interval = crops.interval,  	chance = crops.chance,  	action = function(pos, node, active_object_count, active_object_count_wider) -		local below = { x = pos.x, y = pos.y - 1, z = pos.z } -		if not minetest.registered_nodes[minetest.get_node(below).name].groups.soil then +		if not crops.can_grow(pos) then  			return  		end -		if minetest.get_node_light(pos, nil) < crops.light then +		local below = { x = pos.x, y = pos.y - 1, z = pos.z } +		if not minetest.registered_nodes[minetest.get_node(below).name].groups.soil then  			return  		end +		local meta = minetest.get_meta(pos) +		local water = meta:get_int("crops_water") +		local damage = meta:get_int("crops_damage")  		local n = string.gsub(node.name, "3", "4")  		n = string.gsub(n, "2", "3")  		n = string.gsub(n, "1", "2")  		minetest.set_node(pos, { name = n }) +		meta:set_int("crops_water", water) +		meta:set_int("crops_damage", damage)  	end  }) @@ -133,15 +139,32 @@ minetest.register_abm({  	interval = crops.interval,  	chance = crops.chance,  	action = function(pos, node, active_object_count, active_object_count_wider) -		if minetest.get_node_light(pos, nil) < crops.light then +		if not crops.can_grow(pos) then  			return  		end  		local below = { x = pos.x, y = pos.y - 1, z = pos.z }  		if not minetest.registered_nodes[minetest.get_node(below).name].groups.soil then  			return  		end +		local meta = minetest.get_meta(pos) +		local water = meta:get_int("crops_water") +		local damage = meta:get_int("crops_damage")  		local below = { x = pos.x, y = pos.y - 1, z = pos.z}  		minetest.set_node(below, { name = "crops:soil_with_potatoes" })  	end  }) +crops.potato_die = function(pos) +	minetest.set_node(pos, { name = "crops:potato_plant_5" }) +	local below = { x = pos.x, y = pos.y - 1, z = pos.z } +	local node = minetest.get_node(below) +	if node.name == "crops:soil_with_potatoes" then +		local meta = minetest.get_meta(below) +		meta:set_int("crops_damage", 100) +	end +end + +table.insert(crops.plants, { name = "crops:potato_plant_1", wateruse = 1.0, wither = crops.potato_die }) +table.insert(crops.plants, { name = "crops:potato_plant_2", wateruse = 1.0, wither = crops.potato_die }) +table.insert(crops.plants, { name = "crops:potato_plant_3", wateruse = 1.0, wither = crops.potato_die }) +table.insert(crops.plants, { name = "crops:potato_plant_4", wateruse = 1.0, wither = crops.potato_die }) diff --git a/textures/crops_potato_plant_5.png b/textures/crops_potato_plant_5.pngBinary files differ new file mode 100644 index 0000000..596ed1f --- /dev/null +++ b/textures/crops_potato_plant_5.png | 
