From ba93cb7bea9b00f75a93e9b39e5418a88c37d9d6 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Tue, 29 Jun 2021 18:53:14 -0700 Subject: [PATCH] added WEA Core --- worldeditadditions_core/init.lua | 18 ++++++++++++++++++ worldeditadditions_core/register/check.lua | 14 ++++++++++++++ worldeditadditions_core/register/init.lua | 15 +++++++++++++++ worldeditadditions_core/register/override.lua | 18 ++++++++++++++++++ worldeditadditions_core/register/register.lua | 18 ++++++++++++++++++ worldeditadditions_core/worldedit/init.lua | 5 +++++ 6 files changed, 88 insertions(+) create mode 100644 worldeditadditions_core/init.lua create mode 100644 worldeditadditions_core/register/check.lua create mode 100644 worldeditadditions_core/register/init.lua create mode 100644 worldeditadditions_core/register/override.lua create mode 100644 worldeditadditions_core/register/register.lua create mode 100644 worldeditadditions_core/worldedit/init.lua diff --git a/worldeditadditions_core/init.lua b/worldeditadditions_core/init.lua new file mode 100644 index 0000000..f4f2531 --- /dev/null +++ b/worldeditadditions_core/init.lua @@ -0,0 +1,18 @@ +--- WorldEditAdditions-Core +-- @module worldeditadditions_core +-- @release 1.13 +-- @copyright 2021 Starbeamrainbowlabs and VorTechnix +-- @license Mozilla Public License, 2.0 +-- @author Starbeamrainbowlabs and VorTechnix + +worldeditadditions_core = {} +local we_c = worldeditadditions_core + +we_c.modpath = minetest.get_modpath("worldeditadditions_core") + +-- Initialze WorldEdit stuff if the WorldEdit mod is not present +if not minetest.get_modpath("worldedit") then + dofile(we_c.modpath.."/worldedit/init.lua") +end + +dofile(we_c.modpath.."/register/init.lua") diff --git a/worldeditadditions_core/register/check.lua b/worldeditadditions_core/register/check.lua new file mode 100644 index 0000000..a08a40d --- /dev/null +++ b/worldeditadditions_core/register/check.lua @@ -0,0 +1,14 @@ +function worldeditadditions.register_command(def) + local def = table.copy(def) + assert(name and #name > 0) + assert(def.privs) + def.require_pos = def.require_pos or 0 + assert(def.require_pos >= 0 and def.require_pos < 3) + if def.params == "" and not def.parse then + def.parse = function(param) return true end + else + assert(def.parse) + end + assert(def.nodes_needed == nil or type(def.nodes_needed) == "function") + assert(def.func) +end diff --git a/worldeditadditions_core/register/init.lua b/worldeditadditions_core/register/init.lua new file mode 100644 index 0000000..ddf3499 --- /dev/null +++ b/worldeditadditions_core/register/init.lua @@ -0,0 +1,15 @@ +-- ██████ ███████ ██████ ██ ███████ ████████ ███████ ██████ +-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ██████ █████ ██ ███ ██ ███████ ██ █████ ██████ +-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ██ ██ ███████ ██████ ██ ███████ ██ ███████ ██ ██ + +-- WorldEditAdditions Register/Overwrite Functions + +--TODO: Replicate chatcommand_handler functionality (worldedit_commands/init.lua line 21-60) + +local we_cm = worldeditadditions_core.modpath .. "/register/" + +dofile(we_cm.."check.lua") +dofile(we_cm.."register.lua") +dofile(we_cm.."override.lua") diff --git a/worldeditadditions_core/register/override.lua b/worldeditadditions_core/register/override.lua new file mode 100644 index 0000000..e0d63db --- /dev/null +++ b/worldeditadditions_core/register/override.lua @@ -0,0 +1,18 @@ +local we_c = worldeditadditions_core +function we_c.override_command(name, def) + local success, def = we_c.check(def) + + if not success then + return false, def + end + + minetest.override_chatcommand("/" .. name, { + privs = def.privs, + params = def.params, + description = def.description, + func = function(player_name, param) + return chatcommand_handler(name, player_name, param) + end, + }) + worldedit.registered_commands[name] = def +end diff --git a/worldeditadditions_core/register/register.lua b/worldeditadditions_core/register/register.lua new file mode 100644 index 0000000..ebf8dfc --- /dev/null +++ b/worldeditadditions_core/register/register.lua @@ -0,0 +1,18 @@ +local we_c = worldeditadditions_core +function we_c.register_command(name, def) + local success, def = we_c.check(def) + + if not success then + return false, def + end + + minetest.register_chatcommand("/" .. name, { + privs = def.privs, + params = def.params, + description = def.description, + func = function(player_name, param) + return chatcommand_handler(name, player_name, param) + end, + }) + worldedit.registered_commands[name] = def +end diff --git a/worldeditadditions_core/worldedit/init.lua b/worldeditadditions_core/worldedit/init.lua new file mode 100644 index 0000000..fc4fd8b --- /dev/null +++ b/worldeditadditions_core/worldedit/init.lua @@ -0,0 +1,5 @@ +--- WorldEdit dependencies for WorldEditAdditions + +worldedit = { + registered_commands = {} +}