mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-12-22 11:45:00 +00:00
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!
This commit is contained in:
parent
b8a5bec987
commit
6f20b31763
8 changed files with 90 additions and 2 deletions
|
@ -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")
|
||||
|
|
|
@ -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.
|
||||
|
|
47
worldeditadditions/utils/raycast_adv.lua
Normal file
47
worldeditadditions/utils/raycast_adv.lua
Normal file
|
@ -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
|
2
worldeditadditions_farwand/depends.txt
Normal file
2
worldeditadditions_farwand/depends.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
worldedit
|
||||
worldeditadditions
|
1
worldeditadditions_farwand/edit/worldedit_wand.piskel
Normal file
1
worldeditadditions_farwand/edit/worldedit_wand.piskel
Normal file
|
@ -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=\"}]}"]}}
|
3
worldeditadditions_farwand/init.lua
Normal file
3
worldeditadditions_farwand/init.lua
Normal file
|
@ -0,0 +1,3 @@
|
|||
local modpath = minetest.get_modpath("worldeditadditions_farwand")
|
||||
|
||||
dofile(modpath.."/lib/farwand.lua")
|
20
worldeditadditions_farwand/lib/farwand.lua
Normal file
20
worldeditadditions_farwand/lib/farwand.lua
Normal file
|
@ -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
|
||||
})
|
Binary file not shown.
After Width: | Height: | Size: 261 B |
Loading…
Reference in a new issue