From de8ea11b3967cb5b91951db80b1b865dda07b454 Mon Sep 17 00:00:00 2001 From: Nils Dagsson Moskopp Date: Mon, 18 Apr 2022 05:13:38 +0200 Subject: [PATCH] Add debug command to spawn mcl_farming plant nodes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch adds the debug command “/generate_farming_plant_rows”. The command generates rows of plants and stems per plant type near a player. A farming soil or glass node is placed below each node, so players can find and examine possible gaps between a plant node and a node below. --- mods/ITEMS/mcl_farming/init.lua | 70 +++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/mods/ITEMS/mcl_farming/init.lua b/mods/ITEMS/mcl_farming/init.lua index adce058e..17a4d7c9 100644 --- a/mods/ITEMS/mcl_farming/init.lua +++ b/mods/ITEMS/mcl_farming/init.lua @@ -27,3 +27,73 @@ dofile(minetest.get_modpath("mcl_farming").."/potatoes.lua") -- ========= BEETROOT ========= dofile(minetest.get_modpath("mcl_farming").."/beetroot.lua") + +-- This function generates a row of plantlike and nodebox nodes whose +-- name starts with a given string, starting at a given position. It +-- places a given node below so that the rendering can be examined. +local function generate_plant_row(prefix, pos, below_node) + local i = 1 + for node_name, node in pairs(minetest.registered_nodes) do + if ( + 1 == node_name:find(prefix) and + ( + "plantlike" == node.drawtype or + "nodebox" == node.drawtype + ) + ) then + local node_pos = { + x = pos.x + i, + y = pos.y, + z = pos.z, + } + minetest.set_node( + node_pos, + { + name = node_name, + param2 = node.place_param2 or 0 + } + ) + local below_pos = { + x = node_pos.x, + y = node_pos.y - 1, + z = node_pos.z + } + minetest.set_node( + below_pos, + below_node + ) + i = i + 1 + end + end +end + +minetest.register_chatcommand("generate_farming_plant_rows",{ + description = "Generates rows of mcl_farming plant nodes on farming soil and glass", + privs = { debug = true }, + func = function(name, param) + local player = minetest.get_player_by_name(name) + local pos = player:get_pos() + local node_prefixes = { + "mcl_farming:beetroot", + "mcl_farming:carrot", + "mcl_farming:melon", + "mcl_farming:potato", + "mcl_farming:pumpkin", + "mcl_farming:wheat", + } + for i,node_prefix in ipairs(node_prefixes) do + generate_plant_row( + node_prefix, + pos, + { name = "mcl_farming:soil" } + ) + pos.z = pos.z + 2 + generate_plant_row( + node_prefix, + pos, + { name = "mcl_core:glass" } + ) + pos.z = pos.z + 2 + end + end +})