Heavily simplify code.
This commit is contained in:
parent
2ceaeaddd9
commit
51287bb5ee
@ -1,7 +1,7 @@
|
||||
Allows for the creation of Meseportation systems.
|
||||
Grants teleportation powers to Mese and gold blocks allowing for teleporter constructions.
|
||||
|
||||
Grants special effects to Mese blocks allowing for teleporters made of gold and Mese. When a player punches a gold block which is next to a Mese block, he/she is teleported 100 blocks in the direction of the Mese block relative to the gold block. More Mese placed in a line adds to the transport distance.
|
||||
When you punch a gold block which is next to a Mese block, you are teleported 100 blocks in the direction of the Mese block. Each additional Mese block placed in a line adds 100 blocks to the distance.
|
||||
|
||||
Lines of Mese can be placed on more than one side of a gold block to create diagonal teleporters! However, Mese blocks on opposing sides cancel each other's power.
|
||||
Lines of Mese can also be placed on multiple sides of a gold block to create diagonal teleporters! However, Mese blocks on opposing sides cancel each other's power.
|
||||
|
||||
If used carefully, complex teleportation networks can be set up allowing for teleporting around the land or for traveling up and down vertical mineshafts quickly.
|
||||
If you don't know what you're doing, you'll likely bury yourself or send yourself into the sky! However, with careful planning, complex teleportation networks can be built to make navigating the land a breeze.
|
46
init.lua
46
init.lua
@ -1,40 +1,36 @@
|
||||
meseport = {} -- Add a table so other mods are aware of it.
|
||||
|
||||
local ActionBlockType = "default:goldblock"
|
||||
local NodePowers = {["default:mese"] = 100}
|
||||
local AxisDirections = {'x', 'y', 'z'}
|
||||
local Polarities = {-1, 1}
|
||||
|
||||
local on_punch_old = ItemStack(ActionBlockType):get_definition().on_punch -- Added to avoid conflicts with other mods
|
||||
local on_punch_old = ItemStack(ActionBlockType):get_definition().on_punch -- Added to avoid conflicts with other mods.
|
||||
local PunchDebounces = {}
|
||||
|
||||
minetest.override_item(ActionBlockType, {
|
||||
on_punch = function(pos, node, puncher, pointed_thing)
|
||||
if not PunchDebounces[puncher] then
|
||||
local direction = {x = 0, y = 0, z = 0}
|
||||
local ReadPos = {x = pos.x, y = pos.y, z = pos.z}
|
||||
local function doAction(d, polarity) -- D stands for dimension.
|
||||
local LoopFirst = true
|
||||
local ReadNode = nil
|
||||
while LoopFirst or NodePowers[ReadNode] ~= nil do
|
||||
if LoopFirst then
|
||||
LoopFirst = false
|
||||
else
|
||||
direction[d] = direction[d] + NodePowers[ReadNode]
|
||||
end
|
||||
ReadPos[d] = ReadPos[d] + polarity
|
||||
ReadNode = minetest.get_node(ReadPos).name
|
||||
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
|
||||
ReadPos[d] = pos[d]
|
||||
end
|
||||
|
||||
doAction("x", 1)
|
||||
doAction("x", -1)
|
||||
doAction("y", 1)
|
||||
doAction("y", -1)
|
||||
doAction("z", 1)
|
||||
doAction("z", -1)
|
||||
|
||||
-- Teleport the player
|
||||
if direction.x ~= 0 or direction.y ~= 0 or direction.z ~= 0 then
|
||||
if power.x ~= 0 or power.y ~= 0 or power.z ~= 0 then
|
||||
local puncherPos = puncher:getpos()
|
||||
puncher:setpos({x = puncherPos.x + direction.x, y = puncherPos.y + direction.y, z = puncherPos.z + direction.z})
|
||||
puncher:setpos({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
|
||||
@ -42,6 +38,6 @@ minetest.override_item(ActionBlockType, {
|
||||
end
|
||||
end
|
||||
|
||||
return on_punch_old(pos, node, puncher, pointed_thing) -- Added to avoid conflict with other mods
|
||||
return on_punch_old(pos, node, puncher, pointed_thing) -- Added to avoid conflicts with other mods.
|
||||
end,
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user