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 <michal.cieslakiewicz@wp.pl>
This commit is contained in:
Michal Cieslakiewicz 2019-07-09 16:32:30 +02:00
parent 80b2844d24
commit 311639ee11

View File

@ -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
--[[