@@ -8,34 +8,30 @@ if allium.environment() ~= "client" then return end
88local events = require (" bouquet" ).events
99local Component = require (" net.minecraft.network.chat.Component" )
1010local BuiltInRegistries = require (" net.minecraft.core.registries.BuiltInRegistries" )
11+ local Type = require (" net.minecraft.world.phys.HitResult.Type" )
1112
12- local renderComponent -- The text to be shared between the render event and tick event
13-
14- events .client .guiRenderTail :register (script , function (client , context , deltaTracker , gui )
15- if renderComponent then -- If there's text, then draw it at the top center
16- context :centeredText (gui :getFont (), renderComponent , context :guiWidth ()/ 2 , 5 , 0xffffffff )
17- -- The position 5 was arbitrarily chosen, and was the first value I picked just to test. It worked perfectly.
18- -- Exercise for the reader - Create a background frame behind the text, so it can be viewed on white backgrounds.
19- -- Note that while text rendering uses RGB, background rendering uses ARGB.
20- end
21- end )
22-
23- events .common .playerTick :register (script , function (player )
24- local level = player :level ()
25- if level :isClientSide () then
13+ events .client .guiRenderTail :register (script , function (gui , minecraft , graphics , deltaTracker , shouldRenderLevel , resourcesLoaded )
14+ if minecraft .hitResult and minecraft .hitResult :getType () == Type .BLOCK then
2615 -- Finally, use the block to get the identifier of the block
2716 local identifier = BuiltInRegistries .BLOCK :getKey (
28- -- Use the position to get the state, then the block attributed to that state
29- level :getBlockState (
17+ -- Use the position to get the state, then the block attributed to that state
18+ minecraft . level :getBlockState (
3019 -- Get the block position the player is looking at <- START HERE read UP ^
31- player : pick ( 5 , 0 , false ) :getBlockPos ()
32- ):getBlock ()
20+ minecraft . hitResult :getBlockPos ()
21+ ):getBlock ()
3322 )
3423 local namespace , path = identifier :getNamespace (), identifier :getPath ()
35- if namespace == " minecraft" and path == " air" then -- If we're just looking at air, don't create a text object.
36- renderComponent = nil
37- else -- Otherwise, pull the name of the block from the language.
38- renderComponent = Component .translatable (" block." .. namespace .. " ." .. path )
24+ if not (namespace == " minecraft" and path == " air" ) then -- If we're just looking at air, don't write text.
25+ graphics :centeredText (
26+ minecraft .font ,
27+ Component .translatable (" block." .. namespace .. " ." .. path ),
28+ graphics :guiWidth ()/ 2 ,
29+ 5 ,
30+ 0xffffffff
31+ )
32+ -- The position 5 was arbitrarily chosen, and was the first value I picked just to test. It worked perfectly.
33+ -- Exercise for the reader - Create a background frame behind the text, so it can be viewed on white backgrounds.
34+ -- Note that while text rendering uses RGB, background rendering uses ARGB.
3935 end
4036 end
4137end )
0 commit comments