2 if (minetest
.get_modpath("intllib")) then
5 S
= function(s
,a
,...)a
={a
,...}return s
:gsub("@(%d+)",function(n
)return a
[tonumber(n
)]end)end
8 local returnmirror
= {}
9 returnmirror
.cost_teleport
= 200
10 returnmirror
.cost_set
= 20
12 if tonumber(minetest
.setting_get("returnmirror_cost_teleport")) ~= nil then
13 returnmirror
.cost_teleport
= tonumber(minetest
.setting_get("returnmirror_cost_teleport"))
15 if tonumber(minetest
.setting_get("returnmirror_cost_set")) ~= nil then
16 returnmirror
.cost_set
= tonumber(minetest
.setting_get("returnmirror_cost_set"))
19 if minetest
.get_modpath("mana") ~= nil then
20 returnmirror
.mana
= true
22 returnmirror
.mana
= false
25 returnmirror
.mana_check
= function(player
, cost
)
27 if returnmirror
.mana
then
28 if mana
.subtract(player
:get_player_name(), cost
) then
39 returnmirror
.set_position_inactive
= function(itemstack
, user
, pointed_thing
)
40 -- Use pointed node's on_rightclick function first, if present
41 if pointed_thing
.type == "node" then
42 local node
= minetest
.get_node(pointed_thing
.under
)
43 if user
and not user
:get_player_control().sneak
then
44 if minetest
.registered_nodes
[node
.name
] and minetest
.registered_nodes
[node
.name
].on_rightclick
then
45 return minetest
.registered_nodes
[node
.name
].on_rightclick(pointed_thing
.under
, node
, user
, itemstack
) or itemstack
50 if returnmirror
.mana_check(user
, returnmirror
.cost_set
) then
51 local pos
= user
:getpos()
52 local newitem
= ItemStack("returnmirror:mirror_active")
53 newitem
:set_metadata(minetest
.pos_to_string(pos
))
54 minetest
.sound_play( {name
="returnmirror_set", gain
=1}, {pos
=pos
, max_hear_distance
=12})
57 minetest
.sound_play( {name
="returnmirror_fail", gain
=1}, {pos
=pos
, max_hear_distance
=18})
61 returnmirror
.set_position_active
= function(itemstack
, user
, pointed_thing
)
62 -- Use pointed node's on_rightclick function first, if present
63 if pointed_thing
.type == "node" then
64 local node
= minetest
.get_node(pointed_thing
.under
)
65 if user
and not user
:get_player_control().sneak
then
66 if minetest
.registered_nodes
[node
.name
] and minetest
.registered_nodes
[node
.name
].on_rightclick
then
67 return minetest
.registered_nodes
[node
.name
].on_rightclick(pointed_thing
.under
, node
, user
, itemstack
) or itemstack
72 if returnmirror
.mana_check(user
, returnmirror
.cost_set
) then
73 local pos
= user
:getpos()
74 itemstack
:set_metadata(minetest
.pos_to_string(pos
))
75 minetest
.sound_play( {name
="returnmirror_set", gain
=1}, {pos
=pos
, max_hear_distance
=12})
78 minetest
.sound_play( {name
="returnmirror_fail", gain
=1}, {pos
=pos
, max_hear_distance
=18})
82 local longdesc
, usagehelp
83 if minetest
.get_modpath("doc_items") then
84 usagehelp
= S("Rightclick to set the mirror's teleport location. Leftclick to immediately teleport back to the mirror's teleport location.")
85 if minetest
.get_modpath("mana") ~= nil then
86 longdesc
= S("This item allows to teleport the user back to a previously set location, at the cost of mana.")
87 usagehelp
= usagehelp
.. " " .. S("Setting the teleport location costs @1 mana, teleporting costs @2 mana.", returnmirror
.cost_set
, returnmirror
.cost_teleport
)
89 longdesc
= S("This item allows to teleport its user back to a previously set location.")
93 minetest
.register_tool("returnmirror:mirror_inactive", {
94 description
= S("Mirror of Returning"),
95 _doc_items_longdesc
= longdesc
,
96 _doc_items_usagehelp
= usagehelp
,
97 inventory_image
= "returnmirror_mirror_inactive.png",
98 wield_image
= "returnmirror_mirror_inactive.png",
99 tool_capabilities
= {},
101 on_use
= function(itemstack
, user
, pointed_thing
)
102 minetest
.sound_play( {name
="returnmirror_fail", gain
=1}, {pos
=user
:getpos(), max_hear_distance
=18})
104 on_place
= returnmirror
.set_position_inactive
,
105 on_secondary_use
= returnmirror
.set_position_inactive
,
108 minetest
.register_tool("returnmirror:mirror_active", {
109 description
= S("Mirror of Returning"),
110 _doc_items_create_entry
= false,
112 inventory_image
= "returnmirror_mirror_active.png",
113 wield_image
= "returnmirror_mirror_active.png",
114 tool_capabilities
= {},
116 on_use
= function(itemstack
, user
, pointed_thing
)
117 local dest_string
= itemstack
:get_metadata()
118 local dest
= minetest
.string_to_pos(dest_string
)
119 local src
= user
:getpos()
122 if returnmirror
.mana_check(user
, returnmirror
.cost_teleport
) then
124 minetest
.sound_play( {name
="returnmirror_teleport", gain
=1}, {pos
=src
, max_hear_distance
=30})
125 minetest
.add_particlespawner({
128 minpos
= {x
=src
.x
-0.4, y
=src
.y
+0.25, z
=src
.z
-0.4},
129 maxpos
= {x
=src
.x
+0.4, y
=src
.y
+0.75, z
=src
.z
+0.4},
130 minvel
= {x
=-0.2, y
=-0.2, z
=-0.2},
131 maxvel
= {x
=0.2, y
=0.2, z
=0.2},
136 texture
= "returnmirror_particle_departure.png",
139 minetest
.sound_play( {name
="returnmirror_teleport", gain
=1}, {pos
=dest
, max_hear_distance
=30})
140 minetest
.add_particlespawner({
143 minpos
= {x
=dest
.x
-0.4, y
=dest
.y
+0.25, z
=dest
.z
-0.4},
144 maxpos
= {x
=dest
.x
+0.4, y
=dest
.y
+0.75, z
=dest
.z
+0.4},
145 minvel
= {x
=-0.4, y
=-0.3, z
=-0.4},
146 maxvel
= {x
=0.4, y
=0.3, z
=0.4},
151 texture
= "returnmirror_particle_arrival.png",
156 minetest
.sound_play( {name
="returnmirror_fail", gain
=1}, {pos
=src
, max_hear_distance
=18})
159 on_place
= returnmirror
.set_position_active
,
160 on_secondary_use
= returnmirror
.set_position_active
,
161 groups
= { not_in_creative_inventory
= 1 },
164 minetest
.register_alias("returnmirror:returnmirror", "returnmirror:mirror_inactive")
166 if minetest
.get_modpath("doc") ~= nil then
167 doc
.add_entry_alias("tools", "returnmirror:mirror_inactive", "tools", "returnmirror:mirror_active")