From 78572e453e674f276520c5df0bc5fc7f16160a6f Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Tue, 23 Feb 2021 22:56:56 +0000 Subject: [PATCH] Implement point cloud wand --- worldeditadditions/utils/vector.lua | 33 ++++++++++ .../edit/worldedit_wand.piskel | 2 +- worldeditadditions_farwand/init.lua | 2 + worldeditadditions_farwand/lib/cloudwand.lua | 58 ++++++++++++++++++ worldeditadditions_farwand/lib/do_raycast.lua | 17 +++++ .../textures/worldeditadditions_cloudwand.png | Bin 0 -> 181 bytes 6 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 worldeditadditions_farwand/lib/cloudwand.lua create mode 100644 worldeditadditions_farwand/lib/do_raycast.lua create mode 100644 worldeditadditions_farwand/textures/worldeditadditions_cloudwand.png diff --git a/worldeditadditions/utils/vector.lua b/worldeditadditions/utils/vector.lua index b7c2357..75f2b75 100644 --- a/worldeditadditions/utils/vector.lua +++ b/worldeditadditions/utils/vector.lua @@ -40,3 +40,36 @@ function worldeditadditions.vector.floor(v) -- Some vectors are 2d if v.z then v.z = math.floor(v.z) end end + +--- Determines if the target point is contained within the defined worldedit region. +-- @param pos1 Vector pos1 of the defined region. +-- @param pos2 Vector pos2 of the defined region. +-- @param target Vector The target vector to check. +-- @return boolean Whether the given target is contained within the defined worldedit region. +function worldeditadditions.vector.is_contained(pos1, pos2, target) + local pos1, pos2 = worldedit.sort_pos(pos1, pos2) + return pos1.x >= target.x + and pos1.y >= target.y + and pos1.z >= target.z + and pos2.x <= target.x + and pos2.y <= target.y + and pos2.z <= target.z +end + +--- Expands the defined region to include the given point. +-- @param pos1 Vector pos1 of the defined region. +-- @param pos2 Vector pos2 of the defined region. +-- @param target Vector The target vector to include. +function worldeditadditions.vector.expand_region(pos1, pos2, target) + local pos1, pos2 = worldedit.sort_pos(pos1, pos2) + + if target.x < pos1.x then pos1.x = target.x end + if target.y < pos1.y then pos1.y = target.y end + if target.z < pos1.z then pos1.z = target.z end + + if target.x > pos2.x then pos2.x = target.x end + if target.y > pos2.y then pos2.y = target.y end + if target.z > pos2.z then pos2.z = target.z end + + return pos1, pos2 +end diff --git a/worldeditadditions_farwand/edit/worldedit_wand.piskel b/worldeditadditions_farwand/edit/worldedit_wand.piskel index 4960e21..5a41af1 100644 --- a/worldeditadditions_farwand/edit/worldedit_wand.piskel +++ b/worldeditadditions_farwand/edit/worldedit_wand.piskel @@ -1 +1 @@ -{"modelVersion":2,"piskel":{"name":"worldedit_wand","description":"","fps":0,"height":16,"width":16,"layers":["{\"name\":\"Layer 1\",\"opacity\":1,\"frameCount\":3,\"chunks\":[{\"layout\":[[0],[1],[2]],\"base64PNG\":\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAQCAYAAABQrvyxAAACWklEQVRIS82WXUhTYRjH/yd31ra2viQ5cxFRJlbUKre6CI2gm6AP2kV4FVSGXiZFfoSErCi76OOmQLqJERWkkMFuKqQsShIxvQrbyMK2yMztzNa2sz1xFkdW2fa+BwXP9ft/zu/3vO/zniP4BJCtAniVlNAeCAvQ8WSelJIQlJGekmFoAFcNqW4hWVYasdT6DJOxXQi2ylx5wb9JoNfvCFv2V8PT+ZwrrLpSt43SkRSK4mJWAEnA0Mgusc8XoEk5lm3bj0QaAw3buBiEpjI7OStWYai3D+XbV+Po4w9cBajDRtqm6RUY+VaJlJxGkfgURx5Vo/XlT2aG6YU3qyQKhcOwbHCh6WE/cwHlKqYF1O5f7DZxAWy9V0IJOYX0FCE5fh/Heg5y5f8AvV5TRcGBXqx3O1F/5y27RPtvCRXeZTeiP5TkglCz3p2mbA3e/D+QbXskikbGYSmrhPduH7OEdoxUEF6I3HuDNz8j4GmPk6QFUQhmK075hue1xH/hmvfaabFZRGb5Wpy91TNvJfKCXajdTeJEEIogoqXzvS4JaYkZ4Uiceya0uSiULwh147iLPo8GIDo24tztFwXX//0dVM+0CjHyNY7Lb9ivx9yZypdnAmqpcVOpIYYvE1F4/WNMmVyRM24TrVuhXyJfnhnm/KE1ZBEFfFQW4VrXEHNOE5krCS6Qk57N5DDKiCkZtD0Y5cqqInMhwQ3ReECikmIrxhQrrvgGufOzLcENoHayuXYHJULDKHcUo77jE3eN2ZTgfrl2pi8dttEyRUZdF/uf50yDfcL/XReD1oRfxpVUxz8/zhUAAAAASUVORK5CYII=\"}]}"]}} \ No newline at end of file +{"modelVersion":2,"piskel":{"name":"worldedit_wand","description":"","fps":0,"height":16,"width":16,"layers":["{\"name\":\"Layer 1\",\"opacity\":1,\"frameCount\":4,\"chunks\":[{\"layout\":[[0],[1],[2],[3]],\"base64PNG\":\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAAAQCAYAAACm53kpAAACy0lEQVRYR92XXUhTYRzGn5M7083NMks2FxGmYp9Wal2ERhBE0Ad5EUIQfRh6mRT5ERJiX3bRx42BdBMjKkgpI28qLE3KEimlC5kbmugmms6d6dqX/ziLI1aa77sYjM71nv/7/H7vOe/ZEcwCSJ8JvPMZUGt1CAjjmnmZQoJNQnBKgqoUXDMMxbGkXaXGMt0bON27YKuSuPJKXSIi+4gbU9MBpKcmMs8QmjcJ9L6XsOVAPgoaWpmDsws36Sk46UeMRwwJgA9QlbFL2G+2klNyh8ZNe4PoKt3G3WHYIVFCggYulwfjTg82ZiYzzxDK04yUlbka3W0dyNi+Bide9DOH5dJUrydFRrgCLN+y4ZeCiBFf4dizfFS1f+fqYLFNULxWxb37cu/Zhe7kGcjucEC7PgflTzuZCwRuYlaAvPtXm+K4ALY+TCav5EdwiuAbe4STLYe48vKt/6V3FLFqEUP2MTidE+i5wi7xF9DbhXlk62rDutwslNz/zC6h9qcEGT7HqEan3ccFIWdrdsaFZvDmX7dbyGRcAa/Pjz5rf0jAYB27xD8gq/cYyDU5Bm1aNmoedDBLUB4DGYQXYu65y5t/8vwDydDHj+4VwpE4L+C5giwyLHFB0Ohw1twT9RJ+f3HxSFwQrmKfkRI0ImaWr8WFuy3/rYS/gl0u2k3iuA0BQURlQ19YEgxLNXBMerjPBOVciHR+Uai6Uzk0PGCFaNqAi/feLvr7+W5HGcIy6sH1j3yvt7kSIpVnAqoszKUUlRsj4y7UNA8xZeaKOJ8bR+krw5cQyTwzzKXDqaQVBXwNxONWYzdzThERSQiWf+8Lrc8FcqZgM5nUEtyBGVQ/HuDKyiWjUQI3RNlBAyUn6TAU0OGG+RN3PtokcAPIO1lRtIO89h5kmJJQUj/IPSOaJHCXV563a0f0lBiQUNzI/uU338F4unkirA6KxH/N/wCTFeDHmzMoJgAAAABJRU5ErkJggg==\"}]}"]}} \ No newline at end of file diff --git a/worldeditadditions_farwand/init.lua b/worldeditadditions_farwand/init.lua index 26cc902..c569ede 100644 --- a/worldeditadditions_farwand/init.lua +++ b/worldeditadditions_farwand/init.lua @@ -4,6 +4,8 @@ worldeditadditions.farwand = { 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/chatcommand.lua") dofile(modpath.."/lib/settings.lua") diff --git a/worldeditadditions_farwand/lib/cloudwand.lua b/worldeditadditions_farwand/lib/cloudwand.lua new file mode 100644 index 0000000..b65dec4 --- /dev/null +++ b/worldeditadditions_farwand/lib/cloudwand.lua @@ -0,0 +1,58 @@ +local function add_point(name, pos) + if pos ~= nil then + -- print("[set_pos1]", name, "("..pos.x..", "..pos.y..", "..pos.z..")") + if not worldedit.pos1[name] then worldedit.pos1[name] = vector.new(pos) end + if not worldedit.pos2[name] then worldedit.pos2[name] = vector.new(pos) end + + worldedit.marker_update(name) + + local volume_before = worldedit.volume(worldedit.pos1[name], worldedit.pos2[name]) + + worldedit.pos1[name], worldedit.pos2[name] = worldeditadditions.vector.expand_region(worldedit.pos1[name], worldedit.pos2[name], pos) + + local volume_after = worldedit.volume(worldedit.pos1[name], worldedit.pos2[name]) + + local volume_difference = volume_after - volume_before + + worldedit.marker_update(name) + worldedit.player_notify(name, "Expanded region by "..volume_difference.." nodes") + else + worldedit.player_notify(name, "Error: Too far away (try raising your maxdist with //farwand maxdist )") + -- print("[set_pos1]", name, "nil") + end +end +local function clear_points(name, pos) + worldedit.pos1[name] = nil + worldedit.pos2[name] = nil + worldedit.marker_update(name) + worldedit.set_pos[name] = nil +end + +minetest.register_tool(":worldeditadditions:cloudwand", { + description = "WorldEditAdditions far-reaching point cloud wand", + inventory_image = "worldeditadditions_cloudwand.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 + clear_points(name) + 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) + add_point(name, looking_pos) + -- Left click when pointing at something or nothing + end, + + on_secondary_use = function(itemstack, player, pointed_thing) + local name = player:get_player_name() + -- Right click when pointing at nothing + -- print("[farwand] on_secondary_use", name) + + clear_points(name) + end +}) diff --git a/worldeditadditions_farwand/lib/do_raycast.lua b/worldeditadditions_farwand/lib/do_raycast.lua new file mode 100644 index 0000000..11c3c5c --- /dev/null +++ b/worldeditadditions_farwand/lib/do_raycast.lua @@ -0,0 +1,17 @@ + +--- 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 = worldeditadditions.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/textures/worldeditadditions_cloudwand.png b/worldeditadditions_farwand/textures/worldeditadditions_cloudwand.png new file mode 100644 index 0000000000000000000000000000000000000000..fb3c1fc0b44d39090af4ac1e8cfee21d60fda019 GIT binary patch literal 181 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!73?$#)eFPFv5AX?b1=3}v9L?4ov%LftEZw#6M_dL4*kThZij=SxQcx75|bErN%ZEMu6O;?-m%A>ia@pqR?2(R@)rO~q%9 a0K>}J9QWj(gc}3RVeoYIb6Mw<&;$Tr&^}oJ literal 0 HcmV?d00001