Jump to content

[1.17] How can I apply the HighlightBlock event logic on any given BlockPos


Recommended Posts

Posted

I want to be able to draw the typical block outline that you get when you mouse over a block in first person on any block given I already have its BlockPos.

I've found the specifics of how to draw an outline here (I know this is 1.16, I can deal with the class remappings later, assuming the logic has not significantly changed in 1.17):

https://github.com/TheGreyGhost/MinecraftByExample/blob/master/src/main/java/minecraftbyexample/usefultools/debugging/DebugBlockVoxelShapeHighlighter.java

However, this code does the drawing logic inside the DrawHighlightEvent.HighlightBlock event, and so is a bit redundant since this event is usually fired when a block looked at is being highlighted anyway (I want to outline blocks in events that don't involve the player looking at things). While I get that the point of the code is to demonstrate the inner workings of the event, it does automatically get access to important data that other events wouldn't, namely renderTypeBuffers and matrixStack (which I'm guessing are specific to the block to be outlined).

If I wanted to run this code inside, for example, GuiScreenEvent.DrawScreenEvent, how could I get access to or recreate these two variables for the BlockPos that I have?

Posted

I've managed to convert the example over to 1.17.1 and get the two variables I needed, but now the issue is that as soon as the vertex building code is executed (vertexConsumer.vertex()) my game immediately crashes and throws an exception: java.lang.IllegalStateException: Not filled all elements of the vertex

Crash logs: https://pastebin.com/Bibb7MBM

My 1.17.1 code: https://pastebin.com/qZLdpTA5

Note that I did still just run this in the HighlightBlock event for the time being just to rule out that the crash didn't happen because I ran it in an unusual event.

I tested this code in 1.16.5 and it ran fine, even when forcing the blockpos to a constant with testBlockPos.

  • 2 months later...
Posted (edited)
On 12/27/2021 at 10:31 PM, SoLegendary said:

I want to be able to draw the typical block outline that you get when you mouse over a block in first person on any block given I already have its BlockPos.

I've found the specifics of how to draw an outline here (I know this is 1.16, I can deal with the class remappings later, assuming the logic has not significantly changed in 1.17):

https://github.com/TheGreyGhost/MinecraftByExample/blob/master/src/main/java/minecraftbyexample/usefultools/debugging/DebugBlockVoxelShapeHighlighter.java

However, this code does the drawing logic inside the DrawHighlightEvent.HighlightBlock event, and so is a bit redundant since this event is usually fired when a block looked at is being highlighted anyway (I want to outline blocks in events that don't involve the player looking at things). While I get that the point of the code is to demonstrate the inner workings of the event, it does automatically get access to important data that other events wouldn't, namely renderTypeBuffers and matrixStack (which I'm guessing are specific to the block to be outlined).

If I wanted to run this code inside, for example, GuiScreenEvent.DrawScreenEvent, how could I get access to or recreate these two variables for the BlockPos that I have?

Hey, I found the solution. Instead of using the VertexConsumer to make the wireframe, use LevelRenerer#renderVoxelShape instead. Here's an example in myย code.

Edited by NindyBun

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.