2020-08-29 17:58:20 -05:00
|
|
|
meseport = {} -- Add a table so other mods are aware of it.
|
|
|
|
|
2020-10-19 19:54:28 -06:00
|
|
|
local PunchDebounces = {}
|
2020-08-29 17:58:20 -05:00
|
|
|
local AxisDirections = {'x', 'y', 'z'}
|
|
|
|
local Polarities = {-1, 1}
|
2019-05-02 03:48:02 -05:00
|
|
|
|
2020-10-19 19:54:28 -06:00
|
|
|
meseport.nodepowers = {}
|
|
|
|
local NodePowers = meseport.nodepowers
|
2017-03-01 19:02:15 -06:00
|
|
|
|
2020-10-20 00:03:17 -06:00
|
|
|
meseport.register_nodepower = function(node_name, power_level)
|
|
|
|
assert(minetest.registered_nodes[node_name] ~= nil)
|
|
|
|
|
|
|
|
if power_level == nil or power_level == false then
|
|
|
|
meseport.nodepowers[node_name] = nil
|
|
|
|
return
|
|
|
|
end
|
|
|
|
assert(type(power_level) == "number")
|
|
|
|
meseport.nodepowers[node_name] = power_level
|
|
|
|
end
|
|
|
|
|
2020-10-19 19:54:28 -06:00
|
|
|
meseport.register_actionblock = function(ActionBlockType)
|
|
|
|
local action_block_def = minetest.registered_nodes[ActionBlockType]
|
|
|
|
assert(action_block_def ~= nil)
|
|
|
|
local on_punch_old = action_block_def.on_punch -- Added to avoid conflicts with other mods.
|
|
|
|
|
|
|
|
minetest.override_item(ActionBlockType, {
|
|
|
|
on_punch = function(pos, node, puncher, pointed_thing)
|
2020-10-20 00:03:17 -06:00
|
|
|
if not PunchDebounces[puncher] and not puncher:get_player_control()["sneak"] then
|
2020-10-19 19:54:28 -06:00
|
|
|
local power = {x = 0, y = 0, z = 0}
|
|
|
|
local readPos = {x = pos.x, y = pos.y, z = pos.z}
|
|
|
|
|
|
|
|
-- Figure out the relative position to teleport.
|
|
|
|
for _, axis in ipairs(AxisDirections) do
|
|
|
|
for _, polarity in ipairs(Polarities) do
|
|
|
|
local readNode = nil
|
|
|
|
repeat
|
|
|
|
readPos[axis] = readPos[axis] + polarity
|
|
|
|
readNode = minetest.get_node(readPos).name
|
|
|
|
power[axis] = power[axis] + (NodePowers[readNode] or 0) * polarity
|
|
|
|
until NodePowers[readNode] == nil
|
|
|
|
readPos[axis] = pos[axis]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Teleport the player
|
|
|
|
if power.x ~= 0 or power.y ~= 0 or power.z ~= 0 then
|
|
|
|
local puncherPos = puncher:get_pos()
|
|
|
|
puncher:set_pos({x = puncherPos.x + power.x, y = puncherPos.y + power.y, z = puncherPos.z + power.z})
|
|
|
|
PunchDebounces[puncher] = true
|
|
|
|
minetest.after(0.5, function(...)
|
|
|
|
PunchDebounces[puncher] = nil
|
|
|
|
end)
|
2017-03-01 19:02:15 -06:00
|
|
|
end
|
|
|
|
end
|
2020-10-19 19:54:28 -06:00
|
|
|
|
|
|
|
return on_punch_old(pos, node, puncher, pointed_thing) -- Added to avoid conflicts with other mods.
|
|
|
|
end,
|
2020-10-20 00:03:17 -06:00
|
|
|
|
|
|
|
_meseport_on_punch_old = on_punch_old,
|
2020-10-19 19:54:28 -06:00
|
|
|
})
|
|
|
|
end
|
2017-03-01 19:02:15 -06:00
|
|
|
|
2020-10-20 00:03:17 -06:00
|
|
|
meseport.unregister_actionblock = function(ActionBlockType)
|
|
|
|
local action_block_def = minetest.registered_nodes[ActionBlockType]
|
|
|
|
assert(action_block_def ~= nil)
|
|
|
|
local on_punch_old = action_block_def._meseport_on_punch_old
|
|
|
|
if on_punch_old == nil then
|
|
|
|
return -- was never registered
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.override_item(ActionBlockType, {
|
|
|
|
on_punch = on_punch_old,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-10-19 19:54:28 -06:00
|
|
|
if minetest.get_modpath("default") then
|
2020-10-20 00:03:17 -06:00
|
|
|
meseport.register_nodepower("default:mese", 100)
|
2020-10-19 19:54:28 -06:00
|
|
|
meseport.register_actionblock("default:goldblock")
|
2020-10-19 23:22:41 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
if minetest.get_modpath("mcl_core")
|
|
|
|
and minetest.get_modpath("mesecons_torch")
|
|
|
|
and minetest.registered_nodes["mesecons_torch:redstoneblock"] then
|
2020-10-20 00:03:17 -06:00
|
|
|
|
|
|
|
meseport.register_nodepower("mesecons_torch:redstoneblock", 100)
|
2020-10-19 23:22:41 -06:00
|
|
|
meseport.register_actionblock("mcl_core:goldblock")
|
2020-10-19 19:54:28 -06:00
|
|
|
end
|