add_deco() now adds to item list, set_deco() replaces item list (thanks h-v-smacker)

This commit is contained in:
TenPlus1 2018-05-07 09:18:25 +01:00
parent d1c962837d
commit dd422b6091
3 changed files with 106 additions and 8 deletions

View File

@ -29,5 +29,6 @@ Changelog:
- 0.7 - Can be used on papyrus and cactus now, added coral recipe, api addition - 0.7 - Can be used on papyrus and cactus now, added coral recipe, api addition
- 0.8 - Added support for farming redo's new garlic, pepper and onion crops - 0.8 - Added support for farming redo's new garlic, pepper and onion crops
- 0.9 - Added support for farming redo's pea and beetroot crops, checks for place_param - 0.9 - Added support for farming redo's pea and beetroot crops, checks for place_param
- 1.0 - add_deco() now adds to existing item list while set_deco() replaces item list (thanks h-v-smacker)
Lucky Blocks: 5 Lucky Blocks: 5

31
api.txt
View File

@ -14,7 +14,9 @@ Function Usage
Adding Crops Adding Crops
------------ ------------
bonemeal:add_crop({ nodename_start, growing_steps, seed_name }) bonemeal:add_crop({
{ nodename_start, growing_steps, seed_name }
})
This command is used to add new crops for bonemeal to work on. This command is used to add new crops for bonemeal to work on.
@ -29,7 +31,9 @@ bonemeal:add_crop({
Adding Saplings Adding Saplings
--------------- ---------------
bonemeal:add_sapling({ sapling_node, function, soil_type[sand, dirt, nodename] }) bonemeal:add_sapling({
{ sapling_node, function, soil_type[sand, dirt, nodename] }
})
This command will add new saplings for bonemeal to grow on sand, soil or a This command will add new saplings for bonemeal to grow on sand, soil or a
specified node type. specified node type.
@ -43,15 +47,30 @@ bonemeal:add_sapling({
Adding Dirt Decoration Adding Dirt Decoration
---------------------- ----------------------
bonemeal:add_deco({ dirt_node, {grass_node_list}, {decor_node_list} }) bonemeal:add_deco({
{ dirt_node, {grass_node_list}, {decor_node_list} }
})
This command will add grass and decoration to specific dirt types, use "" to This command will add grass and decoration to specific dirt types, use "" to
add an empty node. add an empty node. If some decorations have been already defined for this dirt type, new
will be added to the respective list. All empty ("") entries will be added regardless,
which allows to decrease the frequency of decoration emergence, if needed.
e.g. e.g.
bonemeal:add_deco({"default:dirt_with_dry_grass", {"default:dry_grass_1", ""}, bonemeal:add_deco({
{"flowers:rose", "flowers:viola"} }) {"default:dirt_with_dry_grass", {"default:dry_grass_1", ""},
{"flowers:rose", "flowers:viola"} }
})
Thus, add_deco() always adds (to) a definition, and never overrides. To discard an existing
definiton in favor of the new one, use
bonemeal:set_deco({
{ dirt_node, {grass_node_list}, {decor_node_list} }
})
This command will set decoration for a given dirt type, fully replacing any existing definition.
Global ON_USE Function Global ON_USE Function

View File

@ -290,10 +290,87 @@ end
-- add grass and flower/plant decoration for specific dirt types -- add grass and flower/plant decoration for specific dirt types
-- {dirt_node, {grass_nodes}, {flower_nodes} -- {dirt_node, {grass_nodes}, {flower_nodes}
-- e.g. {"default:dirt_with_dry_grass", dry_grass, flowers} -- 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) function bonemeal:add_deco(list)
for n = 1, #list do for l = 1, #list do
table.insert(deco, list[n])
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
end end
@ -385,6 +462,7 @@ minetest.register_craftitem("bonemeal:mulch", {
end, end,
}) })
-- bonemeal (strength 2) -- bonemeal (strength 2)
minetest.register_craftitem("bonemeal:bonemeal", { minetest.register_craftitem("bonemeal:bonemeal", {
description = S("Bone Meal"), description = S("Bone Meal"),