2 if (minetest
.get_modpath("intllib")) then
5 S
= function ( s
) return s
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 if returnmirror
.mana_check(user
, returnmirror
.cost_set
) then
41 local pos
= user
:getpos()
42 local newitem
= ItemStack("returnmirror:mirror_active")
43 newitem
:set_metadata(minetest
.pos_to_string(pos
))
44 minetest
.sound_play( {name
="returnmirror_set", gain
=1}, {pos
=pos
, max_hear_distance
=12})
47 minetest
.sound_play( {name
="returnmirror_fail", gain
=1}, {pos
=pos
, max_hear_distance
=18})
51 returnmirror
.set_position_active
= function(itemstack
, user
, pointed_thing
)
52 if returnmirror
.mana_check(user
, returnmirror
.cost_set
) then
53 local pos
= user
:getpos()
54 itemstack
:set_metadata(minetest
.pos_to_string(pos
))
55 minetest
.sound_play( {name
="returnmirror_set", gain
=1}, {pos
=pos
, max_hear_distance
=12})
58 minetest
.sound_play( {name
="returnmirror_fail", gain
=1}, {pos
=pos
, max_hear_distance
=18})
62 local longdesc
, usagehelp
63 if minetest
.get_modpath("doc_items") then
64 usagehelp
= S("Rightclick to set the mirror's teleport location. Leftclick to immediately teleport back to the mirror's teleport location.")
65 if minetest
.get_modpath("mana") ~= nil then
66 longdesc
= S("This item allows to teleport the user back to a previously set location, at the cost of mana.")
67 usagehelp
= usagehelp
.. " " .. string.format(S("Setting the teleport location costs %d mana, teleporting costs %d mana."), returnmirror
.cost_set
, returnmirror
.cost_teleport
)
69 longdesc
= S("This item allows to teleport its user back to a previously set location.")
73 minetest
.register_tool("returnmirror:mirror_inactive", {
74 description
= S("Mirror of Returning"),
75 x_doc_items_longdesc
= longdesc
,
76 x_doc_items_usagehelp
= usagehelp
,
77 inventory_image
= "returnmirror_mirror_inactive.png",
78 wield_image
= "returnmirror_mirror_inactive.png",
79 tool_capabilities
= {},
81 on_use
= function(itemstack
, user
, pointed_thing
)
82 minetest
.sound_play( {name
="returnmirror_fail", gain
=1}, {pos
=user
:getpos(), max_hear_distance
=18})
84 on_place
= returnmirror
.set_position_inactive
,
85 on_secondary_use
= returnmirror
.set_position_inactive
,
88 minetest
.register_tool("returnmirror:mirror_active", {
89 description
= S("Mirror of Returning"),
90 x_doc_items_create_entry
= false,
92 inventory_image
= "returnmirror_mirror_active.png",
93 wield_image
= "returnmirror_mirror_active.png",
94 tool_capabilities
= {},
96 on_use
= function(itemstack
, user
, pointed_thing
)
97 local dest_string
= itemstack
:get_metadata()
98 local dest
= minetest
.string_to_pos(dest_string
)
101 if returnmirror
.mana_check(user
, returnmirror
.cost_teleport
) then
103 local src
= user
:getpos()
104 minetest
.sound_play( {name
="returnmirror_teleport", gain
=1}, {pos
=src
, max_hear_distance
=30})
105 minetest
.add_particlespawner({
108 minpos
= {x
=src
.x
-0.4, y
=src
.y
+0.25, z
=src
.z
-0.4},
109 maxpos
= {x
=src
.x
+0.4, y
=src
.y
+0.75, z
=src
.z
+0.4},
110 minvel
= {x
=-0.2, y
=-0.2, z
=-0.2},
111 maxvel
= {x
=0.2, y
=0.2, z
=0.2},
116 texture
= "returnmirror_particle_departure.png",
119 minetest
.sound_play( {name
="returnmirror_teleport", gain
=1}, {pos
=dest
, max_hear_distance
=30})
120 minetest
.add_particlespawner({
123 minpos
= {x
=dest
.x
-0.4, y
=dest
.y
+0.25, z
=dest
.z
-0.4},
124 maxpos
= {x
=dest
.x
+0.4, y
=dest
.y
+0.75, z
=dest
.z
+0.4},
125 minvel
= {x
=-0.4, y
=-0.3, z
=-0.4},
126 maxvel
= {x
=0.4, y
=0.3, z
=0.4},
131 texture
= "returnmirror_particle_arrival.png",
136 minetest
.sound_play( {name
="returnmirror_fail", gain
=1}, {pos
=pos
, max_hear_distance
=18})
139 on_place
= returnmirror
.set_position_active
,
140 on_secondary_use
= returnmirror
.set_position_active
,
141 groups
= { not_in_creative_inventory
= 1 },
144 minetest
.register_alias("returnmirror:mirror_inactive", "returnmirror:returnmirror")
146 if minetest
.get_modpath("doc") ~= nil then
147 doc
.add_entry_alias("tools", "returnmirror:mirror_inactive", "returnmirror:mirror_active")