From 4dc18bcf3670cb6f38d9880feebec3415eb62c81 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Thu, 9 Feb 2017 13:10:25 +0100 Subject: [PATCH] =?UTF-8?q?Add=20server=20command=20=E2=80=9Clplant?= =?UTF-8?q?=E2=80=9D=20to=20plant=20trees?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- init.lua | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/init.lua b/init.lua index 699a9a4..162b3aa 100644 --- a/init.lua +++ b/init.lua @@ -518,6 +518,8 @@ function ltool.tab_help_plant() "When using coordinates\\, the \"distance\" field is ignored\\, when using,".. "direction\\, the coordinate fields are ignored.,".. ",".. + "You can also use the “lplant” server command to plant trees.,".. + ",".. "If you got a sapling\\, you can place it practically anywhere you like to.,".. "After placing it\\, the sapling will be replaced by the L-system tree after,".. "5 seconds\\, unless it was destroyed in the meantime.,".. @@ -812,6 +814,32 @@ minetest.register_chatcommand("treeform", end }) +minetest.register_chatcommand("lplant", +{ + description = "Plant a L-system tree at the specified position", + privs = { lplant = true }, + params = " ", + func = function(playername, param) + local p = {} + local tree_id, x, y, z = string.match(param, "^([^ ]+) +([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+)$") + tree_id, p.x, p.y, p.z = tonumber(tree_id), tonumber(x), tonumber(y), tonumber(z) + if not tree_id or not p.x or not p.y or not p.z then + return false, "Invalid usage, see /help lplant." + end + local lm = tonumber(minetest.setting_get("map_generation_limit") or 31000) + if p.x < -lm or p.x > lm or p.y < -lm or p.y > lm or p.z < -lm or p.z > lm then + return false, "Cannot plant tree out of map bounds!" + end + + local success = ltool.plant_tree(tree_id, p) + if success == false then + return false, "Unknown tree ID!" + else + return true + end + end +}) + function ltool.dbsel_to_tree(dbsel, playername) return ltool.trees[ltool.playerinfos[playername].treeform.database.textlist[dbsel]] end