mirror of
https://github.com/APercy/airutils.git
synced 2025-03-21 18:41:21 +00:00
tug tool is working, with area support
This commit is contained in:
parent
6dd0901601
commit
e9a73ef3c1
1 changed files with 54 additions and 27 deletions
|
@ -1,11 +1,39 @@
|
||||||
local function try_raycast(pos, look_dir)
|
local S = minetest.get_translator("airutils")
|
||||||
local raycast = minetest.raycast(pos, look_dir, true, false)
|
|
||||||
local pointed = raycast:next()
|
function airutils.move_target(player, pointed_thing)
|
||||||
while pointed do
|
local pos = player:get_pos()
|
||||||
if pointed and pointed.type == "object" and pointed.ref and not pointed.ref:is_player() then
|
local yaw = player:get_look_horizontal()
|
||||||
return pointed.ref
|
|
||||||
end
|
local object = pointed_thing.ref
|
||||||
pointed = raycast:next()
|
--minetest.chat_send_all(dump(object))
|
||||||
|
if object then
|
||||||
|
local obj_pos = object:get_pos()
|
||||||
|
local hip = math.sqrt(math.pow(obj_pos.x - pos.x,2)+math.pow(obj_pos.z - pos.z,2)) + 1
|
||||||
|
pos_x = math.sin(yaw) * -hip
|
||||||
|
pos_z = math.cos(yaw) * hip
|
||||||
|
obj_pos.x = pos.x + pos_x
|
||||||
|
obj_pos.z = pos.z + pos_z
|
||||||
|
|
||||||
|
local node = minetest.get_node(obj_pos).name
|
||||||
|
local nodedef = minetest.registered_nodes[node]
|
||||||
|
local is_airlike = nodedef.drawtype == "airlike"
|
||||||
|
|
||||||
|
if player:get_player_control().sneak == true then
|
||||||
|
local rotation = object:get_rotation()
|
||||||
|
rotation.y = yaw + math.rad(180)
|
||||||
|
object:set_rotation(rotation)
|
||||||
|
else
|
||||||
|
if is_airlike then object:set_pos(obj_pos) end
|
||||||
|
end
|
||||||
|
--[[if object:get_attach() then
|
||||||
|
local dir = player:get_look_dir()
|
||||||
|
minetest.chat_send_all('detach')
|
||||||
|
object:set_detach()
|
||||||
|
object:set_rotation(dir)
|
||||||
|
else
|
||||||
|
minetest.chat_send_all('object found')
|
||||||
|
object:set_attach(player, "", {x=0, y=0, z=20})
|
||||||
|
end]]--
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -18,28 +46,27 @@ minetest.register_tool("airutils:tug", {
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[local pos = player:get_pos()
|
local pos = player:get_pos()
|
||||||
local pname = player:get_player_name()
|
local pname = player:get_player_name()
|
||||||
|
|
||||||
local look_dir = player:get_look_dir()
|
if areas then
|
||||||
local object = try_raycast(pos, look_dir)
|
if not areas:canInteract(pos, pname) then
|
||||||
if object then
|
local owners = areas:getNodeOwners(pos)
|
||||||
if object:get_attach() then
|
minetest.chat_send_player(pname,
|
||||||
local dir = player:get_look_dir()
|
S("@1 is protected by @2.",
|
||||||
minetest.chat_send_all('detach')
|
minetest.pos_to_string(pos),
|
||||||
object:set_detach()
|
table.concat(owners, ", ")))
|
||||||
object:set_rotation(dir)
|
else
|
||||||
else
|
airutils.move_target(player, pointed_thing)
|
||||||
minetest.chat_send_all('object found')
|
|
||||||
object:set_attach(player, "", {x=0, y=0, z=20})
|
|
||||||
end
|
end
|
||||||
end]]--
|
else
|
||||||
end,
|
airutils.move_target(player, pointed_thing)
|
||||||
|
end
|
||||||
|
|
||||||
--[[on_secondary_use = function(itemstack, user, pointed_thing)
|
|
||||||
local object = user:get_attach()
|
end,
|
||||||
if object then user:set_detach() end
|
|
||||||
end,]]--
|
|
||||||
|
|
||||||
sound = {breaks = "default_tool_breaks"},
|
sound = {breaks = "default_tool_breaks"},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue