From 47120ba3e1da0214a41b7ed15f265eee6fced31f Mon Sep 17 00:00:00 2001 From: Giov4 Date: Tue, 22 Sep 2020 14:56:25 +0200 Subject: [PATCH] + Modified enderpearl texture + Added on_teleport callback + Added block_teleport function --- init.lua | 52 +++++++++++++++++++++++++++++---- textures/enderpearl-export.png | Bin 0 -> 768 bytes textures/enderpearl.png | Bin 209 -> 301 bytes 3 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 textures/enderpearl-export.png diff --git a/init.lua b/init.lua index fef2379..bbfb32a 100644 --- a/init.lua +++ b/init.lua @@ -1,10 +1,12 @@ +enderpearl = {} local t = minetest.get_translator("enderpearl") +local callbacks = {} + ---------------------- -- ! Item Section ! -- ---------------------- - minetest.register_craftitem("enderpearl:ender_pearl", { description = "Enderpeal\n"..t("Left click to throw it@nIt will teleport you on the node it hits making you 2 damage@n(it won't work if you launch it to an unloaded world area)"), inventory_image = "enderpearl.png", @@ -35,7 +37,6 @@ minetest.register_craftitem("enderpearl:ender_pearl", { -- ! Entity Section ! -- ------------------------ - -- entity declaration local thrown_ender_pearl = { initial_properties = { @@ -52,7 +53,7 @@ local thrown_ender_pearl = { speed = 56, gravity = 32, damage = 2, - lifetime = 15 + lifetime = 10 }, player_name = "" } @@ -62,16 +63,26 @@ local thrown_ender_pearl = { function thrown_ender_pearl:on_step(dtime, moveresult) local collided_with_node = moveresult.collisions[1] and moveresult.collisions[1].type == "node" - -- if it's touching the ground or it collides with a node - if moveresult.touching_ground == true or collided_with_node then + -- if it collides with a node + if collided_with_node then local player = minetest.get_player_by_name(self.player_name) if player == nil then self.object:remove() + return + elseif player:get_meta():get_string("ep_can_teleport") == "false" then + self.object:remove() + return end player:set_pos(vector.add(self.object:get_pos(), {x = 0, y = 1, z = 1})) player:set_hp(player:get_hp()-self.initial_properties.damage, "enderpearl") + + for i=1, #callbacks do + local node = minetest.get_node(moveresult.collisions[1].node_pos) + callbacks[i](node) + end + self.object:remove() end end @@ -89,4 +100,33 @@ end -minetest.register_entity("enderpearl:thrown_ender_pearl", thrown_ender_pearl) \ No newline at end of file +minetest.register_entity("enderpearl:thrown_ender_pearl", thrown_ender_pearl) + + + +--------------------------- +-- ! Callbacks Section ! -- +--------------------------- + +-- on_teleport(hit_node) +function enderpearl.on_teleport(func) + table.insert(callbacks, func) +end + + + +----------------------- +-- ! Utils Section ! -- +----------------------- + +function enderpearl.block_teleport(player, duration) + if duration then + minetest.after(duration, function() + if minetest.get_player_by_name(player:get_player_name()) then + player:get_meta():set_string("ep_can_teleport", "") + end + end) + end + + player:get_meta():set_string("ep_can_teleport", "false") +end \ No newline at end of file diff --git a/textures/enderpearl-export.png b/textures/enderpearl-export.png new file mode 100644 index 0000000000000000000000000000000000000000..a1be0ea5b96246a9ed5e5624093d25a2781ad7f3 GIT binary patch literal 768 zcmeAS@N?(olHy`uVBq!ia0vp^2_VeD1|%QND7Ro>U^?#U;uumf=j~j>Y>_|_H}g#r zi&fYZog6saE-m@OpR=;JD1!axp`)VUdF2Ri z(wjB!e0LZeRxI%QS@HYXS?icjh3SWSN)_T_D*a-uo?Kjh{6wk0Lip7G8VqiX23!q+ z3}+&OxkH1`w%)w_@W-!$?+ZHr$`sxGFzsjB7Nhor9$4Pn=k!o{kif(Pgq#_p`TYvQdkebP4}7Av}ucRu~yl( zpTF~Glx+(6{PXa1W%KK7)7Qsqojo5E9Q^VG$Q4jaX5@WkkG%ErY+w85{jqObA3vY; z@%{IEA=^V1&Dys~WcwDI6IC%w|IHGGxCd;@-8IjPzoq;+UQ@mQ>h&_KzYkYj{knO} zHIbV;Q=jJ`yW|%4t$X$wUu!OXDf(P$^XJ{W!0PPQocT9vQ~i(dS+)oDqd4S~@J6k_ zC)a=c@mBpKzgqO2Gm2m8k3HUd?r7NhY$Q_=fdh8T+V4$O_K)Jct|>1%@$IG=a^OAD z%t#X1cl?rk*{sU=7c&C(t$%XIs`{f9vYI9Tul{{->vBO&ZjH8|qo@ATSxUFw32xnc ze&@xKie>utcHGaSA+ZLwck;KUYsa=9`gnBj=g1hjo8(bU^mYv0bj9Uj$f}h|NC9%je&ORK1<7w4CIC}5gQu&X J%Q~loCID9dSj7MU literal 0 HcmV?d00001 diff --git a/textures/enderpearl.png b/textures/enderpearl.png index a092ed86f3609624841c17cadd9368a3319479e6..86676fc24328c3b14217f2afcc528dfc85423d19 100644 GIT binary patch delta 274 zcmV+t0qy?L0j&a%B!BctL_t(IjbmV-5HRAB=yUJ+kIXOHS%Ot93oea?=~`$q5OH*a zP&j?=J^u^SwHVHAx{G0xk)JXH0|Ns?|IBMBhA<*)wwGjQ5So_6z`(%3@Gff}HWxD( z`6;6qg5d=iIQaZ03g2Fm9jiJfWZMru|H-gEa5`QC`)6Kbuz#0ihldr03l8$$XE+#F z#=yXf#gH!y4E79)m@c3MU>IQkSrMB$oN`PI43M}z`1~i%fI=|@8dk7afV~rt=k4?O2X9{x9( z`1~h^At)SV%?F?VMA3{aj%)}cx@MtiNem1O3=Hc7r(<=6y(Bw|AxxxbMm7W%PE6>M zgfydj4aERLny~>47tq{*!1bB94Zs!uxHQ8JDB4-Vh#ok&G%ml(nuijN)JsU%3_%A3 jlQOa)*u=4ACW-+7$xu-i`we!400000NkvXXu0mjf&Mr%v