Construction Wand

Construction Wand

22M Downloads

The construction wand preview wireframe grid breaks in locations beyond hundred thousand.

starmun-0010 opened this issue · 4 comments

commented

MC 1.16.5
Forge 36.1.2
constructionwand-1.16.5-2.0

To Reproduce

  1. Install construction wands
  2. Create new world
  3. Teleport to coordinate (100000, y, 100000)
  4. Hold any construction wand in hand
  5. Try to place blocks (Creative mode or otherwise)
  6. The preview grid will start to appear glitched

Further Information

  • The farther you go into higher co-ordinates the more severely the grid will break.
  • It happens in both, the positive and negative directions
  • (Speculation) Seems like an integer overflow error maybe?
  • Following is an image in 10 million co-ordinate range
    2021-03-31_21 58 25
commented

Hi AbdulMuqsit,

I have successfully reproduced the issue with CW2.0 in MC1.16.5.
If you are beyond 100k blocks from the origin, the preview starts getting flaky and above 10M blocks it is unusable.

After that I went on testing all Minecraft versions with both the latest (2.0) and the oldest version available.
Here are the results:

MC CW Result
1.16.5 2.0 ❌ Bug present
1.16.2 1.2 ❌ Bug present
1.16.2 2.0 ❌ Bug present
1.16.1 1.1 ❌ Bug present
1.16.1 1.2 ❌ Bug present
1.16.1 2.0 ❌ Bug present
1.15.2 1.0 ✔️ OK
1.15.2 1.1 ❌ Bug present
1.15.2 1.2 ❌ Bug present
1.15.2 2.0 ❌ Bug present
1.14.4 1.2 ✔️ OK
1.14.4 2.0 ✔️ OK

The 1.14 versions use a different rendering system and are not affected.
Seems like the bug sneaked in between V1.0 and V1.1.

Further investigation needed...

commented

Looks like I changed the render function with the CW1.1 update. Not so sure why I did that, but I changed it back to the old one and the bug is gone. Need to do some more verification and testing, but I guess I'll get the update out tomorrow.

commented

Here are the 2 functions in question

1.0 version without the bug:

MatrixStack ms = event.getMatrix();
IRenderTypeBuffer buffer = event.getBuffers();
ms.push();

double partialTicks = event.getPartialTicks();
double d0 = player.lastTickPosX + (player.getPosX() - player.lastTickPosX) * partialTicks;
double d1 = player.lastTickPosY + player.getEyeHeight() + (player.getPosY() - player.lastTickPosY) * partialTicks;
double d2 = player.lastTickPosZ + (player.getPosZ() - player.lastTickPosZ) * partialTicks;

for(BlockPos block : blocks) {
    AxisAlignedBB aabb = new AxisAlignedBB(block).offset(-d0, -d1, -d2);
    IVertexBuilder lineBuilder = buffer.getBuffer(RenderTypes.TRANSLUCENT_LINES);
    WorldRenderer.drawBoundingBox(ms, lineBuilder, aabb, colorR, colorG, colorB, 0.4F);
}
ms.pop();

1.1 - 2.0 version with the bug:

double renderPosX = Minecraft.getInstance().getRenderManager().info.getProjectedView().getX();
double renderPosY = Minecraft.getInstance().getRenderManager().info.getProjectedView().getY();
double renderPosZ = Minecraft.getInstance().getRenderManager().info.getProjectedView().getZ();

ms.push();
ms.translate(-renderPosX, -renderPosY, -renderPosZ);

for(BlockPos block : blocks) {
    AxisAlignedBB aabb = new AxisAlignedBB(block);
    IVertexBuilder lineBuilder = buffer.getBuffer(RenderTypes.TRANSLUCENT_LINES);
    WorldRenderer.drawBoundingBox(ms, lineBuilder, aabb, red, green, blue, 0.4F);
}
ms.pop();
commented

Released CW 2.1 which fixes the issue