Merge pull request #7 from minetest-mods/teleporter
added teleporting on mese punch (configurable)
This commit is contained in:
commit
c5a6e43b86
@ -13,7 +13,7 @@ This minetest mod adds a calibratable compass to the minetest. Original mod [her
|
||||
The new compass points to the origin / Zero point and is already usable.
|
||||
2. Punch the compass to a compatible node (all by default) and enter the target name
|
||||
3. Now this compass leads you allways to this location. You can give it away to allow other users to find this place.
|
||||
|
||||
4. Punch a teleport compatible node (by default mese block) to teleport back to the calibrated place
|
||||
|
||||
## For server owners:
|
||||
The mod support the next settings:
|
||||
@ -23,6 +23,7 @@ The mod support the next settings:
|
||||
ccompass_restrict_target (Disabled by default): If enabled, only specific nodes are allowed for calibration (usable with any type waypoint nodes for example)
|
||||
ccompass_restrict_target_nodes: List of technical node names allowed for compass calibration, separated by ','
|
||||
ccompass_aliasses: If enabled the compas:* items will be aliased to the ccompass:* items for compatibility
|
||||
ccompass_teleport_nodes: List of technical node names that triggers the teleport to destination, separated by ','
|
||||
|
||||
|
||||
## For developers:
|
||||
@ -32,6 +33,7 @@ The mod support the next settings:
|
||||
ccompass.recalibrate = true
|
||||
ccompass.restrict_target = true
|
||||
ccompass.restrict_target_nodes["schnitzeljagd:waypoint"] = true
|
||||
ccompass.teleport_nodes["default:diamondblock"] = true
|
||||
```
|
||||
|
||||
2. The pointed node metadata will be checked for "waypoint_name" attribute. It this attribute is set, the calibration screen take this string as proposal. This can be used for a game specific calibration node. To get it working working just set in node definition something like
|
||||
|
45
init.lua
45
init.lua
@ -19,6 +19,16 @@ if nodes_setting then
|
||||
ccompass.restrict_target_nodes[z] = true
|
||||
end)
|
||||
end
|
||||
-- Teleport targets
|
||||
ccompass.teleport_nodes = {}
|
||||
local teleport_nodes_setting = minetest.settings:get("ccompass_teleport_nodes")
|
||||
if teleport_nodes_setting then
|
||||
teleport_nodes_setting:gsub("[^,]+", function(z)
|
||||
ccompass.teleport_nodes[z] = true
|
||||
end)
|
||||
else
|
||||
ccompass.teleport_nodes["default:mese"] = true
|
||||
end
|
||||
|
||||
if minetest.settings:get_bool("ccompass_aliasses") then
|
||||
minetest.register_alias("compass:0", "ccompass:0")
|
||||
@ -68,6 +78,30 @@ local function get_destination(player, stack)
|
||||
end
|
||||
end
|
||||
|
||||
local function teleport_above(playername, target, counter)
|
||||
local player = minetest.get_player_by_name(playername)
|
||||
if not player then
|
||||
return
|
||||
end
|
||||
|
||||
for i = (counter or 1), 160 do
|
||||
local nodename = minetest.get_node(target).name
|
||||
if nodename == "ignore" then
|
||||
minetest.emerge_area(target, target)
|
||||
minetest.after(0.1, teleport_above, playername, target, i)
|
||||
return
|
||||
end
|
||||
|
||||
if nodename ~= 'air' then
|
||||
target.y = target.y + 1
|
||||
else
|
||||
break
|
||||
end
|
||||
end
|
||||
player:setpos(target)
|
||||
return
|
||||
end
|
||||
|
||||
-- get right image number for players compas
|
||||
local function get_compass_stack(player, stack)
|
||||
local target = get_destination(player, stack)
|
||||
@ -102,6 +136,15 @@ local function on_use_function(itemstack, player, pointed_thing)
|
||||
return
|
||||
end
|
||||
|
||||
local nodepos = minetest.get_pointed_thing_position(pointed_thing)
|
||||
local node = minetest.get_node(nodepos)
|
||||
|
||||
-- Do teleport to target
|
||||
if ccompass.teleport_nodes[node.name] then
|
||||
teleport_above(player:get_player_name(), get_destination(player, itemstack))
|
||||
return
|
||||
end
|
||||
|
||||
-- recalibration allowed?
|
||||
if not ccompass.recalibrate then
|
||||
local destination = itemstack:get_meta():get_string("target_pos")
|
||||
@ -112,9 +155,7 @@ local function on_use_function(itemstack, player, pointed_thing)
|
||||
end
|
||||
|
||||
-- target nodes restricted?
|
||||
local nodepos = minetest.get_pointed_thing_position(pointed_thing)
|
||||
if ccompass.restrict_target then
|
||||
local node = minetest.get_node(nodepos)
|
||||
if not ccompass.restrict_target_nodes[node.name] then
|
||||
minetest.chat_send_player(player:get_player_name(), "Calibration on this node not possible")
|
||||
return
|
||||
|
@ -9,3 +9,6 @@ ccompass_restrict_target_nodes (Nodes list allowed for calibration) string
|
||||
|
||||
# Enable aliasses to replace other compass mods
|
||||
ccompass_aliasses (Enable compatibility aliasses) bool false
|
||||
|
||||
# Nodes able to teleport to destination on punch, separated by ','
|
||||
ccompass_teleport_nodes (Nodes list for teleport on punch) string default:mese
|
||||
|
Loading…
x
Reference in New Issue
Block a user