Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Farwand refactor #117

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ globals = {
"worldeditadditions",
"worldeditadditions_commands",
"worldeditadditions_core",
"worldeditadditions_tools"
}
-- Read-only globals
read_globals = {
Expand Down
9 changes: 6 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ 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.
- Added `//sgrow` and `//sshrink` commands to enlarge and shrink selection regions and aliased them over WorldEdit equivalents (`//expand`, `//outset` and `//contract`, `//inset` respectively).
- Added Unified Axis Syntax (UAS) parser. - Implementation by @VorTechnix
- See [UAS System reference] for details. (Note to self hook up hyperlink)
- See [UAS System reference](https://worldeditadditions.mooncarrot.space/Reference/#unified-axis-syntax-uas) for details.
- Added `//uasparse` command to show the vectors produced by a given UAS expression. - Implementation by @VorTechnix
- Added `//tool` command to list available tools and give tools to players. (Requires players to have the `weatool` privilege) - Implementation by @VorTechnix
- Added `weatool` privilege. - Implementation by @VorTechnix

### Bugfixes and changes
- When commands produce an error, the name of the command that produced the error is now also printed. Useful when using e.g. [`//multi`](https://worldeditadditions.mooncarrot.space/Reference/#multi) etc.
Expand All @@ -36,6 +38,7 @@ Note to self: See the bottom of this file for the release template text.

### Lua API changes
- Add `core.pos.get12(player_name, sort=false)`
- Add `tools.register_tool(name, tool_def)` - Implementation by @VorTechnix


## v1.14.5: The multipoint update, hotfix 5 (1st August 2023)
Expand Down Expand Up @@ -63,7 +66,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
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 15 additions & 4 deletions Chat-Command-Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1896,8 +1896,19 @@ Prevents the execution of a command if it could potentially affect a large numbe
██ ██████ ██████ ███████ ███████
-->

### `//tool list || give|exists <tool name>`
> Added in v1.15

Lists available tools, allowes player to check if a specific tool exists and gives tools on demand as long as the player doesn't already have them, has room in their inventory, and has the `weatool` privilege.

```weacmd
//tool list
//tool give cloudwand
//tool exists multiwand
```

### 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.

Expand All @@ -1908,7 +1919,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_farwand.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.

Expand Down Expand Up @@ -1941,7 +1952,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.

Expand All @@ -1953,7 +1964,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.

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ The detailed explanations have moved! Check them out [here](https://worldeditadd
- [WorldEditAdditions Far Wand](https://github.com/sbrl/Minetest-WorldEditAdditions/blob/main/Chat-Command-Reference.md#far-wand)
- [WorldEditAdditions Cloud Wand](https://github.com/sbrl/Minetest-WorldEditAdditions/blob/main/Chat-Command-Reference.md#cloud-wand)
- [`//farwand skip_liquid (true|false) | maxdist <number>`](https://github.com/sbrl/Minetest-WorldEditAdditions/blob/main/Chat-Command-Reference.md#farwand-skip_liquid-truefalse--maxdist-number)
- [`//tool list || give|exists <tool name>`](https://github.com/sbrl/Minetest-WorldEditAdditions/blob/main/Chat-Command-Reference.md#tool-list-giveexists-tool-name) _(new in v1.15)_


## Installation
Expand Down
3 changes: 2 additions & 1 deletion worldeditadditions_core/core/pos.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ local function compat_worldedit_pos2_get(player_name)
end

--- Sets pos1/pos2 in worldedit for compatibility.
-- @internal
-- @param player_name string The name of the player to set the position for.
-- @param i number The index of the position to set.
-- @param pos Vector3 The position to set.
Expand All @@ -106,6 +107,7 @@ local function compat_worldedit_set(player_name, i, pos, do_update)
end

--- Fetches pos1/pos2 from WorldEdit (if available) and sets them in WorldEditAdditions' postional subsystem
-- @internal
-- @param player_name string The name of the player to sync the positions for.
local function compat_worldedit_get(player_name)
compat_worldedit_pos1_get(player_name)
Expand Down Expand Up @@ -334,7 +336,6 @@ anchor = wea_c.EventEmitter.new({
set_all = set_all,
unmark = unmark,
mark = mark,
compat_worldedit_get = compat_worldedit_get,
})
anchor.debug = false

Expand Down
14 changes: 0 additions & 14 deletions worldeditadditions_farwand/init.lua

This file was deleted.

17 changes: 0 additions & 17 deletions worldeditadditions_farwand/lib/do_raycast.lua

This file was deleted.

3 changes: 0 additions & 3 deletions worldeditadditions_farwand/mod.conf

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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
Expand Down
64 changes: 64 additions & 0 deletions worldeditadditions_tools/commands/weatool.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
-- ██ ██ ███████ █████ ████████ ██████ ██████ ██
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
-- ██ █ ██ █████ ███████ ██ ██ ██ ██ ██ ██
-- ██ ███ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
-- ███ ███ ███████ ██ ██ ██ ██████ ██████ ███████

local wea_c = worldeditadditions_core
local wea_t = worldeditadditions_tools

worldeditadditions_core.register_command("tool", {
params = "list || give|exists <tool name> ",
description = "Give WEA tools by name to the calling player or list available tools.",
privs = { worldedit = true, weatool = 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,
})
30 changes: 30 additions & 0 deletions worldeditadditions_tools/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---@diagnostic disable-next-line: lowercase-global
worldeditadditions_tools = {
player_data = {},
registered_tools = {},
}
local wea_t = worldeditadditions_tools

minetest.register_privilege("weatool", {
description = "Allows players to use WEA tools.",
give_to_singleplayer = true,
give_to_admin = true,
})
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")
Original file line number Diff line number Diff line change
@@ -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",

Expand All @@ -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 = wea_t.do_raycast(player)
wea.selection.add_point(name, looking_pos)
-- Left click when pointing at something or nothing
end,
Expand Down
Original file line number Diff line number Diff line change
@@ -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..")")
Expand All @@ -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 = wea_t.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 = wea_t.do_raycast(player)
set_pos1(name, looking_pos)
-- Left click when pointing at something or nothing
end,
Expand All @@ -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 = wea_t.do_raycast(player)
set_pos2(name, looking_pos)
end
})
Loading
Loading