From d53f4f8702c3faec9e2f51d0782a6ea94c96c821 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Wed, 9 Oct 2024 20:35:45 -0700 Subject: [PATCH] Initial refactor --- CHANGELOG.md | 4 +- CONTRIBUTING.md | 2 +- Chat-Command-Reference.md | 8 +- worldeditadditions_farwand/init.lua | 14 --- worldeditadditions_farwand/lib/do_raycast.lua | 17 ---- worldeditadditions_farwand/mod.conf | 3 - .../.edit/brush.piskel | 0 .../.edit/worldedit_wand.piskel | 0 .../.edit/worldeditadditions_movement.piskel | 0 .../commands/farwand_config.lua | 2 +- worldeditadditions_tools/commands/weatool.lua | 64 ++++++++++++ worldeditadditions_tools/init.lua | 24 +++++ .../items}/cloudwand.lua | 5 +- .../items}/farwand.lua | 12 ++- .../items}/movetool.lua | 11 +- .../items}/multiwand.lua | 3 +- worldeditadditions_tools/lib/do_raycast.lua | 17 ++++ .../lib/register_tool.lua | 94 ++++++++++++++++++ .../lib/settings.lua | 12 +-- worldeditadditions_tools/mod.conf | 3 + .../textures/worldeditadditions_chisel.png | Bin .../textures/worldeditadditions_cloudwand.png | Bin .../textures/worldeditadditions_farwand.png | Bin .../textures/worldeditadditions_movement.png | Bin .../textures/worldeditadditions_multiwand.png | Bin 25 files changed, 234 insertions(+), 61 deletions(-) delete mode 100644 worldeditadditions_farwand/init.lua delete mode 100644 worldeditadditions_farwand/lib/do_raycast.lua delete mode 100644 worldeditadditions_farwand/mod.conf rename {worldeditadditions_farwand => worldeditadditions_tools}/.edit/brush.piskel (100%) rename {worldeditadditions_farwand => worldeditadditions_tools}/.edit/worldedit_wand.piskel (100%) rename {worldeditadditions_farwand => worldeditadditions_tools}/.edit/worldeditadditions_movement.piskel (100%) rename worldeditadditions_farwand/lib/chatcommand.lua => worldeditadditions_tools/commands/farwand_config.lua (96%) create mode 100644 worldeditadditions_tools/commands/weatool.lua create mode 100644 worldeditadditions_tools/init.lua rename {worldeditadditions_farwand/lib => worldeditadditions_tools/items}/cloudwand.lua (87%) rename {worldeditadditions_farwand/lib => worldeditadditions_tools/items}/farwand.lua (82%) rename {worldeditadditions_farwand/lib => worldeditadditions_tools/items}/movetool.lua (83%) rename {worldeditadditions_farwand/lib => worldeditadditions_tools/items}/multiwand.lua (96%) create mode 100644 worldeditadditions_tools/lib/do_raycast.lua create mode 100644 worldeditadditions_tools/lib/register_tool.lua rename {worldeditadditions_farwand => worldeditadditions_tools}/lib/settings.lua (71%) create mode 100644 worldeditadditions_tools/mod.conf rename {worldeditadditions_farwand => worldeditadditions_tools}/textures/worldeditadditions_chisel.png (100%) rename {worldeditadditions_farwand => worldeditadditions_tools}/textures/worldeditadditions_cloudwand.png (100%) rename {worldeditadditions_farwand => worldeditadditions_tools}/textures/worldeditadditions_farwand.png (100%) rename {worldeditadditions_farwand => worldeditadditions_tools}/textures/worldeditadditions_movement.png (100%) rename {worldeditadditions_farwand => worldeditadditions_tools}/textures/worldeditadditions_multiwand.png (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index d8dd4d7..34ef006 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ Note to self: See the bottom of this file for the release template text. - Added [`//ngroups`](https://worldeditadditions.mooncarrot.space/Reference/#ngroups), which lists the groups that a given node is a member of. Useful when paired with [`//nodeapply`](https://worldeditadditions.mooncarrot.space/Reference/#nodeapply)! - Added [`//rotate+`](https://worldeditadditions.mooncarrot.space/Reference/#rotate) to rotate regions through arbitrary series of potentially non-axis-aligned rotations. **Does not support slabs/stairs yet,** but this is on the todo list! - Added [`//speed`](https://worldeditadditions.mooncarrot.space/Reference/#speed) to adjust your own movement speed - - Also added an associated [movement speed adjustment tool](https://worldeditadditions.mooncarrot.space/Reference/#movement), which looks like this: ![A picture of the move speed adjustment tool. It looks like a monarch butterfly.](https://raw.githubusercontent.com/sbrl/Minetest-WorldEditAdditions/dev/worldeditadditions_farwand/textures/worldeditadditions_movement.png) + - Also added an associated [movement speed adjustment tool](https://worldeditadditions.mooncarrot.space/Reference/#movement), which looks like this: ![A picture of the move speed adjustment tool. It looks like a monarch butterfly.](https://raw.githubusercontent.com/sbrl/Minetest-WorldEditAdditions/dev/worldeditadditions_tools/textures/worldeditadditions_movement.png) - Added [`//set+`](https://worldeditadditions.mooncarrot.space/Reference/#set) for setting nodes and param2/light levels quickly. - NOTE TO SELF: Setting light values doesn't appear to be working very well for some reason - Added [`//ndef`](https://worldeditadditions.mooncarrot.space/Reference/#ndef) to print a given node's definition table. This is for debugging and development purposes. @@ -63,7 +63,7 @@ Note to self: See the bottom of this file for the release template text. - Add `//dome+`, which allows you to change the direction the dome is pointing in, and also create multiple domes at once - Add `//metaball`, which renders 2 or more [metaballs](https://en.wikipedia.org/wiki/Metaballs) in Minetest - Significant backend refactoring to tidy things up - - Add new multi-point selection wand ![A picture of the multi-point wand](https://raw.githubusercontent.com/sbrl/Minetest-WorldEditAdditions/main/worldeditadditions_farwand/textures/worldeditadditions_multiwand.png) to select many points at once. + - Add new multi-point selection wand ![A picture of the multi-point wand](https://raw.githubusercontent.com/sbrl/Minetest-WorldEditAdditions/main/worldeditadditions_tools/textures/worldeditadditions_multiwand.png) to select many points at once. - Implement custom region boxing UI, which replaces the WorldEdit region box when using WorldEditAdditions wands. - Is backwards compatible with regular WorldEdit wands and tools, as WorldEditAdditions keeps the new positioning system in sync with WorldEdit's. - The new multipoint wand required this as a prerequisite diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 791815c..a72417e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -11,7 +11,7 @@ Name | Description --------------------------------|------------------------ `worldeditadditions` | The main mod. Core world manipulation implementations (backed by the `*_core` mod ref core and utility functions) should go in here. `worldeditadditions_commands` | Chat commands. These interact with the core manipulators in `worldeditadditions` mod. -`worldeditadditions_farwand` | Everything to do with the far wand tool, and now other tools like the cloud wand, multi-point wand, etc. It's different enough to everything else that it warrants it's own separate mod to avoid muddling things. +`worldeditadditions_tools` | Everything to do with the far wand tool, and now other tools like the cloud wand, multi-point wand, etc. It's different enough to everything else that it warrants it's own separate mod to avoid muddling things. `worldeditadditions_core` | Core components such as the positioning system (`worldeditadditions_core.pos`), the command registration function, and utility functions go in here. Additionally, every command should be implemented in its own file. This helps keep things organised and files short. diff --git a/Chat-Command-Reference.md b/Chat-Command-Reference.md index d608396..d45196b 100644 --- a/Chat-Command-Reference.md +++ b/Chat-Command-Reference.md @@ -1897,7 +1897,7 @@ Prevents the execution of a command if it could potentially affect a large numbe --> ### Movement speed adjustment tool -The movement speed adjustment tool, as the name suggests, adjusts your local player movement speed. It looks like this: ![A picture of the move speed adjustment tool. It looks like a monarch butterfly.](https://raw.githubusercontent.com/sbrl/Minetest-WorldEditAdditions/dev/worldeditadditions_farwand/textures/worldeditadditions_movement.png). +The movement speed adjustment tool, as the name suggests, adjusts your local player movement speed. It looks like this: ![A picture of the move speed adjustment tool. It looks like a monarch butterfly.](https://raw.githubusercontent.com/sbrl/Minetest-WorldEditAdditions/dev/worldeditadditions_tools/textures/worldeditadditions_movement.png). Primary (left) clicking will increase your movement speed, and secondary (right) clicking will decrease it in x0.5 increments, down to a minimum of x0.5. @@ -1908,7 +1908,7 @@ See also [`//speed`](#speed). ### Far Wand > Added in v1.7 -The far wand (`worldeditadditions:farwand`) is a variant on the traditional WorldEdit wand (`worldedit:wand`). It looks like this: ![A picture of the far wand](https://raw.githubusercontent.com/sbrl/Minetest-WorldEditAdditions/main/worldeditadditions_farwand/textures/worldeditadditions_farwand.png) +The far wand (`worldeditadditions:farwand`) is a variant on the traditional WorldEdit wand (`worldedit:wand`). It looks like this: ![A picture of the far wand](https://raw.githubusercontent.com/sbrl/Minetest-WorldEditAdditions/main/worldeditadditions_tools/textures/worldeditadditions_tools.png) It functions very similarly to the regular WorldEdit wand, except that it has a _much_ longer range - which can be very useful for working on large-scale terrain for example. It also comes with an associated command to control it. @@ -1941,7 +1941,7 @@ Note that the number there isn't in blocks (because hard maths). It is however p ### Cloud Wand > Added in v1.11 -The cloud wand (`worldeditadditions:cloudwand`) is a another variant the above _Far Wand_. It looks like this: ![A picture of the far wand](https://raw.githubusercontent.com/sbrl/Minetest-WorldEditAdditions/main/worldeditadditions_farwand/textures/worldeditadditions_cloudwand.png) +The cloud wand (`worldeditadditions:cloudwand`) is a another variant the above _Far Wand_. It looks like this: ![A picture of the far wand](https://raw.githubusercontent.com/sbrl/Minetest-WorldEditAdditions/main/worldeditadditions_tools/textures/worldeditadditions_cloudwand.png) Unlike the other 2 wands, this wand functions in an additive manner. Left-click on a node to expand the currently defined region (creating a new one if one isn't defined already) to include that node. Right click to clear the currently defined region. @@ -1953,7 +1953,7 @@ Note that punching out the positions **does not unset them**. Use `//reset` to r ### MultiPoint Wand > Added in v1.14 -The third type of wand provided by WorldEditAdditions is completely different, in that it allows you to select up to **999 points** at once! It looks like this: ![A picture of the multi-point wand](https://raw.githubusercontent.com/sbrl/Minetest-WorldEditAdditions/main/worldeditadditions_farwand/textures/worldeditadditions_multiwand.png) +The third type of wand provided by WorldEditAdditions is completely different, in that it allows you to select up to **999 points** at once! It looks like this: ![A picture of the multi-point wand](https://raw.githubusercontent.com/sbrl/Minetest-WorldEditAdditions/main/worldeditadditions_tools/textures/worldeditadditions_multiwand.png) It is important to note that (at present) the points selected by this wand **are not compatible with normal points**. This will change in the future, but requires a lot of work to implement. diff --git a/worldeditadditions_farwand/init.lua b/worldeditadditions_farwand/init.lua deleted file mode 100644 index d5da5e9..0000000 --- a/worldeditadditions_farwand/init.lua +++ /dev/null @@ -1,14 +0,0 @@ -worldeditadditions.farwand = { - player_data = {} -} - -local modpath = minetest.get_modpath("worldeditadditions_farwand") - -dofile(modpath.."/lib/do_raycast.lua") -dofile(modpath.."/lib/farwand.lua") -dofile(modpath.."/lib/cloudwand.lua") -dofile(modpath.."/lib/multiwand.lua") -dofile(modpath.."/lib/movetool.lua") - -dofile(modpath.."/lib/chatcommand.lua") -dofile(modpath.."/lib/settings.lua") diff --git a/worldeditadditions_farwand/lib/do_raycast.lua b/worldeditadditions_farwand/lib/do_raycast.lua deleted file mode 100644 index ea99022..0000000 --- a/worldeditadditions_farwand/lib/do_raycast.lua +++ /dev/null @@ -1,17 +0,0 @@ -local wea_c = worldeditadditions_core ---- worldeditadditions.raycast() wrapper -function worldeditadditions.farwand.do_raycast(player) - if player == nil then return nil end - local player_name = player:get_player_name() - - if worldeditadditions.farwand.player_data[player_name] == nil then - worldeditadditions.farwand.player_data[player_name] = { maxdist = 1000, skip_liquid = true } - end - - local looking_pos, node_id = wea_c.raycast( - player, - worldeditadditions.farwand.player_data[player_name].maxdist, - worldeditadditions.farwand.player_data[player_name].skip_liquid - ) - return looking_pos, node_id -end diff --git a/worldeditadditions_farwand/mod.conf b/worldeditadditions_farwand/mod.conf deleted file mode 100644 index 6a00c47..0000000 --- a/worldeditadditions_farwand/mod.conf +++ /dev/null @@ -1,3 +0,0 @@ -name = worldeditadditions_farwand -description = worldeditadditions: convenient tool items -depends = worldedit, worldeditadditions diff --git a/worldeditadditions_farwand/.edit/brush.piskel b/worldeditadditions_tools/.edit/brush.piskel similarity index 100% rename from worldeditadditions_farwand/.edit/brush.piskel rename to worldeditadditions_tools/.edit/brush.piskel diff --git a/worldeditadditions_farwand/.edit/worldedit_wand.piskel b/worldeditadditions_tools/.edit/worldedit_wand.piskel similarity index 100% rename from worldeditadditions_farwand/.edit/worldedit_wand.piskel rename to worldeditadditions_tools/.edit/worldedit_wand.piskel diff --git a/worldeditadditions_farwand/.edit/worldeditadditions_movement.piskel b/worldeditadditions_tools/.edit/worldeditadditions_movement.piskel similarity index 100% rename from worldeditadditions_farwand/.edit/worldeditadditions_movement.piskel rename to worldeditadditions_tools/.edit/worldeditadditions_movement.piskel diff --git a/worldeditadditions_farwand/lib/chatcommand.lua b/worldeditadditions_tools/commands/farwand_config.lua similarity index 96% rename from worldeditadditions_farwand/lib/chatcommand.lua rename to worldeditadditions_tools/commands/farwand_config.lua index 4df3a08..5d71c46 100644 --- a/worldeditadditions_farwand/lib/chatcommand.lua +++ b/worldeditadditions_tools/commands/farwand_config.lua @@ -1,5 +1,5 @@ local wea_c = worldeditadditions_core -local farwand = worldeditadditions.farwand -- Convenience shurtcut +local farwand = worldeditadditions_tools -- Convenience shurtcut local function parse_params_farwand(params_text) if params_text == nil then diff --git a/worldeditadditions_tools/commands/weatool.lua b/worldeditadditions_tools/commands/weatool.lua new file mode 100644 index 0000000..f8886c5 --- /dev/null +++ b/worldeditadditions_tools/commands/weatool.lua @@ -0,0 +1,64 @@ +-- ██ ██ ███████ █████ ████████ ██████ ██████ ██ +-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ██ █ ██ █████ ███████ ██ ██ ██ ██ ██ ██ +-- ██ ███ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ███ ███ ███████ ██ ██ ██ ██████ ██████ ███████ + +local wea_c = worldeditadditions_core +local wea_t = worldeditadditions_tools + +worldeditadditions_core.register_command("tool", { + params = "list || give|exists ", + description = "Give WEA tools by name to the calling player or list available tools.", + privs = { worldedit = true, give = true }, + require_pos = 0, + parse = function(params_text) + local ret = wea_c.split(params_text) + if #ret < 1 then return false, "Error: No params found!" end + + local commands = {list = true, give = true, exists = true} + if not commands[ret[1]] then + return false, "Invalid command: "..ret[1] + end + + if wea_t.registered_tools[ret[2]] or ret[1] == "list" then + return true, ret + else return false, "No such WEA tool: "..ret[2] end + end, + func = function(name, params_text) + if params_text[1] == "list" then + -- Return a list of available tools in rows of 7 + local ret = "WEA Registered Tools:\n" + local i = 0 + for k, _ in pairs(wea_t.registered_tools) do + i = i + 1 + if i % 7 == 0 then ret = ret..k.."\n" + else ret = ret..k.." " end + end + return true, ret + elseif params_text[1] == "exists" then + -- NOTE: If tool did not exist it would be flagged by parse function + return true, "WEA tool \""..params_text[2].."\" exists" + else + -- Initiate player variable and check if it is a valid player + local player = minetest.get_player_by_name(name) + if not player or not player:is_player() then + return false, "\""..name.."\" is not a valid player." + end + -- Create inventory and item instances + local inv = player:get_inventory() + local item = "worldeditadditions:"..params_text[2] + -- Make sure the player doesn't already have the item and has room for it + if inv:contains_item("main", item) then + return false, name.." already has (a) \""..params_text[2].."\"." + elseif not inv:room_for_item("main", item) then + return false, name.." does not have room for (a) \""..params_text[2].."\"." + else + -- Give the player the item + inv:add_item("main", item) + return true, "Gave \""..params_text[2].."\" to "..name + end + + end + end, +}) \ No newline at end of file diff --git a/worldeditadditions_tools/init.lua b/worldeditadditions_tools/init.lua new file mode 100644 index 0000000..98e8068 --- /dev/null +++ b/worldeditadditions_tools/init.lua @@ -0,0 +1,24 @@ +worldeditadditions_tools = { + player_data = {}, + registered_tools = {}, +} +local wea_t = worldeditadditions_tools + +local modpath = minetest.get_modpath("worldeditadditions_tools") + + +-- Libraries +dofile(modpath.."/lib/do_raycast.lua") +dofile(modpath.."/lib/settings.lua") + +wea_t.register_tool = dofile(modpath.."/lib/register_tool.lua") + +-- Items +dofile(modpath.."/items/farwand.lua") +dofile(modpath.."/items/cloudwand.lua") +dofile(modpath.."/items/multiwand.lua") +dofile(modpath.."/items/movetool.lua") + +-- Chat commands +dofile(modpath.."/commands/farwand_config.lua") +dofile(modpath.."/commands/weatool.lua") diff --git a/worldeditadditions_farwand/lib/cloudwand.lua b/worldeditadditions_tools/items/cloudwand.lua similarity index 87% rename from worldeditadditions_farwand/lib/cloudwand.lua rename to worldeditadditions_tools/items/cloudwand.lua index a880aea..4df41a9 100644 --- a/worldeditadditions_farwand/lib/cloudwand.lua +++ b/worldeditadditions_tools/items/cloudwand.lua @@ -1,7 +1,8 @@ local wea = worldeditadditions local wea_c = worldeditadditions_core +local wea_t = worldeditadditions_tools -minetest.register_tool(":worldeditadditions:cloudwand", { +wea_t.register_tool("cloudwand", { description = "WorldEditAdditions far-reaching additive selector wand", inventory_image = "worldeditadditions_cloudwand.png", @@ -16,7 +17,7 @@ minetest.register_tool(":worldeditadditions:cloudwand", { on_use = function(itemstack, player, pointed_thing) local name = player:get_player_name() -- print("[farwand] on_use", name) - local looking_pos, node_id = worldeditadditions.farwand.do_raycast(player) + local looking_pos, node_id = worldeditadditions_tools.do_raycast(player) wea.selection.add_point(name, looking_pos) -- Left click when pointing at something or nothing end, diff --git a/worldeditadditions_farwand/lib/farwand.lua b/worldeditadditions_tools/items/farwand.lua similarity index 82% rename from worldeditadditions_farwand/lib/farwand.lua rename to worldeditadditions_tools/items/farwand.lua index 56a9a2a..4411491 100644 --- a/worldeditadditions_farwand/lib/farwand.lua +++ b/worldeditadditions_tools/items/farwand.lua @@ -1,3 +1,5 @@ +local wea_t = worldeditadditions_tools + local function set_pos1(name, pos) if pos ~= nil then -- print("[set_pos1]", name, "("..pos.x..", "..pos.y..", "..pos.z..")") @@ -21,23 +23,23 @@ local function set_pos2(name, pos) end end -minetest.register_tool(":worldeditadditions:farwand", { +wea_t.register_tool("farwand", { description = "WorldEditAdditions far-reaching wand", - inventory_image = "worldeditadditions_farwand.png", + inventory_image = "worldeditadditions_tools.png", on_place = function(itemstack, player, pointed_thing) local name = player:get_player_name() -- print("[farwand] on_place", name) -- Right click when pointing at something -- Pointed thing: https://rubenwardy.com/minetest_modding_book/lua_api.html#pointed_thing - local looking_pos, node_id = worldeditadditions.farwand.do_raycast(player) + local looking_pos, node_id = worldeditadditions_tools.do_raycast(player) set_pos2(name, looking_pos) end, on_use = function(itemstack, player, pointed_thing) local name = player:get_player_name() -- print("[farwand] on_use", name) - local looking_pos, node_id = worldeditadditions.farwand.do_raycast(player) + local looking_pos, node_id = worldeditadditions_tools.do_raycast(player) set_pos1(name, looking_pos) -- Left click when pointing at something or nothing end, @@ -47,7 +49,7 @@ minetest.register_tool(":worldeditadditions:farwand", { -- Right click when pointing at nothing -- print("[farwand] on_secondary_use", name) - local looking_pos, node_id = worldeditadditions.farwand.do_raycast(player) + local looking_pos, node_id = worldeditadditions_tools.do_raycast(player) set_pos2(name, looking_pos) end }) diff --git a/worldeditadditions_farwand/lib/movetool.lua b/worldeditadditions_tools/items/movetool.lua similarity index 83% rename from worldeditadditions_farwand/lib/movetool.lua rename to worldeditadditions_tools/items/movetool.lua index d91528c..8d1b241 100644 --- a/worldeditadditions_farwand/lib/movetool.lua +++ b/worldeditadditions_tools/items/movetool.lua @@ -1,7 +1,8 @@ -local weac = worldeditadditions_core +local wea_c = worldeditadditions_core +local wea_t = worldeditadditions_tools local function adjust_speed_relative(player, offset) - local overrides = weac.player_get_physics_override( + local overrides = wea_c.player_get_physics_override( player, "worldeditadditions_movetool" ) if overrides == nil then overrides = {} end @@ -10,7 +11,7 @@ local function adjust_speed_relative(player, offset) local src_speed = overrides.speed or 1 local src_climb_speed = overrides.climb_speed or 1 - weac.player_set_physics_override( + wea_c.player_set_physics_override( player, "worldeditadditions_movetool", { speed = math.max(src_speed + offset, 0.5), climb_speed = math.max(src_climb_speed + offset, 0.5) @@ -20,7 +21,7 @@ local function adjust_speed_relative(player, offset) -- }) -- Completely paranoid is me - local overrides_after = weac.player_get_physics_override( + local overrides_after = wea_c.player_get_physics_override( player, "worldeditadditions_movetool" ) worldedit.player_notify(player:get_player_name(), "Movement speed is now x" .. tostring(overrides_after.speed)) @@ -36,7 +37,7 @@ local function use_secondary(player) end -minetest.register_tool(":worldeditadditions:movetool", { +wea_t.register_tool("movetool", { description = "WorldEditAdditions movement speed adjustment tool", inventory_image = "worldeditadditions_movement.png", diff --git a/worldeditadditions_farwand/lib/multiwand.lua b/worldeditadditions_tools/items/multiwand.lua similarity index 96% rename from worldeditadditions_farwand/lib/multiwand.lua rename to worldeditadditions_tools/items/multiwand.lua index 09cb1e1..b036c61 100644 --- a/worldeditadditions_farwand/lib/multiwand.lua +++ b/worldeditadditions_tools/items/multiwand.lua @@ -1,4 +1,5 @@ local wea_c = worldeditadditions_core +local wea_t = worldeditadditions_tools local wea = worldeditadditions local Vector3 = wea_c.Vector3 @@ -25,7 +26,7 @@ local function pop_pos(player_name) end -minetest.register_tool(":worldeditadditions:multiwand", { +wea_t.register_tool("multiwand", { description = "WorldEditAdditions multi-point wand", inventory_image = "worldeditadditions_multiwand.png", diff --git a/worldeditadditions_tools/lib/do_raycast.lua b/worldeditadditions_tools/lib/do_raycast.lua new file mode 100644 index 0000000..bb08a76 --- /dev/null +++ b/worldeditadditions_tools/lib/do_raycast.lua @@ -0,0 +1,17 @@ +local wea_c = worldeditadditions_core +--- worldeditadditions.raycast() wrapper +function worldeditadditions_tools.do_raycast(player) + if player == nil then return nil end + local player_name = player:get_player_name() + + if worldeditadditions_tools.player_data[player_name] == nil then + worldeditadditions_tools.player_data[player_name] = { maxdist = 1000, skip_liquid = true } + end + + local looking_pos, node_id = wea_c.raycast( + player, + worldeditadditions_tools.player_data[player_name].maxdist, + worldeditadditions_tools.player_data[player_name].skip_liquid + ) + return looking_pos, node_id +end diff --git a/worldeditadditions_tools/lib/register_tool.lua b/worldeditadditions_tools/lib/register_tool.lua new file mode 100644 index 0000000..2182ea4 --- /dev/null +++ b/worldeditadditions_tools/lib/register_tool.lua @@ -0,0 +1,94 @@ +-- ██████ ███████ ██████ ██ ███████ ████████ ███████ ██████ +-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ██████ █████ ██ ███ ██ ███████ ██ █████ ██████ +-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ██ ██ ███████ ██████ ██ ███████ ██ ███████ ██ ██ +-- +-- ████████ ██████ ██████ ██ +-- ██ ██ ██ ██ ██ ██ +-- ██ ██ ██ ██ ██ ██ +-- ██ ██ ██ ██ ██ ██ +-- ██ ██████ ██████ ███████ + +--- WorldEditAdditions tool registration +-- A wrapper for registering tools for WorldEditAdditions. +-- @module worldeditadditions_core + +local wea_t = worldeditadditions_tools + +-- Helper functions -- +local function log_error(toolname, error_message) + minetest.log("error", "register_tool("..toolname..") error: "..error_message) +end + +local function log_warn(toolname, error_message) + minetest.log("warning", "register_tool("..toolname..") warning: "..error_message) +end + + +--- Registers a new WorldEditAdditions tool. +-- @param tool string The name of the tool to register. +-- @param options table A table of options for the tool: +-- - `description` (string) A description of the tool. +-- - `inventory_image` (string) The path to the image for the tool. +-- - `on_use` (function) A function that is called when right click while pointing at something. +-- - `on_place` (function) A function that is called when left click while pointing at something. +-- - `on_secondary_use` (function) A function that is called when left click while pointing at nothing. +-- - `stack_max` (number) The maximum number of the items that can be put in an ItemStack. +-- - `groups` (table) A table of groups that the tool belongs to. +local function register_tool(tool, options) + + --- + -- 1: Validation + --- + if type(options.description) ~= "string" then + log_error(tool, "The description option is not a string.") + return false + end + if type(options.inventory_image) ~= "string" then + log_error(tool, "The inventory_image option is not a string.") + return false + end + if not options.inventory_image:match("^.+%.png$") then + log_error(tool, "The inventory_image option is not a valid image path.") + return false + end + if type(options.on_use) ~= "function" then + if options.on_use == nil then + log_warn(tool, "The on_use option is nil.") + else + log_error(tool, "The on_use option is not a function.") + return false + end + end + if type(options.on_place) ~= "function" then + if options.on_place == nil then + log_warn(tool, "The on_place option is nil.") + else + log_error(tool, "The on_place option is not a function.") + return false + end + end + if type(options.on_secondary_use) ~= "function" then + if options.on_secondary_use == nil then + log_warn(tool, "The on_secondary_use option is nil.") + else + log_error(tool, "The on_secondary_use option is not a function.") + return false + end + end + + --- + -- 2: Normalisation + --- + if not options.stack_max then options.stack_max = 1 end + if not options.groups then options.groups = {wea = 1, wand = 1} end + + --- + -- 3: Registration + --- + minetest.register_tool(":worldeditadditions:" .. tool, options) + wea_t.registered_tools[tool] = options +end + +return register_tool \ No newline at end of file diff --git a/worldeditadditions_farwand/lib/settings.lua b/worldeditadditions_tools/lib/settings.lua similarity index 71% rename from worldeditadditions_farwand/lib/settings.lua rename to worldeditadditions_tools/lib/settings.lua index 8e1cddb..d6dd939 100644 --- a/worldeditadditions_farwand/lib/settings.lua +++ b/worldeditadditions_tools/lib/settings.lua @@ -1,9 +1,9 @@ --- If the settings object for the given player name doesn't exist, it is created. -- @param name The name of the player to ensure has a settings object. local function settings_init(name) - if worldeditadditions.farwand.player_data[name] == nil then + if worldeditadditions_tools.player_data[name] == nil then minetest.log("INFO", "Initialising settings for "..name) - worldeditadditions.farwand.player_data[name] = { + worldeditadditions_tools.player_data[name] = { maxdist = 1000, skip_liquid = true } @@ -14,10 +14,10 @@ end -- @param string name The name of the player to get the setting for. -- @param string setting_name The name of the setting to fetch. -- @return any The value of the setting. -function worldeditadditions.farwand.setting_get(name, setting_name) +function worldeditadditions_tools.setting_get(name, setting_name) if setting_name == nil then return nil end settings_init(name) - return worldeditadditions.farwand.player_data[name][setting_name] + return worldeditadditions_tools.player_data[name][setting_name] end --- Sets a given farwand setting for the given player name to the given value. @@ -25,9 +25,9 @@ end -- @param string setting_name The name of the setting to set. -- @param any setting_value The value to set the setting to. -- @return bool Whether setting the setting was successful or not. -function worldeditadditions.farwand.setting_set(name, setting_name, setting_value) +function worldeditadditions_tools.setting_set(name, setting_name, setting_value) if setting_name == nil then return false end settings_init(name) - worldeditadditions.farwand.player_data[name][setting_name] = setting_value + worldeditadditions_tools.player_data[name][setting_name] = setting_value return true end diff --git a/worldeditadditions_tools/mod.conf b/worldeditadditions_tools/mod.conf new file mode 100644 index 0000000..c5ce9fa --- /dev/null +++ b/worldeditadditions_tools/mod.conf @@ -0,0 +1,3 @@ +name = worldeditadditions_tools +description = worldeditadditions: convenient tool items +depends = worldedit, worldeditadditions, worldeditadditions_core diff --git a/worldeditadditions_farwand/textures/worldeditadditions_chisel.png b/worldeditadditions_tools/textures/worldeditadditions_chisel.png similarity index 100% rename from worldeditadditions_farwand/textures/worldeditadditions_chisel.png rename to worldeditadditions_tools/textures/worldeditadditions_chisel.png diff --git a/worldeditadditions_farwand/textures/worldeditadditions_cloudwand.png b/worldeditadditions_tools/textures/worldeditadditions_cloudwand.png similarity index 100% rename from worldeditadditions_farwand/textures/worldeditadditions_cloudwand.png rename to worldeditadditions_tools/textures/worldeditadditions_cloudwand.png diff --git a/worldeditadditions_farwand/textures/worldeditadditions_farwand.png b/worldeditadditions_tools/textures/worldeditadditions_farwand.png similarity index 100% rename from worldeditadditions_farwand/textures/worldeditadditions_farwand.png rename to worldeditadditions_tools/textures/worldeditadditions_farwand.png diff --git a/worldeditadditions_farwand/textures/worldeditadditions_movement.png b/worldeditadditions_tools/textures/worldeditadditions_movement.png similarity index 100% rename from worldeditadditions_farwand/textures/worldeditadditions_movement.png rename to worldeditadditions_tools/textures/worldeditadditions_movement.png diff --git a/worldeditadditions_farwand/textures/worldeditadditions_multiwand.png b/worldeditadditions_tools/textures/worldeditadditions_multiwand.png similarity index 100% rename from worldeditadditions_farwand/textures/worldeditadditions_multiwand.png rename to worldeditadditions_tools/textures/worldeditadditions_multiwand.png