From 311639ee11f8849ee66fe810d6750c18f31eb998 Mon Sep 17 00:00:00 2001 From: Michal Cieslakiewicz Date: Tue, 9 Jul 2019 16:32:30 +0200 Subject: [PATCH] slmodules: cropswatcher: fix crash when using default farming mod. farming.registered_plants table for farming_redo mod differs slightly from default (vanilla) Minetest game farming mod. Redo adds 'crop' value and indexes elements by full name ("farming:wheat") while vanilla one creates entries with simple labels ("wheat") and does not provide 'crop' field. This causes game to crash for vanilla farming addon with following error: cropswatcher.lua:80: attempt to concatenate field 'crop' (a nil value) Code has been updated to correctly handle either of farming mods. This fixes issue #1 by neoh4x0r. Signed-off-by: Michal Cieslakiewicz --- slmodules/cropswatcher.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/slmodules/cropswatcher.lua b/slmodules/cropswatcher.lua index c9ca473..8163670 100644 --- a/slmodules/cropswatcher.lua +++ b/slmodules/cropswatcher.lua @@ -75,11 +75,12 @@ local cwstate = { -- tables with farming crop nodes local cropnames = {} local isgrowncrop = {} -for _, c in pairs(farming.registered_plants) do +for j, c in pairs(farming.registered_plants) do + local lcn = c.crop or "farming:" .. j for i = 1, c.steps do - cropnames[#cropnames + 1] = c.crop .. "_" .. i + cropnames[#cropnames + 1] = lcn .. "_" .. i end - isgrowncrop[c.crop .. "_" .. c.steps] = true + isgrowncrop[lcn .. "_" .. c.steps] = true end --[[