From 6f20b31763ceb5849d4b47026d792a813d201d9d Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Sat, 13 Jun 2020 02:08:03 +0100 Subject: [PATCH] Strat work on a far-reaching wand, but it isn't finished yet. We've got all the backend functions we'll probably need implemented though! --- worldeditadditions/init.lua | 1 + worldeditadditions/utils/nodes.lua | 18 ++++++- worldeditadditions/utils/raycast_adv.lua | 47 ++++++++++++++++++ worldeditadditions_farwand/depends.txt | 2 + .../edit/worldedit_wand.piskel | 1 + worldeditadditions_farwand/init.lua | 3 ++ worldeditadditions_farwand/lib/farwand.lua | 20 ++++++++ .../textures/worldeditadditions_farwand.png | Bin 0 -> 261 bytes 8 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 worldeditadditions/utils/raycast_adv.lua create mode 100644 worldeditadditions_farwand/depends.txt create mode 100644 worldeditadditions_farwand/edit/worldedit_wand.piskel create mode 100644 worldeditadditions_farwand/init.lua create mode 100644 worldeditadditions_farwand/lib/farwand.lua create mode 100644 worldeditadditions_farwand/textures/worldeditadditions_farwand.png diff --git a/worldeditadditions/init.lua b/worldeditadditions/init.lua index cef29a9..7758048 100644 --- a/worldeditadditions/init.lua +++ b/worldeditadditions/init.lua @@ -11,6 +11,7 @@ dofile(worldeditadditions.modpath.."/utils/strings.lua") dofile(worldeditadditions.modpath.."/utils/numbers.lua") dofile(worldeditadditions.modpath.."/utils/nodes.lua") dofile(worldeditadditions.modpath.."/utils/tables.lua") +dofile(worldeditadditions.modpath.."/utils/raycast_adv.lua") -- For the farwand dofile(worldeditadditions.modpath.."/utils.lua") dofile(worldeditadditions.modpath.."/lib/floodfill.lua") diff --git a/worldeditadditions/utils/nodes.lua b/worldeditadditions/utils/nodes.lua index 336ebc5..3161697 100644 --- a/worldeditadditions/utils/nodes.lua +++ b/worldeditadditions/utils/nodes.lua @@ -32,7 +32,7 @@ local node_id_air = minetest.get_content_id("air") local node_id_ignore = minetest.get_content_id("ignore") --- Determines whether the given node/content id is an airlike node or not. --- @param id number The content/node id to check. +-- @param id number The content/node id to check. -- @return bool Whether the given node/content id is an airlike node or not. function worldeditadditions.is_airlike(id) -- Do a fast check against air and ignore @@ -42,13 +42,13 @@ function worldeditadditions.is_airlike(id) return false end - local name = minetest.get_name_from_content_id(id) -- If the node isn't registered, then it might not be an air node if not minetest.registered_nodes[id] then return false end if minetest.registered_nodes[id].sunlight_propagates == true then return true end -- Check for membership of the airlike group + local name = minetest.get_name_from_content_id(id) local airlike_value = minetest.get_item_group(name, "airlike") if airlike_value ~= nil and airlike_value > 0 then return true @@ -61,6 +61,20 @@ function worldeditadditions.is_airlike(id) return false end +--- Determines whether the given node/content id is a liquid-ish node or not. +-- @param id number The content/node id to check. +-- @return bool Whether the given node/content id is a liquid-ish node or not. +function worldeditadditions.is_liquidlike(id) + if id == node_id_ignore then return false end + if not minetest.registered_nodes[id] then return false end + + local liquidtype = minetest.registered_nodes[id].liquidtype + + if liquidtype == nil or liquidtype == "none" then return false end + -- If it's not none, then it has to be a liquid as the only other values are source and flowing + return true +end + --- Given a manip object and associates, generates a 2D x/z heightmap. -- Note that pos1 and pos2 should have already been pushed through -- worldedit.sort_pos(pos1, pos2) before passing them to this function. diff --git a/worldeditadditions/utils/raycast_adv.lua b/worldeditadditions/utils/raycast_adv.lua new file mode 100644 index 0000000..575112f --- /dev/null +++ b/worldeditadditions/utils/raycast_adv.lua @@ -0,0 +1,47 @@ + +--- Raycasts to find a node in the direction the given player is looking. +-- @param player Player The player object to raycast from. +-- @param maxdist number The maximum distance to raycast. +-- @param skip_liquid bool Whether to skip liquids when raycasting. +-- @return position, number nil if nothing was found (or unloaded chunks were hit), or the position as an {x, y, z} table and the node id if something was found. +function worldeditadditions.raycast(player, maxdist, skip_liquid) + if maxdist == nil then maxdist = 100 end + if skip_liquid == nil then skip_liquid = false end + local look_dir = player:get_look_dir() + + local node_id_ignore = minetest.get_content_id("ignore") + local cur_pos = {} + local player_pos = player:getpos() + player_pos.y = player_pos.y + 1.5 -- Calculate from the eye position + + for i = 1, maxdist do + local j = i / 10 + + cur_pos.x = (look_dir.x*j) + player_pos.x + cur_pos.y = (look_dir.y*j) + player_pos.y + cur_pos.z = (look_dir.z*j) + player_pos.z + + local found_node = false + + local node = minetest.get_node_or_nil(cur_pos) + if node ~= nil then + local node_id = minetest.get_content_id(node.name) + local is_air = worldeditadditions.is_airlike(node_id) + + -- ignore = unloaded chunks, as far as I can tell + if node_id == node_id_ignore then + return nil + end + + if is_air == false then + if skip_liquid == true then + return cur_pos, node_id + elseif worldeditadditions.is_liquidlike(node_id) == true then + return cur_pos, node_id + end + end + end + end + + return nil +end diff --git a/worldeditadditions_farwand/depends.txt b/worldeditadditions_farwand/depends.txt new file mode 100644 index 0000000..3db9cda --- /dev/null +++ b/worldeditadditions_farwand/depends.txt @@ -0,0 +1,2 @@ +worldedit +worldeditadditions diff --git a/worldeditadditions_farwand/edit/worldedit_wand.piskel b/worldeditadditions_farwand/edit/worldedit_wand.piskel new file mode 100644 index 0000000..4960e21 --- /dev/null +++ b/worldeditadditions_farwand/edit/worldedit_wand.piskel @@ -0,0 +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 diff --git a/worldeditadditions_farwand/init.lua b/worldeditadditions_farwand/init.lua new file mode 100644 index 0000000..91723bc --- /dev/null +++ b/worldeditadditions_farwand/init.lua @@ -0,0 +1,3 @@ +local modpath = minetest.get_modpath("worldeditadditions_farwand") + +dofile(modpath.."/lib/farwand.lua") diff --git a/worldeditadditions_farwand/lib/farwand.lua b/worldeditadditions_farwand/lib/farwand.lua new file mode 100644 index 0000000..85db6cf --- /dev/null +++ b/worldeditadditions_farwand/lib/farwand.lua @@ -0,0 +1,20 @@ +minetest.register_tool(":worldeditadditions:farwand", { + description = "WorldEditAdditions far-reaching wand", + inventory_image = "worldeditadditions_farwand.png", + + on_place = function(itemstack, player, pointed_thing) + print("[farwand] on_place", player:get_player_name()) + -- Right click when pointing at something + end, + + on_use = function(itemstack, player, pointed_thing) + print("[farwand] on_use", player:get_player_name()) + -- Left click when pointing at something or nothing + end, + + on_secondary_use = function(itemstack, player, pointed_thing) + -- Right click when pointing at nothing + + print("[farwand] on_secondary_use", player:get_player_name()) + end +}) diff --git a/worldeditadditions_farwand/textures/worldeditadditions_farwand.png b/worldeditadditions_farwand/textures/worldeditadditions_farwand.png new file mode 100644 index 0000000000000000000000000000000000000000..e1c55cc41bedaff9be597aabf1d6ba8a0612cec3 GIT binary patch literal 261 zcmV+g0s8)lP)Sj)Gce;Ljd8j)_m?YG7Zzd!$F zU}oLR5VzTmq4wwxq77j*Tp{-V=jY!Hf4}}``1NKbL(+bK(hPukx7nKGKZtE2$;NQz z`7fdk!Eh?bAW{s$>Q_<>!5LV@8iF^pL54{1b27a6_#J1M5R5LEA-7+DXXrYO8NCDz z0L4t1DaU_RQBDSIh7e@{K0}B$0GA;o8Gy|Yk_|vNge(J)4FLe7l6Saj9QY9c0000< LMNUMnLSTXbB!O$_ literal 0 HcmV?d00001