diff --git a/README.md b/README.md index 875bb44..b1aae44 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ https://forum.minetest.net/viewtopic.php?f=9&t=9234 Change log: +- 1.4 - Change Pad texture so it's not as contrasting, check for attached player before tp. - 1.3 - Added some formspec checks and switch to enable old teleport pad texture (thanks mazes 80) - 1.2 - New teleport pad texture, code tweaks to work with minetest 5.x - 1.1 - Using 0.4.16+ code changes, can only teleport players now, added MineClone2 crafts and spanish translation diff --git a/alt_textures/teleport_potion_pad.png b/alt_textures/teleport_potion_pad.png new file mode 100644 index 0000000..8ec6906 Binary files /dev/null and b/alt_textures/teleport_potion_pad.png differ diff --git a/init.lua b/init.lua index c91f5f5..8ce38b3 100644 --- a/init.lua +++ b/init.lua @@ -1,20 +1,19 @@ +--[[ + Teleport Potion mod by TenPlus1 ---= Teleport Potion mod by TenPlus1 + Craft teleport potion or pad, use on node to bookmark location, place to open + portal or place pad, portals show a blue flame that you can walk into + before it closes (10 seconds), potions can also be thrown for local teleport. +]]-- --- Craft teleport potion or pad, use on node to bookmark location, place to open --- portal or place pad, portals show a blue flame that you can walk into --- before it closes (10 seconds), potions can also be thrown for local teleport. +-- translation and settings --- translation support local S = minetest.get_translator("teleport_potion") - --- check for MineClone2 local mcl = minetest.get_modpath("mcl_core") - --- max teleport distance local dist = tonumber(minetest.settings:get("map_generation_limit") or 31000) -- creative check + local creative_mode_cache = minetest.settings:get_bool("creative_mode") local function is_creative(name) @@ -22,6 +21,7 @@ local function is_creative(name) end -- choose texture for teleport pad + local teleport_pad_texture = "teleport_potion_pad.png" if minetest.settings:get_bool("teleport_potion_use_old_texture") == true then @@ -29,11 +29,10 @@ if minetest.settings:get_bool("teleport_potion_use_old_texture") == true then end -- make sure coordinates are valid -local check_coordinates = function(str) - if not str or str == "" then - return nil - end +local function check_coordinates(str) + + if not str or str == "" then return nil end -- get coords from string local x, y, z = string.match(str, "^(-?%d+),(-?%d+),(-?%d+)$") @@ -46,14 +45,10 @@ local check_coordinates = function(str) end -- convert string coords to numbers - x = tonumber(x) - y = tonumber(y) - z = tonumber(z) + x = tonumber(x) ; y = tonumber(y) ; z = tonumber(z) -- are coords in map range ? - if x > dist or x < -dist - or y > dist or y < -dist - or z > dist or z < -dist then + if x > dist or x < -dist or y > dist or y < -dist or z > dist or z < -dist then return nil end @@ -62,7 +57,8 @@ local check_coordinates = function(str) end -- particle effect -local effect = function(pos, amount, texture, min_size, max_size, radius, gravity, glow) + +local function effect(pos, amount, texture, min_size, max_size, radius, gravity, glow) radius = radius or 2 gravity = gravity or -10 @@ -85,6 +81,7 @@ local effect = function(pos, amount, texture, min_size, max_size, radius, gravit }) end +-- position bookmark function local teleport_destinations = {} @@ -99,16 +96,14 @@ local function set_teleport_destination(playername, dest) end --- Teleport portal + minetest.register_node("teleport_potion:portal", { drawtype = "plantlike", tiles = { { name = "teleport_potion_portal.png", animation = { - type = "vertical_frames", - aspect_w = 16, - aspect_h = 16, - length = 1.0 + type = "vertical_frames", aspect_w = 16, aspect_h = 16, length = 1.0 } } }, @@ -134,6 +129,8 @@ minetest.register_node("teleport_potion:portal", { minetest.sound_play("portal_close", { pos = pos, gain = 1.0, max_hear_distance = 10}, true) + effect(pos, 25, "teleport_potion_particle.png", 2, 2, 1, -10, 15) + minetest.remove_node(pos) end, @@ -141,6 +138,7 @@ minetest.register_node("teleport_potion:portal", { }) -- Throwable potion + local function throw_potion(itemstack, player) local playerpos = player:get_pos() @@ -161,6 +159,7 @@ local function throw_potion(itemstack, player) end -- potion entity + local potion_entity = { initial_properties = { @@ -229,6 +228,7 @@ end minetest.register_entity("teleport_potion:potion_entity", potion_entity) --- Teleport potion + minetest.register_node("teleport_potion:potion", { tiles = {"teleport_potion_potion.png"}, drawtype = "signlike", @@ -288,6 +288,7 @@ minetest.register_node("teleport_potion:potion", { }) -- teleport potion recipe + if mcl then minetest.register_craft({ @@ -310,6 +311,7 @@ else end --- Teleport pad + local teleport_formspec_context = {} minetest.register_node("teleport_potion:pad", { @@ -326,12 +328,10 @@ minetest.register_node("teleport_potion:pad", { light_source = 5, groups = {snappy = 3}, node_box = { - type = "fixed", - fixed = {-0.5, -0.5, -0.5, 0.5, -6/16, 0.5} + type = "fixed", fixed = {-0.5, -0.5, -0.5, 0.5, -6/16, 0.5} }, selection_box = { - type = "fixed", - fixed = {-0.5, -0.5, -0.5, 0.5, -6/16, 0.5} + type = "fixed", fixed = {-0.5, -0.5, -0.5, 0.5, -6/16, 0.5} }, -- Save pointed nodes coordinates as destination for further portals @@ -349,9 +349,7 @@ minetest.register_node("teleport_potion:pad", { local name = placer:get_player_name() local dest = teleport_destinations[name] - if not dest then - dest = pos - end + if not dest then dest = pos end -- Set coords meta:set_int("x", dest.x) @@ -379,7 +377,8 @@ minetest.register_node("teleport_potion:pad", { end local meta = minetest.get_meta(pos) - local coords = meta:get_int("x") .. "," .. meta:get_int("y") .. "," .. meta:get_int("z") + local coords = meta:get_int("x") .. "," + .. meta:get_int("y") .. "," .. meta:get_int("z") local desc = meta:get_string("desc") local formspec = "field[desc;" .. S("Description") .. ";" .. minetest.formspec_escape(desc) .. "]" @@ -390,22 +389,17 @@ minetest.register_node("teleport_potion:pad", { "field[coords;" .. S("Teleport coordinates") .. ";" .. coords .. "]" end - teleport_formspec_context[name] = { - pos = pos, - coords = coords, - desc = desc, - } + teleport_formspec_context[name] = {pos = pos, coords = coords, desc = desc} minetest.show_formspec(name, "teleport_potion:set_destination", formspec) end }) -- Check and set coordinates + minetest.register_on_player_receive_fields(function(player, formname, fields) - if formname ~= "teleport_potion:set_destination" then - return false - end + if formname ~= "teleport_potion:set_destination" then return false end local name = player:get_player_name() local context = teleport_formspec_context[name] @@ -414,9 +408,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) teleport_formspec_context[name] = nil - if fields.control == nil and fields.desc == nil then - return false - end + if fields.control == nil and fields.desc == nil then return false end local meta = minetest.get_meta(context.pos) @@ -452,6 +444,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) end) -- teleport pad recipe + if mcl then minetest.register_craft({ @@ -474,6 +467,7 @@ else end -- check portal & pad, teleport any entities on top + minetest.register_abm({ label = "Potion/Pad teleportation", nodenames = {"teleport_potion:portal", "teleport_potion:pad"}, @@ -486,9 +480,7 @@ minetest.register_abm({ -- check objects inside pad/portal local objs = minetest.get_objects_inside_radius(pos, 1) - if #objs == 0 then - return - end + if #objs == 0 then return end -- get coords from pad/portal local meta = minetest.get_meta(pos) @@ -503,7 +495,8 @@ minetest.register_abm({ for n = 1, #objs do - if objs[n]:is_player() then + -- are we a player who isn't currently attached? + if objs[n]:is_player() and not objs[n]:get_attach() then -- play sound on portal end minetest.sound_play("portal_close", { @@ -528,14 +521,10 @@ minetest.register_abm({ local rot = node.param2 local yaw = 0 - if rot == 0 or rot == 20 then - yaw = 0 -- north - elseif rot == 2 or rot == 22 then - yaw = 3.14 -- south - elseif rot == 1 or rot == 23 then - yaw = 4.71 -- west - elseif rot == 3 or rot == 21 then - yaw = 1.57 -- east + if rot == 0 or rot == 20 then yaw = 0 -- north + elseif rot == 2 or rot == 22 then yaw = 3.14 -- south + elseif rot == 1 or rot == 23 then yaw = 4.71 -- west + elseif rot == 3 or rot == 21 then yaw = 1.57 -- east end objs[n]:set_look_horizontal(yaw) @@ -544,8 +533,8 @@ minetest.register_abm({ end }) - -- lucky blocks + if minetest.get_modpath("lucky_block") then lucky_block:add_blocks({ diff --git a/textures/teleport_potion_pad.png b/textures/teleport_potion_pad.png index 8ec6906..8bbce7a 100644 Binary files a/textures/teleport_potion_pad.png and b/textures/teleport_potion_pad.png differ