Jump to content

Recommended Posts

Posted (edited)

I'm trying to render a block's bounding box as a solid color cube that can be seen through other blocks. I've searched for a few hours for a method that is both up to date and working but have had no luck so far. I haven't worked with 3D rendering before, so I am trying to use this as a basis to get started, so please forgive me if I ask too many questions. If you are unsure what it is I am trying to accomplish, try googling "chest finder" and looking at the images. (P.S. No, I am not making another hacked client) I don't wish to be spoonfed code, but I need help getting pushed in the right direction. Cheers!

Edited by Crypnotic
Posted

You can render the outline in any of forge's rendering events. I would recommend RenderWorldLastEvent.

To make it render on top of everything just disable depth in the GlStateManager. Don't forget to re-enale it once you are done.

The TileEntityStructureRenderer can assist you with rendering the box itself - see how it is done there, in vanilla.

Once you piece it all together you can store the positions of the blocks you want to outline in any array and in the event iterate through that array, offset the gl matrix accordingly(again, look at how vanilla handles it, generic entity rendering is the example you need) and render your box. 

Posted
52 minutes ago, V0idWa1k3r said:

You can render the outline in any of forge's rendering events. I would recommend RenderWorldLastEvent.

To make it render on top of everything just disable depth in the GlStateManager. Don't forget to re-enale it once you are done.

The TileEntityStructureRenderer can assist you with rendering the box itself - see how it is done there, in vanilla.

Once you piece it all together you can store the positions of the blocks you want to outline in any array and in the event iterate through that array, offset the gl matrix accordingly(again, look at how vanilla handles it, generic entity rendering is the example you need) and render your box. 

2

I did, afaik, everything you explained. It's rendering lines now, but they're rather... weird. It should be outlining the Andesite block, but it definitely is not.

2017-04-30_11.21.05.png

Posted (edited)

You need to offset the vertexbuffer/gl matrix(whichever you are using) before rendering the lines at the desired position.

Think of it this way:

Every time MC renders the world it offsets everything based on the player's position.

The RenderWorldLast event is fired when those offsets are applied.

If you want your outline to be stationary and not follow the player you need to 'negate' them by offsetting your rendering back to where it was(0,0,0) and then render at the desired position(x,y,z).

So your rendering would then look like

calculate offsets

offset(-offsets)

render boxes loop

offset(offsets).

 

As I usually do, here is a simple example:

 

// your positions. You might want to shift them a bit too
int sX = yourX;
int sY = yourY;
int sZ = yourZ;
// Usually the player
Entity entity = Minecraft.getMinecraft().getRenderViewEntity();
//Interpolating everything back to 0,0,0. These are transforms you can find at RenderEntity class
double d0 = entity.lastTickPosX + (entity.posX - entity.lastTickPosX) * (double)evt.getPartialTicks();
double d1 = entity.lastTickPosY + (entity.posY - entity.lastTickPosY) * (double)evt.getPartialTicks();
double d2 = entity.lastTickPosZ + (entity.posZ - entity.lastTickPosZ) * (double)evt.getPartialTicks();
//Apply 0-our transforms to set everything back to 0,0,0
Tessellator.getInstance().getBuffer().setTranslation(-d0, -d1, -d2);
//Your render function which renders boxes at a desired position. In this example I just copy-pasted the one on TileEntityStructureRenderer
renderBox(Tessellator.getInstance(), Tessellator.getInstance().getBuffer(), sX, sY, sZ, sX + 1, sY + 1, sZ + 1);
//When you are done rendering all your boxes reset the offsets. We do not want everything that renders next to still be at 0,0,0 :)
Tessellator.getInstance().getBuffer().setTranslation(0, 0, 0);

 

note that if you want to outline more than 1 box like this you would need to apply player offsets first, then render your boxes in a loop, then reset the offsets.

 

This is a result I get with my example:

 

2017-04-30_19.40.52.png

Edited by V0idWa1k3r
  • Like 1
  • 3 years later...
Posted

@V0idWa1k3r Hi. I know it's been a good few years since this thread was active but I can't seem to get this code to work. In the renderBox function I found, it takes 3 extra int arguments. I looked at the code and those seem to be color arguments(r, g, b). However, the color only shows up when I'm looking in the positive x, positive z direction. Otherwise, the outline is just black. Do you have any idea why this is happening?

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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