From b526b9557378bc475d1209f0bdc41cd43df647b4 Mon Sep 17 00:00:00 2001 From: ForbiddenJ Date: Wed, 1 Mar 2017 19:02:15 -0600 Subject: [PATCH] Initial upload --- README.md | 11 ++++++++++ depends.txt | 1 + description.txt | 2 ++ init.lua | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+) create mode 100644 README.md create mode 100644 depends.txt create mode 100644 description.txt create mode 100644 init.lua diff --git a/README.md b/README.md new file mode 100644 index 0000000..4990e41 --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +# Meseport + +This mod allows you to teleport by means of Mese and Gold structures. +You punch a gold block that's next to Mese to teleport 100 meters in the +direction that the Mese is located relative to the gold block. Each +additional Mese added in a straight line adds an additional 100 meters. +You can also add Mese to multiple sides in such a way to go in diagonal +directions! However, Mese on opposing sides cancel each other. Thanks to +oscar14 for the Gold-Mese-Transport idea! + +### License: Unlicense diff --git a/depends.txt b/depends.txt new file mode 100644 index 0000000..4ad96d5 --- /dev/null +++ b/depends.txt @@ -0,0 +1 @@ +default diff --git a/description.txt b/description.txt new file mode 100644 index 0000000..5f56033 --- /dev/null +++ b/description.txt @@ -0,0 +1,2 @@ +Meseportation system. +The properties of Mese allows for teleportation systems made of gold and Mese. When a player punches a gold block which is next to Mese, 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. You can also place lines of mese on more than one side of the gold block to create diagonal transports! However, Mese on opposing sides cancel each other. diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..db161ce --- /dev/null +++ b/init.lua @@ -0,0 +1,57 @@ +local on_punch_old = ItemStack("default:goldblock"):get_definition().on_punch -- Added to avoid conflict with other mods +local NodePowers = {["default:mese"] = 100} +local PunchDebounces = {} + +minetest.override_item("default:goldblock", { + 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} + for d,v in pairs(direction) do -- D stands for dimension. + -- Go positive + local LoopFirst, ReadNode + + LoopFirst = true + ReadNode = nil + while (LoopFirst or NodePowers[ReadNode] ~= nil) do + if not LoopFirst then + direction[d] = direction[d] + NodePowers[ReadNode] + else + LoopFirst = false + end + ReadPos[d] = ReadPos[d] + 1 + ReadNode = minetest.get_node(ReadPos)["name"] + end + ReadPos[d] = pos[d] + + -- Go negative + LoopFirst = true + ReadNode = nil + while (LoopFirst or NodePowers[ReadNode] ~= nil) do + if not LoopFirst then + direction[d] = direction[d] - NodePowers[ReadNode] + else + LoopFirst = false + end + ReadPos[d] = ReadPos[d] - 1 + ReadNode = minetest.get_node(ReadPos)["name"] + end + ReadPos[d] = pos[d] + end + + -- Teleport the player + -- Condition added to avoid jumpiness after punching unpowered gold. + if (direction.x ~= 0 or direction.y ~= 0 or direction.z ~= 0) then + local puncherPos = puncher:getpos() + puncher:setpos({x = puncherPos.x + direction.x, y = puncherPos.y + direction.y, z = puncherPos.z + direction.z}) + PunchDebounces[puncher] = true + minetest.after(0.5, function(...) + PunchDebounces[puncher] = nil + end) + end + end + + return on_punch_old(pos, node, puncher, pointed_thing) -- Added to avoid conflict with other mods + end) +})