mirror of
https://github.com/APercy/airutils.git
synced 2025-03-21 18:41:21 +00:00
creating the base for tug tool
This commit is contained in:
parent
79a41bc86e
commit
6dd0901601
4 changed files with 185 additions and 134 deletions
138
airutils_papi.lua
Normal file
138
airutils_papi.lua
Normal file
|
@ -0,0 +1,138 @@
|
||||||
|
|
||||||
|
|
||||||
|
function airutils.PAPIplace(player,pos)
|
||||||
|
local dir = minetest.dir_to_facedir(player:get_look_dir())
|
||||||
|
local pos1 = vector.new(pos)
|
||||||
|
core.set_node(pos, {name="airutils:papi", param2=dir})
|
||||||
|
local player_name = player:get_player_name()
|
||||||
|
local meta = core.get_meta(pos)
|
||||||
|
meta:set_string("infotext", "PAPI\rOwned by: "..player_name)
|
||||||
|
meta:set_string("owner", player_name)
|
||||||
|
meta:set_string("dont_destroy", "false")
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
function airutils.togglePapiSide(pos, node, clicker, itemstack)
|
||||||
|
local player_name = clicker:get_player_name()
|
||||||
|
local meta = core.get_meta(pos)
|
||||||
|
|
||||||
|
if player_name ~= meta:get_string("owner") then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local dir=node.param2
|
||||||
|
if node.name == "airutils:papi_right" then
|
||||||
|
core.set_node(pos, {name="airutils:papi", param2=dir})
|
||||||
|
meta:set_string("infotext", "PAPI - left side\rOwned by: "..player_name)
|
||||||
|
elseif node.name == "airutils:papi" then
|
||||||
|
core.set_node(pos, {name="airutils:papi_right", param2=dir})
|
||||||
|
meta:set_string("infotext", "PAPI - right side\rOwned by: "..player_name)
|
||||||
|
end
|
||||||
|
|
||||||
|
meta:set_string("owner", player_name)
|
||||||
|
meta:set_string("dont_destroy", "false")
|
||||||
|
end
|
||||||
|
|
||||||
|
airutils.papi_collision_box = {
|
||||||
|
type = "fixed",
|
||||||
|
fixed={{-0.5,-0.5,-0.5,0.5,-0.42,0.5},},
|
||||||
|
}
|
||||||
|
|
||||||
|
airutils.papi_selection_box = {
|
||||||
|
type = "fixed",
|
||||||
|
fixed={{-0.5,-0.5,-0.5,0.5,1.5,0.5},},
|
||||||
|
}
|
||||||
|
|
||||||
|
airutils.groups_right = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1}
|
||||||
|
airutils.groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}
|
||||||
|
|
||||||
|
-- PAPI node (default left)
|
||||||
|
minetest.register_node("airutils:papi",{
|
||||||
|
description = "PAPI",
|
||||||
|
inventory_image = "papi.png",
|
||||||
|
wield_image = "papi.png",
|
||||||
|
tiles = {"airutils_black.png", "airutils_u_black.png", "airutils_white.png",
|
||||||
|
"airutils_metal.png", {name = "airutils_red.png", backface_culling = true},},
|
||||||
|
groups = airutils.groups,
|
||||||
|
paramtype2 = "facedir",
|
||||||
|
paramtype = "light",
|
||||||
|
drawtype = "mesh",
|
||||||
|
mesh = "papi.b3d",
|
||||||
|
visual_scale = 1.0,
|
||||||
|
light_source = 13,
|
||||||
|
backface_culling = true,
|
||||||
|
selection_box = airutils.papi_selection_box,
|
||||||
|
collision_box = airutils.papi_collision_box,
|
||||||
|
can_dig = airutils.canDig,
|
||||||
|
_color = "",
|
||||||
|
on_destruct = airutils.remove,
|
||||||
|
on_place = function(itemstack, placer, pointed_thing)
|
||||||
|
local pos = pointed_thing.above
|
||||||
|
if airutils.PAPIplace(placer,pos)==true then
|
||||||
|
itemstack:take_item(1)
|
||||||
|
return itemstack
|
||||||
|
else
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
on_rightclick=airutils.togglePapiSide,
|
||||||
|
on_punch = function(pos, node, puncher, pointed_thing)
|
||||||
|
local player_name = puncher:get_player_name()
|
||||||
|
local meta = core.get_meta(pos)
|
||||||
|
if player_name ~= meta:get_string("owner") then
|
||||||
|
local privs = minetest.get_player_privs(player_name)
|
||||||
|
if privs.server == false then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local itmstck=puncher:get_wielded_item()
|
||||||
|
local item_name = ""
|
||||||
|
if itmstck then item_name = itmstck:get_name() end
|
||||||
|
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
-- PAPI right node
|
||||||
|
minetest.register_node("airutils:papi_right",{
|
||||||
|
description = "PAPI_right_side",
|
||||||
|
tiles = {"airutils_black.png", "airutils_u_black.png", "airutils_white.png",
|
||||||
|
"airutils_metal.png", {name = "airutils_red.png", backface_culling = true},},
|
||||||
|
groups = airutils.groups_right,
|
||||||
|
paramtype2 = "facedir",
|
||||||
|
paramtype = "light",
|
||||||
|
drawtype = "mesh",
|
||||||
|
mesh = "papi_right.b3d",
|
||||||
|
visual_scale = 1.0,
|
||||||
|
light_source = 13,
|
||||||
|
backface_culling = true,
|
||||||
|
selection_box = airutils.papi_selection_box,
|
||||||
|
collision_box = airutils.papi_collision_box,
|
||||||
|
can_dig = airutils.canDig,
|
||||||
|
_color = "",
|
||||||
|
on_destruct = airutils.remove,
|
||||||
|
on_rightclick=airutils.togglePapiSide,
|
||||||
|
on_punch = function(pos, node, puncher, pointed_thing)
|
||||||
|
local player_name = puncher:get_player_name()
|
||||||
|
local meta = core.get_meta(pos)
|
||||||
|
if player_name ~= meta:get_string("owner") then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local itmstck=puncher:get_wielded_item()
|
||||||
|
local item_name = ""
|
||||||
|
if itmstck then item_name = itmstck:get_name() end
|
||||||
|
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
-- PAPI craft
|
||||||
|
minetest.register_craft({
|
||||||
|
output = 'airutils:papi',
|
||||||
|
recipe = {
|
||||||
|
{'default:glass', 'default:mese_crystal', 'default:glass'},
|
||||||
|
{'default:glass', 'default:steel_ingot' , 'default:glass'},
|
||||||
|
{'' , 'default:steel_ingot' , ''},
|
||||||
|
}
|
||||||
|
})
|
45
airutils_tug.lua
Normal file
45
airutils_tug.lua
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
local function try_raycast(pos, look_dir)
|
||||||
|
local raycast = minetest.raycast(pos, look_dir, true, false)
|
||||||
|
local pointed = raycast:next()
|
||||||
|
while pointed do
|
||||||
|
if pointed and pointed.type == "object" and pointed.ref and not pointed.ref:is_player() then
|
||||||
|
return pointed.ref
|
||||||
|
end
|
||||||
|
pointed = raycast:next()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.register_tool("airutils:tug", {
|
||||||
|
description = "Tug tool for airport",
|
||||||
|
inventory_image = "airutils_tug.png",
|
||||||
|
stack_max=1,
|
||||||
|
on_use = function(itemstack, player, pointed_thing)
|
||||||
|
if not player then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[local pos = player:get_pos()
|
||||||
|
local pname = player:get_player_name()
|
||||||
|
|
||||||
|
local look_dir = player:get_look_dir()
|
||||||
|
local object = try_raycast(pos, look_dir)
|
||||||
|
if object then
|
||||||
|
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,
|
||||||
|
|
||||||
|
--[[on_secondary_use = function(itemstack, user, pointed_thing)
|
||||||
|
local object = user:get_attach()
|
||||||
|
if object then user:set_detach() end
|
||||||
|
end,]]--
|
||||||
|
|
||||||
|
sound = {breaks = "default_tool_breaks"},
|
||||||
|
})
|
136
init.lua
136
init.lua
|
@ -2,17 +2,8 @@
|
||||||
|
|
||||||
airutils = {}
|
airutils = {}
|
||||||
|
|
||||||
function airutils.PAPIplace(player,pos)
|
dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "airutils_papi.lua")
|
||||||
local dir = minetest.dir_to_facedir(player:get_look_dir())
|
dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "airutils_tug.lua")
|
||||||
local pos1 = vector.new(pos)
|
|
||||||
core.set_node(pos, {name="airutils:papi", param2=dir})
|
|
||||||
local player_name = player:get_player_name()
|
|
||||||
local meta = core.get_meta(pos)
|
|
||||||
meta:set_string("infotext", "PAPI\rOwned by: "..player_name)
|
|
||||||
meta:set_string("owner", player_name)
|
|
||||||
meta:set_string("dont_destroy", "false")
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
function airutils.remove(pos)
|
function airutils.remove(pos)
|
||||||
local meta = core.get_meta(pos)
|
local meta = core.get_meta(pos)
|
||||||
|
@ -28,128 +19,5 @@ function airutils.canDig(pos, player)
|
||||||
and player:get_player_name() == meta:get_string("owner")
|
and player:get_player_name() == meta:get_string("owner")
|
||||||
end
|
end
|
||||||
|
|
||||||
function airutils.togglePapiSide(pos, node, clicker, itemstack)
|
|
||||||
local player_name = clicker:get_player_name()
|
|
||||||
local meta = core.get_meta(pos)
|
|
||||||
|
|
||||||
if player_name ~= meta:get_string("owner") then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local dir=node.param2
|
|
||||||
if node.name == "airutils:papi_right" then
|
|
||||||
core.set_node(pos, {name="airutils:papi", param2=dir})
|
|
||||||
meta:set_string("infotext", "PAPI - left side\rOwned by: "..player_name)
|
|
||||||
elseif node.name == "airutils:papi" then
|
|
||||||
core.set_node(pos, {name="airutils:papi_right", param2=dir})
|
|
||||||
meta:set_string("infotext", "PAPI - right side\rOwned by: "..player_name)
|
|
||||||
end
|
|
||||||
|
|
||||||
meta:set_string("owner", player_name)
|
|
||||||
meta:set_string("dont_destroy", "false")
|
|
||||||
end
|
|
||||||
|
|
||||||
airutils.collision_box = {
|
|
||||||
type = "fixed",
|
|
||||||
fixed={{-0.5,-0.5,-0.5,0.5,-0.42,0.5},},
|
|
||||||
}
|
|
||||||
|
|
||||||
airutils.selection_box = {
|
|
||||||
type = "fixed",
|
|
||||||
fixed={{-0.5,-0.5,-0.5,0.5,1.5,0.5},},
|
|
||||||
}
|
|
||||||
|
|
||||||
airutils.groups_right = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1}
|
|
||||||
airutils.groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}
|
|
||||||
|
|
||||||
-- PAPI node (default left)
|
|
||||||
minetest.register_node("airutils:papi",{
|
|
||||||
description = "PAPI",
|
|
||||||
inventory_image = "papi.png",
|
|
||||||
wield_image = "papi.png",
|
|
||||||
tiles = {"airutils_black.png", "airutils_u_black.png", "airutils_white.png",
|
|
||||||
"airutils_metal.png", {name = "airutils_red.png", backface_culling = true},},
|
|
||||||
groups = airutils.groups,
|
|
||||||
paramtype2 = "facedir",
|
|
||||||
paramtype = "light",
|
|
||||||
drawtype = "mesh",
|
|
||||||
mesh = "papi.b3d",
|
|
||||||
visual_scale = 1.0,
|
|
||||||
light_source = 13,
|
|
||||||
backface_culling = true,
|
|
||||||
selection_box = airutils.selection_box,
|
|
||||||
collision_box = airutils.collision_box,
|
|
||||||
can_dig = airutils.canDig,
|
|
||||||
_color = "",
|
|
||||||
on_destruct = airutils.remove,
|
|
||||||
on_place = function(itemstack, placer, pointed_thing)
|
|
||||||
local pos = pointed_thing.above
|
|
||||||
if airutils.PAPIplace(placer,pos)==true then
|
|
||||||
itemstack:take_item(1)
|
|
||||||
return itemstack
|
|
||||||
else
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
on_rightclick=airutils.togglePapiSide,
|
|
||||||
on_punch = function(pos, node, puncher, pointed_thing)
|
|
||||||
local player_name = puncher:get_player_name()
|
|
||||||
local meta = core.get_meta(pos)
|
|
||||||
if player_name ~= meta:get_string("owner") then
|
|
||||||
local privs = minetest.get_player_privs(player_name)
|
|
||||||
if privs.server == false then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local itmstck=puncher:get_wielded_item()
|
|
||||||
local item_name = ""
|
|
||||||
if itmstck then item_name = itmstck:get_name() end
|
|
||||||
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
-- PAPI right node
|
|
||||||
minetest.register_node("airutils:papi_right",{
|
|
||||||
description = "PAPI_right_side",
|
|
||||||
tiles = {"airutils_black.png", "airutils_u_black.png", "airutils_white.png",
|
|
||||||
"airutils_metal.png", {name = "airutils_red.png", backface_culling = true},},
|
|
||||||
groups = airutils.groups_right,
|
|
||||||
paramtype2 = "facedir",
|
|
||||||
paramtype = "light",
|
|
||||||
drawtype = "mesh",
|
|
||||||
mesh = "papi_right.b3d",
|
|
||||||
visual_scale = 1.0,
|
|
||||||
light_source = 13,
|
|
||||||
backface_culling = true,
|
|
||||||
selection_box = airutils.selection_box,
|
|
||||||
collision_box = airutils.collision_box,
|
|
||||||
can_dig = airutils.canDig,
|
|
||||||
_color = "",
|
|
||||||
on_destruct = airutils.remove,
|
|
||||||
on_rightclick=airutils.togglePapiSide,
|
|
||||||
on_punch = function(pos, node, puncher, pointed_thing)
|
|
||||||
local player_name = puncher:get_player_name()
|
|
||||||
local meta = core.get_meta(pos)
|
|
||||||
if player_name ~= meta:get_string("owner") then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local itmstck=puncher:get_wielded_item()
|
|
||||||
local item_name = ""
|
|
||||||
if itmstck then item_name = itmstck:get_name() end
|
|
||||||
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
-- PAPI craft
|
|
||||||
minetest.register_craft({
|
|
||||||
output = 'airutils:papi',
|
|
||||||
recipe = {
|
|
||||||
{'default:glass', 'default:mese_crystal', 'default:glass'},
|
|
||||||
{'default:glass', 'default:steel_ingot' , 'default:glass'},
|
|
||||||
{'' , 'default:steel_ingot' , ''},
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
BIN
textures/airutils_tug.png
Normal file
BIN
textures/airutils_tug.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.9 KiB |
Loading…
Add table
Reference in a new issue