From 58b7efa83944f932fa90336e18d8eb3677b38eff Mon Sep 17 00:00:00 2001 From: copygirl Date: Tue, 10 Oct 2023 17:28:01 +0200 Subject: [PATCH] Implement basic HUD functionality --- hud.lua | 55 ++++++++++++++++++ init.lua | 1 + ...extended_rotating_hud_rotate_clockwise.png | Bin 0 -> 4744 bytes ..._rotating_hud_rotate_counter_clockwise.png | Bin 0 -> 4754 bytes 4 files changed, 56 insertions(+) create mode 100644 hud.lua create mode 100644 textures/nc_extended_rotating_hud_rotate_clockwise.png create mode 100644 textures/nc_extended_rotating_hud_rotate_counter_clockwise.png diff --git a/hud.lua b/hud.lua new file mode 100644 index 0000000..8acb454 --- /dev/null +++ b/hud.lua @@ -0,0 +1,55 @@ +local ipairs + = ipairs + +local minetest, vector + = minetest, vector + +local player_huds = {} + +local function do_player_rotating_checks(player) + local name = player:get_player_name() + + local hud_index = player_huds[name] + if hud_index then + player:hud_remove(hud_index) + player_huds[name] = nil + end + + local look_dir = player:get_look_dir() + local player_pos = vector.copy(player:get_pos()) + local eye_offset = vector.divide(player:get_eye_offset(), 10) + local eye_height = player:get_properties().eye_height; + local eye_pos = player_pos + eye_offset + vector.new(0, eye_height, 0) + + local default_reach = minetest.registered_items[""].range or 4 + local wielded_reach = player:get_wielded_item():get_definition().reach + local reach = wielded_reach or default_reach + + local node = nil + local ray = minetest.raycast(eye_pos, eye_pos + look_dir * reach, false, false) + for pointed_thing in ray do node = pointed_thing end + + if node then + hud_index = player:hud_add({ + hud_elem_type = "image", + name = "rotation hint", + text = "nc_extended_rotating_hud_rotate_clockwise.png", + position = { x = 0.5, y = 0.5 }, + offset = { x = 0, y = 0 }, + alignment = { x = 0, y = 0 }, + scale = { x = 1, y = 1 }, + }) + player_huds[name] = hud_index + end +end + +minetest.register_globalstep(function(delta_time) + for _, player in ipairs(minetest.get_connected_players()) do + do_player_rotating_checks(player) + end +end) + +minetest.register_on_leaveplayer(function(player) + local name = player:get_player_name() + player_huds[name] = nil +end) diff --git a/init.lua b/init.lua index 9064164..99e69b4 100755 --- a/init.lua +++ b/init.lua @@ -2,6 +2,7 @@ local minetest, vector, include = minetest, vector, include local rotate = include("rotate") +local hud = include("hud") minetest.register_on_punchnode(function(pos, node, puncher, pointed_thing) local def = minetest.registered_nodes[node.name] diff --git a/textures/nc_extended_rotating_hud_rotate_clockwise.png b/textures/nc_extended_rotating_hud_rotate_clockwise.png new file mode 100644 index 0000000000000000000000000000000000000000..5c7c50f16a25279ec7aa933a5b6042810f7104dd GIT binary patch literal 4744 zcmeHKdsI_L8czU$qF{?uStxEAS`6wXH*anv0tS$jMtP(VSbW^vN4S#5CApA5t-3Z! zi%LaVABd>fwFqkEVAWlGK z2Zbu_pX*a#voBxwI~iCk^I$z&qfO=V9Qma!nYBi6xSxL%7a5&EDt!o?KIG!4`vRRiF*;^a^Ub1&bxwn^3!z_W| zbA3y1Wklq}^}*{ZuZBK|cnF7iwPev*^u6Y@EiKc(qaVZu^!)tv*zY%Nby3Jt4wd=x zzOJy`fPMcsq3C>=`Bzft+jjJa;wjRaGg;Gj3d62ljJe;F{oYk^<=49GO_N^MKQb6| zZmfK3PuIQ2;s1K~Qu(>*fwAv9YNcXR(PQamS8PqUyse<9!1Ayj$}OqBic0XmY;u*A zOEY?cOXuxQiT_OX`VQ%r!;r9!`CiIo-V#NDYh?l?I!`H zJ3)jvDV?6tYu{92R&x}JTMa~%(@e8+a$;hgG>YXD49`FqDT|7K`$#jNN8u`dmP`w4 zX*H2YC70NUjFLGztRx>paDMDezZjP62 zIAyifM)0Ij(kK{8bW%lP{!Bk!j14E1=?O^#6riQz=P?Ye6bc;-OmZF~{fv{sXie@OQg~xKD25TXs;`6~cZ*YBPTB{wRx7Y_% z0D1_WC@mC4!9ufHIMTz;Bo+aZfd&1dhh0}p6T)=DZY{K7L}C$PVZujJ;MkBqU1&48 zw}WFs!bF$>)DC79Ju@YHABH?w35=APc6$M_pFuJdIV{#QYhy>;+ZnkK;6B9r40>?y zZZJS;waNr5R>&?-lc3_W^DA*HM&U}gDMkz^ff}R`EXE~}lps*ZATlT*gTX+Ga3mTQ z;n)Z&jm6HO7K~u20C^MzcrZjFA|-eV8Ve73)!48xZ@b%e`ylq28>8Dz^}g#BrlK)g+s}3Kr^u3U-LC^7Qf~c zJl^Oe&!z9ET%&S5mjcfP9*wS1xt>db=K_yL*Z)l}zv0Iz!UFyUIl#kG@OZ&X;6cm7 zkTN@g^R)DXubM&Y1v)v~&f$!mz!om2syY~S`Y;-8qEC;X-}n&awi{t%fzv8YLcC6Y z{MN?i{EW1qld&JKSz~@UZK`?uj=-tyn%~y3uiGexj@9#>~DMJxk8qetUfN+2#nJxbW5D zOHcZ0CoGBHHUSm;bYeYkpHzM_JL4 z>G~NLzsS#hw3Ji1{;(iV;mA4V?Rk01ok=O`70afVF%_>sbqno3yB2kSQ&!fw-&H1O1{|>9!WCqN z?Xt&}#yc(Fn)Jq#>Zb4fJN}+_D4;c>;SG6Y+Qn3T?I%AR3cMnnv206HOYZ(v5t}@( z?4H}J;@sX-{qNR2_7;xiZr=k}jeXYn+Afd9JHn2f==$C6@~-TrCHG(0dnd3iXWj=V zJ2Ah*FO9ph;fuN3Qn!};_ML9dvbDj78?%-t6?w%egFm~-z}&d@&-pKIC)*j1Wes8F zy&ex1wXbRneeB!8y%gY?msD92q^*j!oS1euZ|vpF^=qcyoweuM`R@99SJUcx)Z#hC zJMQe&id{Yh3v3}-^VTtS^Rw$j7^!~e#=2MbX4mf;bNui}jWap9Z5>c`!&}FXhF1A6 zdBPRGU7r~ka?jFTMM5Rp+-!6O%|1$$8jp7Gw3}qDoo9A_NarD^n|^w_w041?YsJm2$8vH( Pq;fQga}xH=TDbf_p!uW4 literal 0 HcmV?d00001 diff --git a/textures/nc_extended_rotating_hud_rotate_counter_clockwise.png b/textures/nc_extended_rotating_hud_rotate_counter_clockwise.png new file mode 100644 index 0000000000000000000000000000000000000000..4ec901cc552e001693f4fd53c1094933aaf04683 GIT binary patch literal 4754 zcmeHKdsGuw8lM0PqJX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