Hello,
this is my first post, so please be considerate of errors
The whole code is on my github too: https://github.com/Silverminer007/Shrines/blob/experimental/src/main/java/com/silverminer/shrines/events/ClientEvents.java
So, i want to draw boxes to the world which don't depent on any block/tileentity in the world. I've written a method that should draw the lines. I'm calling it from RenderWorldLastEvent event. Here is my code:
public static void renderBounds(MatrixStack ms) {
// Enable depth test first
RenderSystem.depthMask(false);
// Get Minecraft and store it locally for multiple use
Minecraft mc = Minecraft.getInstance();
// Get dimension to draw only bounds of the correct dimension
RegistryKey<World> dim;
if (mc.level != null) {
dim = mc.level.dimension();
} else {
dim = null;
}
// This doesn't work in both ways. What's the correct / working way to do that?
RenderSystem.lineWidth(30.0f);
// Translate coordinates from players system to world system
Vector3d vec = mc.gameRenderer.getMainCamera().getPosition();
double renderPosX = vec.x();
double renderPosY = vec.y();
double renderPosZ = vec.z();
ms.pushPose();
ms.translate(-renderPosX, -renderPosY, -renderPosZ);
// Get vertex builder
IRenderTypeBuffer irendertypebuffer1 = mc.renderBuffers().bufferSource();
IVertexBuilder vb = irendertypebuffer1.getBuffer(RenderType.lines());
// Color of the bound (White)
Color c = new Color(Utils.properties.bound_color);
// Split up in red, green and blue and transform it to 0.0 - 1.0
float red = c.getRed() / 255.0f;
float green = c.getGreen() / 255.0f;
float blue = c.getBlue() / 255.0f;
// Iterate over all bounds to draw
for (CustomStructureData data : Utils.DATAS_FROM_SERVER) {
for (ResourceData rd : data.PIECES_ON_FLY) {
if (rd.getDimension() == dim) {
MutableBoundingBox mbb = rd.getBounds();
// Drawing a line box as in StructureTileEntityRenderer#render
WorldRenderer.renderLineBox(ms, vb, mbb.x0, mbb.y0, mbb.z0, mbb.x1, mbb.y1, mbb.z1, red, green,
blue, 1.0f, red, green, blue);
}
}
}
ms.popPose();
}
The lines were drawn, but are in the wrong color (Dark Green/Black instead of White) until the inventory is opened. After opening they turn white. The lines are also moving while flying, sprinting and bobbing. Looks like i've missed something, but what?
I've tested to call my method from DrawHighlightEvent.HighlightBlock and suprisingly everything worked fine! I've searched in vanilla code and saw, DrawHighlightEvent.HighlightBlock is called in WorldRenderer#renderLevel and RenderWorldLastEvent from GameRenderer#render. GameRenderer calls first WorldRenderer#renderLevel and then DrawHighlightEvent.HighlightBlock is fired, so something seems to change inside #renderLevel. I think it's MatrixStack, because it's the only parameter i use from RenderWorldLastEvent and DrawHighlightEvent.HighlightBlock. It could also be any variable from Minecraft Instance, but i'm not sure how to check that.
In the image, you see two boxes, one from DrawHighlightEvent.HighlightBlock(the inner white) and one from RenderWorldLastEvent(The outer)
Does anyone have an idea how to fix or what to check?
Thanks for all the help in advance