From 02b6cc11f5ad41630c65bd95e62812387fcdc69a Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sat, 18 Feb 2017 20:23:26 +0100 Subject: [PATCH] Make cocoas grow --- mods/ITEMS/mcl_cocoas/init.lua | 39 ++++++++++++++++++++++++++++------ mods/ITEMS/mcl_dye/init.lua | 9 +++----- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/mods/ITEMS/mcl_cocoas/init.lua b/mods/ITEMS/mcl_cocoas/init.lua index b786cabac..2bf426457 100644 --- a/mods/ITEMS/mcl_cocoas/init.lua +++ b/mods/ITEMS/mcl_cocoas/init.lua @@ -1,7 +1,7 @@ mcl_cocoas = {} --- place cocoa -function mcl_cocoas.place_cocoa(itemstack, placer, pointed_thing, plantname) +-- Place cocoa +function mcl_cocoas.place(itemstack, placer, pointed_thing, plantname) local pt = pointed_thing @@ -50,11 +50,25 @@ function mcl_cocoas.place_cocoa(itemstack, placer, pointed_thing, plantname) return itemstack end +-- Attempts to grow a cocoa at pos, returns true when grown, returns false if there's no cocoa +-- or it is already at full size +function mcl_cocoas.grow(pos) + local node = minetest.get_node(pos) + if node.name == "mcl_cocoas:cocoa_1" then + minetest.set_node(pos, {name = "mcl_cocoas:cocoa_2", param2 = node.param2}) + elseif node.name == "mcl_cocoas:cocoa_2" then + minetest.set_node(pos, {name = "mcl_cocoas:cocoa_3", param2 = node.param2}) + return true + end + return false +end + -- Note: cocoa beans are implemented as mcl_dye:brown -- Cocoa definition +-- 1st stage local crop_def = { - description = "Cocoa (Stage 0)", + description = "Young Cocoa", drawtype = "nodebox", tiles = { "[combine:32x32:12,2=mcl_cocoas_cocoa_stage_0.png", "[combine:32x32:12,22=mcl_cocoas_cocoa_stage_0.png", @@ -92,10 +106,10 @@ local crop_def = { sounds = mcl_sounds.node_sound_wood_defaults() } --- stage 1 +-- 2nd stage minetest.register_node("mcl_cocoas:cocoa_1", table.copy(crop_def)) -crop_def.description = "Cocoa (Stage 1)" +crop_def.description = "Medium Cocoa" crop_def.tiles = { "[combine:32x32:10,2=mcl_cocoas_cocoa_stage_1.png", "[combine:32x32:10,18=mcl_cocoas_cocoa_stage_1.png", "mcl_cocoas_cocoa_stage_1.png", "mcl_cocoas_cocoa_stage_1.png^[transformFX", @@ -123,8 +137,8 @@ crop_def.selection_box = { minetest.register_node("mcl_cocoas:cocoa_2", table.copy(crop_def)) --- stage 2 (final) -crop_def.description = "Cocoa (Stage 2)" +-- Final stage +crop_def.description = "Mature Cocoa" crop_def.tiles = { -- The following 2 textures were derived from the original because the size of the top/bottom is slightly different :-( -- TODO: Find a way to *only* use the base texture @@ -200,3 +214,14 @@ minetest.register_on_generated(function(minp, maxp) end end) +minetest.register_abm({ + nodenames = {"mcl_cocoas:cocoa_1", "mcl_cocoas:cocoa_2"}, + -- Same as potatoes + -- TODO: Tweak/balance the growth speed + interval = 50, + chance = 20, + action = function(pos, node) + mcl_cocoas.grow(pos) + end +} ) + diff --git a/mods/ITEMS/mcl_dye/init.lua b/mods/ITEMS/mcl_dye/init.lua index 83820fa87..fea19b29d 100644 --- a/mods/ITEMS/mcl_dye/init.lua +++ b/mods/ITEMS/mcl_dye/init.lua @@ -180,11 +180,8 @@ mcl_dye.apply_bone_meal = function(pointed_thing) minetest.add_node(pos, {name="mcl_farming:melontige_unconnect"}) end return true - elseif n.name == "mcl_cocoas:cocoa_1" then - minetest.set_node(pos, {name="mcl_cocoas:cocoa_2", param2 = n.param2}) - return true - elseif n.name == "mcl_cocoas:cocoa_2" then - minetest.set_node(pos, {name="mcl_cocoas:cocoa_3", param2 = n.param2}) + elseif n.name == "mcl_cocoas:cocoa_1" or n.name == "mcl_cocoas:cocoa_2" then + mcl_cocoas.grow(pos) return true elseif n.name ~= "" and n.name == "mcl_core:junglesapling" then minetest.add_node(pos, {name="air"}) @@ -233,7 +230,7 @@ minetest.register_craftitem("mcl_dye:brown", { stack_max = 64, groups = dyelocal.dyes[4][3], on_place = function(itemstack, user, pointed_thing) - return mcl_cocoas.place_cocoa(itemstack, placer, pointed_thing, "mcl_cocoas:cocoa_1") + return mcl_cocoas.place(itemstack, placer, pointed_thing, "mcl_cocoas:cocoa_1") end, })