2 returnmirror
.cost_teleport
= 200
3 returnmirror
.cost_set
= 20
5 if tonumber(minetest
.setting_get("returnmirror_cost_teleport")) ~= nil then
6 returnmirror
.cost_teleport
= tonumber(minetest
.setting_get("returnmirror_cost_teleport"))
8 if tonumber(minetest
.setting_get("returnmirror_cost_set")) ~= nil then
9 returnmirror
.cost_set
= tonumber(minetest
.setting_get("returnmirror_cost_set"))
12 if minetest
.get_modpath("mana") ~= nil then
13 returnmirror
.mana
= true
15 returnmirror
.mana
= false
18 returnmirror
.mana_check
= function(player
, cost
)
20 if returnmirror
.mana
then
21 if mana
.subtract(player
:get_player_name(), cost
) then
32 returnmirror
.set_position_inactive
= function(itemstack
, user
, pointed_thing
)
33 if returnmirror
.mana_check(user
, returnmirror
.cost_set
) then
34 local pos
= user
:getpos()
35 local newitem
= ItemStack("returnmirror:mirror_active")
36 newitem
:set_metadata(minetest
.pos_to_string(pos
))
37 minetest
.sound_play( {name
="returnmirror_set", gain
=1}, {pos
=pos
, max_hear_distance
=12})
40 minetest
.sound_play( {name
="returnmirror_fail", gain
=1}, {pos
=pos
, max_hear_distance
=18})
44 returnmirror
.set_position_active
= function(itemstack
, user
, pointed_thing
)
45 if returnmirror
.mana_check(user
, returnmirror
.cost_set
) then
46 local pos
= user
:getpos()
47 itemstack
:set_metadata(minetest
.pos_to_string(pos
))
48 minetest
.sound_play( {name
="returnmirror_set", gain
=1}, {pos
=pos
, max_hear_distance
=12})
51 minetest
.sound_play( {name
="returnmirror_fail", gain
=1}, {pos
=pos
, max_hear_distance
=18})
55 minetest
.register_tool("returnmirror:mirror_inactive", {
56 description
= "Mirror of Returning",
57 inventory_image
= "returnmirror_mirror_inactive.png",
58 wield_image
= "returnmirror_mirror_inactive.png",
59 tool_capabilities
= {},
61 on_use
= function(itemstack
, user
, pointed_thing
)
62 minetest
.sound_play( {name
="returnmirror_fail", gain
=1}, {pos
=user
:getpos(), max_hear_distance
=18})
64 on_place
= returnmirror
.set_position_inactive
,
65 on_secondary_use
= returnmirror
.set_position_inactive
,
68 minetest
.register_tool("returnmirror:mirror_active", {
69 description
= "Mirror of Returning",
71 inventory_image
= "returnmirror_mirror_active.png",
72 wield_image
= "returnmirror_mirror_active.png",
73 tool_capabilities
= {},
75 on_use
= function(itemstack
, user
, pointed_thing
)
76 local dest_string
= itemstack
:get_metadata()
77 local dest
= minetest
.string_to_pos(dest_string
)
80 if returnmirror
.mana_check(user
, returnmirror
.cost_teleport
) then
82 local src
= user
:getpos()
83 minetest
.sound_play( {name
="returnmirror_teleport", gain
=1}, {pos
=src
, max_hear_distance
=30})
84 minetest
.add_particlespawner({
87 minpos
= {x
=src
.x
-0.4, y
=src
.y
+0.25, z
=src
.z
-0.4},
88 maxpos
= {x
=src
.x
+0.4, y
=src
.y
+0.75, z
=src
.z
+0.4},
89 minvel
= {x
=-0.2, y
=-0.2, z
=-0.2},
90 maxvel
= {x
=0.2, y
=0.2, z
=0.2},
95 texture
= "returnmirror_particle_departure.png",
98 minetest
.sound_play( {name
="returnmirror_teleport", gain
=1}, {pos
=dest
, max_hear_distance
=30})
99 minetest
.add_particlespawner({
102 minpos
= {x
=dest
.x
-0.4, y
=dest
.y
+0.25, z
=dest
.z
-0.4},
103 maxpos
= {x
=dest
.x
+0.4, y
=dest
.y
+0.75, z
=dest
.z
+0.4},
104 minvel
= {x
=-0.4, y
=-0.3, z
=-0.4},
105 maxvel
= {x
=0.4, y
=0.3, z
=0.4},
110 texture
= "returnmirror_particle_arrival.png",
115 minetest
.sound_play( {name
="returnmirror_fail", gain
=1}, {pos
=pos
, max_hear_distance
=18})
118 on_place
= returnmirror
.set_position_active
,
119 on_secondary_use
= returnmirror
.set_position_active
,
120 groups
= { not_in_creative_inventory
= 1 },
123 minetest
.register_alias("returnmirror:mirror_inactive", "returnmirror:returnmirror")
125 if minetest
.get_modpath("doc_items") ~= nil then
126 local longdesc
, usagehelp
127 usagehelp
= "Rightclick to set the mirror's teleport location. Leftclick to immediately teleport back to the mirror's teleport location."
128 if minetest
.get_modpath("mana") ~= nil then
129 longdesc
="This item allows to teleport the user back to a previously set location, at the cost of mana."
130 usagehelp
= usagehelp
.. " " .. string.format("Setting the teleport location costs %d mana, teleporting costs %d mana.", returnmirror
.cost_set
, returnmirror
.cost_teleport
)
132 longdesc
= "This item allows to teleport its user back to a previously set location."
135 doc
.sub
.items
.set_items_longdesc({
136 ["returnmirror:mirror_inactive"] = longdesc
,
138 doc
.sub
.items
.set_items_usagehelp({
139 ["returnmirror:mirror_inactive"] = usagehelp
142 doc
.add_entry_alias("tools", "returnmirror:mirror_inactive", "returnmirror:mirror_active")