139 lines
4.1 KiB
Lua
139 lines
4.1 KiB
Lua
|
|
minetest.register_tool("advtrains:1",
|
|
{
|
|
description = "1",
|
|
groups = {cracky=1}, -- key=name, value=rating; rating=1..3.
|
|
inventory_image = "drwho_screwdriver.png",
|
|
wield_image = "drwho_screwdriver.png",
|
|
stack_max = 1,
|
|
range = 7.0,
|
|
on_use = function(itemstack, user, pointed_thing)
|
|
pos1=pointed_thing.under
|
|
end,
|
|
})
|
|
minetest.register_tool("advtrains:2",
|
|
{
|
|
description = "2",
|
|
groups = {cracky=1}, -- key=name, value=rating; rating=1..3.
|
|
inventory_image = "drwho_screwdriver.png",
|
|
wield_image = "drwho_screwdriver.png",
|
|
stack_max = 1,
|
|
range = 7.0,
|
|
on_use = function(itemstack, user, pointed_thing)
|
|
pos2=pointed_thing.under
|
|
end,
|
|
})
|
|
minetest.register_tool("advtrains:3",
|
|
{
|
|
description = "3",
|
|
groups = {cracky=1}, -- key=name, value=rating; rating=1..3.
|
|
inventory_image = "drwho_screwdriver.png",
|
|
wield_image = "drwho_screwdriver.png",
|
|
stack_max = 1,
|
|
range = 7.0,
|
|
on_use = function(itemstack, user, pointed_thing)
|
|
pos3=pointed_thing.under
|
|
end,
|
|
})
|
|
minetest.register_tool("advtrains:4",
|
|
{
|
|
description = "4",
|
|
groups = {cracky=1}, -- key=name, value=rating; rating=1..3.
|
|
inventory_image = "drwho_screwdriver.png",
|
|
wield_image = "drwho_screwdriver.png",
|
|
stack_max = 1,
|
|
range = 7.0,
|
|
on_use = function(itemstack, user, pointed_thing)
|
|
pos4=pointed_thing.under
|
|
end,
|
|
})
|
|
core.register_chatcommand("mad", {
|
|
params="",
|
|
description="",
|
|
privs={},
|
|
func = function(name, param)
|
|
return true, advtrains.get_wagon_yaw(pos1, pos2, pos3, pos4, tonumber(param))*2*math.pi/360
|
|
end,
|
|
})
|
|
|
|
advtrains.firstobject=nil
|
|
minetest.register_tool("advtrains:connect",
|
|
{
|
|
description = "connect wagons tool",
|
|
groups = {cracky=1}, -- key=name, value=rating; rating=1..3.
|
|
inventory_image = "drwho_screwdriver.png",
|
|
wield_image = "drwho_screwdriver.png",
|
|
stack_max = 1,
|
|
range = 7.0,
|
|
|
|
on_place = function(itemstack, placer, pointed_thing)
|
|
|
|
end,
|
|
--[[
|
|
^ Shall place item and return the leftover itemstack
|
|
^ default: minetest.item_place ]]
|
|
on_use = function(itemstack, user, pointed_thing)
|
|
if pointed_thing.type=="object" then
|
|
local luaent=pointed_thing.ref:get_luaentity()
|
|
if luaent and luaent.is_wagon then
|
|
if advtrains.firstobject then
|
|
minetest.chat_send_all("connect second object "..luaent.unique_id)
|
|
advtrains.connect_wagons(luaent, advtrains.firstobject)
|
|
minetest.chat_send_all("done")
|
|
advtrains.firstobject=nil
|
|
else
|
|
advtrains.firstobject=luaent
|
|
minetest.chat_send_all("connect first object "..luaent.unique_id)
|
|
end
|
|
end
|
|
end
|
|
end,
|
|
--[[
|
|
^ default: nil
|
|
^ Function must return either nil if no item shall be removed from
|
|
inventory, or an itemstack to replace the original itemstack.
|
|
e.g. itemstack:take_item(); return itemstack
|
|
^ Otherwise, the function is free to do what it wants.
|
|
^ The default functions handle regular use cases.
|
|
]]
|
|
})
|
|
minetest.register_tool("advtrains:tttool",
|
|
{
|
|
description = "traintester tool",
|
|
groups = {cracky=1}, -- key=name, value=rating; rating=1..3.
|
|
inventory_image = "drwho_screwdriver.png",
|
|
wield_image = "drwho_screwdriver.png",
|
|
stack_max = 1,
|
|
range = 7.0,
|
|
|
|
on_place = function(itemstack, placer, pointed_thing)
|
|
|
|
end,
|
|
--[[
|
|
^ Shall place item and return the leftover itemstack
|
|
^ default: minetest.item_place ]]
|
|
on_use = function(itemstack, user, pointed_thing)
|
|
if pointed_thing.type=="object" then
|
|
local luaent=pointed_thing.ref:get_luaentity()
|
|
if luaent and luaent.is_wagon then
|
|
minetest.chat_send_all("wagon yaw is "..pointed_thing.ref:getyaw())
|
|
minetest.chat_send_all("trains last yaw is set to "..luaent:train().last_front_yaw)
|
|
minetest.chat_send_all("end report")
|
|
end
|
|
else
|
|
minetest.chat_send_all(dump(minetest.get_node(pointed_thing.under)))
|
|
local c1, c2=advtrains.get_track_connections(minetest.get_node(pointed_thing.under).name, minetest.get_node(pointed_thing.under).param2)
|
|
minetest.chat_send_all(c1.." <-> "..c2)
|
|
end
|
|
end,
|
|
--[[
|
|
^ default: nil
|
|
^ Function must return either nil if no item shall be removed from
|
|
inventory, or an itemstack to replace the original itemstack.
|
|
e.g. itemstack:take_item(); return itemstack
|
|
^ Otherwise, the function is free to do what it wants.
|
|
^ The default functions handle regular use cases.
|
|
]]
|
|
}
|
|
)
|