From fc4a6a44ebfff75cbdf0a4b62b63d7b8b5f7eacc Mon Sep 17 00:00:00 2001 From: h-v-smacker Date: Mon, 7 May 2018 08:02:36 +0300 Subject: Resolution of API ambiguity --- init.lua | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 2 deletions(-) (limited to 'init.lua') diff --git a/init.lua b/init.lua index f4f8f32..35526f8 100644 --- a/init.lua +++ b/init.lua @@ -290,13 +290,83 @@ end -- add grass and flower/plant decoration for specific dirt types -- {dirt_node, {grass_nodes}, {flower_nodes} -- e.g. {"default:dirt_with_dry_grass", dry_grass, flowers} +-- if an entry already exists for a given dirt type, it will add new entries and all empty +-- entries, allowing to both add decorations and decrease their frequency. function bonemeal:add_deco(list) - for n = 1, #list do - table.insert(deco, list[n]) + for l = 1, #list do + + for n = 1, #deco do + + -- update existing entry + if list[l][1] == deco[n][1] then + + -- adding grass types + for _,extra in ipairs(list[l][2]) do + if extra ~= "" then + for __,entry in ipairs(deco[n][2]) do + if extra == entry then + extra = false + break + end + end + end + if extra then + table.insert(deco[n][2], extra) + end + end + + -- adding decoration types + for _,extra in ipairs(list[l][3]) do + if extra ~= "" then + for __,entry in ipairs(deco[n][3]) do + if extra == entry then + extra = false + break + end + end + end + if extra then + table.insert(deco[n][3], extra) + end + end + + list[l] = false + break + end + + end + + if list[l] then + table.insert(deco, list[l]) + end + end end +-- definitively set a decration scheme +-- this function will either add a new entry as is, or replace the existing one +function bonemeal:set_deco(list) + + for l = 1, #list do + + for n = 1, #deco do + + -- replace existing entry + if list[l][1] == deco[n][1] then + deco[n][2] = list[l][2] + deco[n][3] = list[l][3] + list[l] = false + break + end + end + + if list[l] then + table.insert(deco, list[l]) + end + + end +end -- global on_use function for bonemeal function bonemeal:on_use(pos, strength, node) -- cgit v1.2.3