2022-09-18 23:18:03 +00:00
|
|
|
local wea_c = worldeditadditions_core
|
|
|
|
local Vector3 = wea_c.Vector3
|
|
|
|
|
2020-05-11 01:02:02 +00:00
|
|
|
--- Bonemeal command.
|
|
|
|
-- Applies bonemeal to all notes
|
|
|
|
-- @module worldeditadditions.overlay
|
|
|
|
|
|
|
|
-- strength The strength to apply - see bonemeal:on_use
|
|
|
|
-- chance Positive integer that represents the chance bonemealing will occur
|
2021-08-05 00:17:43 +00:00
|
|
|
function worldeditadditions.bonemeal(pos1, pos2, strength, chance, nodename_list)
|
|
|
|
if not nodename_list then nodename_list = {} end
|
2022-09-18 23:18:03 +00:00
|
|
|
pos1, pos2 = Vector3.sort(pos1, pos2)
|
2020-05-11 01:02:02 +00:00
|
|
|
-- pos2 will always have the highest co-ordinates now
|
|
|
|
|
|
|
|
-- This command requires the bonemeal mod to be installed
|
|
|
|
-- We check here too because other mods might call this function directly and bypass the chat command system
|
|
|
|
if not minetest.get_modpath("bonemeal") then
|
|
|
|
return false, "Bonemeal mod not loaded"
|
|
|
|
end
|
|
|
|
|
2022-09-18 23:18:03 +00:00
|
|
|
local node_list = wea_c.table.map(nodename_list, function(nodename)
|
2021-08-05 00:17:43 +00:00
|
|
|
return minetest.get_content_id(nodename)
|
|
|
|
end)
|
|
|
|
local node_list_count = #nodename_list
|
|
|
|
|
|
|
|
|
2020-05-11 01:02:02 +00:00
|
|
|
-- Fetch the nodes in the specified area
|
|
|
|
local manip, area = worldedit.manip_helpers.init(pos1, pos2)
|
|
|
|
local data = manip:get_data()
|
|
|
|
|
|
|
|
local node_id_air = minetest.get_content_id("air")
|
|
|
|
|
|
|
|
-- z y x is the preferred loop order (because CPU cache I'd guess), but that isn't really possible here
|
|
|
|
local nodes_bonemealed = 0
|
|
|
|
local candidates = 0
|
|
|
|
for z = pos2.z, pos1.z, -1 do
|
|
|
|
for x = pos2.x, pos1.x, -1 do
|
|
|
|
for y = pos2.y, pos1.y, -1 do
|
2021-08-05 00:17:43 +00:00
|
|
|
local i = area:index(x, y, z)
|
2022-09-18 23:18:03 +00:00
|
|
|
if not wea_c.is_airlike(data[i]) then
|
2021-08-05 00:17:43 +00:00
|
|
|
local should_bonemeal = true
|
2022-09-18 23:18:03 +00:00
|
|
|
if node_list_count > 0 and not wea_c.table.contains(node_list, data[i]) then
|
2021-08-05 00:17:43 +00:00
|
|
|
should_bonemeal = false
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2021-05-11 21:17:10 +00:00
|
|
|
-- It's not an air node, so let's try to bonemeal it
|
|
|
|
|
2021-08-05 00:17:43 +00:00
|
|
|
if should_bonemeal and math.random(0, chance - 1) == 0 then
|
2021-05-11 21:17:10 +00:00
|
|
|
bonemeal:on_use(
|
2022-09-18 23:18:03 +00:00
|
|
|
Vector3.new(x, y, z),
|
2021-05-11 21:17:10 +00:00
|
|
|
strength,
|
|
|
|
nil
|
|
|
|
)
|
|
|
|
nodes_bonemealed = nodes_bonemealed + 1
|
2020-05-11 01:02:02 +00:00
|
|
|
end
|
2021-05-11 21:17:10 +00:00
|
|
|
|
|
|
|
candidates = candidates + 1
|
2020-05-11 01:02:02 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
-- Save the modified nodes back to disk & return
|
|
|
|
-- Note that we do NOT save it back to disk here, because we haven't actually changed anything
|
|
|
|
-- We just grabbed the data via manip to allow for rapid node name lookups
|
|
|
|
-- worldedit.manip_helpers.finish(manip, data)
|
|
|
|
|
|
|
|
return true, nodes_bonemealed, candidates
|
|
|
|
end
|