From f3449329867d599b524bbd908b3dc74dc9355c22 Mon Sep 17 00:00:00 2001 From: tenplus1 Date: Sat, 4 Jan 2025 11:49:52 +0000 Subject: [PATCH] tweak code, texture. add attachment check --- README.md | 1 + alt_textures/teleport_potion_pad.png | Bin 0 -> 266 bytes init.lua | 101 ++++++++++++--------------- textures/teleport_potion_pad.png | Bin 266 -> 240 bytes 4 files changed, 46 insertions(+), 56 deletions(-) create mode 100644 alt_textures/teleport_potion_pad.png 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 0000000000000000000000000000000000000000..8ec690674b1aee7daa81dff7d485e428340af63b GIT binary patch literal 266 zcmV+l0rmcgP)Xw zaVTaW1+XwMFa&3t6RCRb)RQa_*8ZipAq>Z8RR#uzNmtM0X`5h`Vu9=SO*cd~Y|_;; zRpt(G@y#>OL&TYo6}3G-fZ)h6w4FSF=_)2<>#8Ij+MXX^V`IbA15tp`FzMNJ=sD?)j4YqD*3ZNR`UWDjDQ;n>E31<+>VHZYs60$uAx8ZjZRz2uWg2&FUU%!6+ z`UPh|!VOsg6T#$ACFy{kmLLEUm+ 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 8ec690674b1aee7daa81dff7d485e428340af63b..8bbce7ad96cb752f1878ce1f836a7932298f6c52 100644 GIT binary patch delta 223 zcmeBT`oK6rvYwfNfk8u;KNv`{q&xaLGB9lH=l+w(3gj~u2e~^j-aM&O59BB$dj$D1 zFjT2AFf_C27 z5PS8P;jR$7iyG@bm2Vv{TB4komdw>SAfLeaQEK81p?}4Oh6f|pgypBnmCygraBe4K UcVw&iI-vOsp00i_>zopr0B-?I$p8QV delta 249 zcmVEFnW*`NyFfcF#XPXnLdhOJc zED+ZIrMDpr$7ods28Kyj&*W*FV3lHl>-J4IL^f>F)iYJ*4sh|!GtWcBnUEE=JwJfp z$T75?Jb>vcCS>cXBpuqGA7Eo+!_)&&fY31M>KO>5LEf$5;c_mhhDQtywr*$&pc>#_ zgy=z2jjVtPXAsI^7e;pyvONg5;dc^NJ?Kt?$Ih=`zkdDt1!q9Q4Osyb!Q@aS>42V= zAOI4V@bLcf