Program: 156421
Project: 156421
Buggy source:
@SuppressWarnings("String_Node_Str") @Override protected void drawForegroundLayer(){
  camY+=scaleSpeed;
  scaleSpeed*=0.7F;
{
    ChunkPos chunkPos=new ChunkPos((int)positionX >> 4,(int)positionZ >> 4);
    ZonePlannerMapChunk zonePlannerMapChunk=ZonePlannerMapDataClient.instance.getLoadedChunk(new ZonePlannerMapChunkKey(chunkPos,Minecraft.getMinecraft().theWorld.provider.getDimension(),getLevel()));
    BlockPos pos=null;
    if (zonePlannerMapChunk != null) {
      pos=zonePlannerMapChunk.data.keySet().stream().filter(blockPos -> blockPos.getX() == (int)positionX - chunkPos.getXStart() && blockPos.getZ() == (int)positionZ - chunkPos.getZStart()).findAny().orElse(null);
    }
    if (pos != null && pos.getY() + 10 > camY) {
      camY=Math.max(camY,pos.getY() + 10);
    }
  }
  int x=guiLeft;
  int y=guiTop;
  if (lastSelected != null) {
    String text="String_Node_Str" + lastSelected.getX() + "String_Node_Str"+ lastSelected.getY()+ "String_Node_Str"+ lastSelected.getZ();
    fontRendererObj.drawString(text,x + 130,y + 130,0x404040);
  }
  int offsetX=8;
  int offsetY=9;
  int sizeX=213;
  int sizeY=100;
  GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);
  GL11.glPushMatrix();
  GL11.glMatrixMode(GL11.GL_PROJECTION);
  GL11.glPushMatrix();
  GL11.glLoadIdentity();
  ScaledResolution scaledResolution=new ScaledResolution(Minecraft.getMinecraft());
  GL11.glViewport((x + offsetX) * scaledResolution.getScaleFactor(),Minecraft.getMinecraft().displayHeight - (sizeY + y + offsetY) * scaledResolution.getScaleFactor(),sizeX * scaledResolution.getScaleFactor(),sizeY * scaledResolution.getScaleFactor());
  GL11.glScalef(scaledResolution.getScaleFactor(),scaledResolution.getScaleFactor(),1);
  GLU.gluPerspective(70.0F,(float)sizeX / sizeY,1F,1000.0F);
  GL11.glMatrixMode(GL11.GL_MODELVIEW);
  GL11.glLoadIdentity();
  RenderHelper.enableStandardItemLighting();
  GL11.glEnable(GL12.GL_RESCALE_NORMAL);
  GL11.glRotatef(90,1,0,0);
  GL11.glPushMatrix();
  GL11.glTranslatef(-positionX,-camY,-positionZ);
  GL11.glDisable(GL11.GL_BLEND);
  GL11.glDisable(GL11.GL_ALPHA_TEST);
  Minecraft.getMinecraft().getRenderManager().renderEngine.bindTexture(new ResourceLocation("String_Node_Str","String_Node_Str"));
  int chunkBaseX=(int)positionX >> 4;
  int chunkBaseZ=(int)positionZ >> 4;
  int radius=8;
  for (int chunkX=chunkBaseX - radius; chunkX < chunkBaseX + radius; chunkX++) {
    for (int chunkZ=chunkBaseZ - radius; chunkZ < chunkBaseZ + radius; chunkZ++) {
      GL11.glCallList(ZonePlannerMapRenderer.instance.drawChunk(new ZonePlannerMapChunkKey(new ChunkPos(chunkX,chunkZ),container.tile.getWorld().provider.getDimension(),getLevel())));
    }
  }
  BlockPos found=null;
  int foundColor=0;
  if (Mouse.getX() / scaledResolution.getScaleFactor() > x + offsetX && Mouse.getX() / scaledResolution.getScaleFactor() < x + offsetX + sizeX && scaledResolution.getScaledHeight() - Mouse.getY() / scaledResolution.getScaleFactor() > y + offsetY && scaledResolution.getScaledHeight() - Mouse.getY() / scaledResolution.getScaleFactor() < y + offsetY + sizeY) {
    FloatBuffer projectionBuffer=BufferUtils.createFloatBuffer(16);
    FloatBuffer modelViewBuffer=BufferUtils.createFloatBuffer(16);
    IntBuffer viewportBuffer=BufferUtils.createIntBuffer(16);
    GL11.glGetFloat(GL11.GL_PROJECTION_MATRIX,projectionBuffer);
    GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX,modelViewBuffer);
    GL11.glGetInteger(GL11.GL_VIEWPORT,viewportBuffer);
    FloatBuffer positionNearBuffer=BufferUtils.createFloatBuffer(3);
    FloatBuffer positionFarBuffer=BufferUtils.createFloatBuffer(3);
    GLU.gluUnProject(Mouse.getX(),Mouse.getY(),0f,modelViewBuffer,projectionBuffer,viewportBuffer,positionNearBuffer);
    GLU.gluUnProject(Mouse.getX(),Mouse.getY(),1f,modelViewBuffer,projectionBuffer,viewportBuffer,positionFarBuffer);
    Vector3d rayStart=new Vector3d(positionNearBuffer.get(0),positionNearBuffer.get(1),positionNearBuffer.get(2));
    Vector3d rayPosition=new Vector3d(rayStart);
    Vector3d rayDirection=new Vector3d(positionFarBuffer.get(0),positionFarBuffer.get(1),positionFarBuffer.get(2));
    rayDirection.sub(rayStart);
    rayDirection.normalize();
    rayDirection.scale(0.1);
    for (int i=0; i < 10000; i++) {
      int chunkX=(int)rayPosition.getX() >> 4;
      int chunkZ=(int)rayPosition.getZ() >> 4;
      ZonePlannerMapChunk zonePlannerMapChunk=ZonePlannerMapDataClient.instance.getLoadedChunk(new ZonePlannerMapChunkKey(new ChunkPos(chunkX,chunkZ),Minecraft.getMinecraft().theWorld.provider.getDimension(),getLevel()));
      if (zonePlannerMapChunk != null) {
        BlockPos pos=new BlockPos(Math.round(rayPosition.getX()) - chunkX * 16,Math.round(rayPosition.getY()),Math.round(rayPosition.getZ()) - chunkZ * 16);
        if (zonePlannerMapChunk.data.containsKey(pos)) {
          found=new BlockPos(pos.getX() + chunkX * 16,pos.getY(),pos.getZ() + chunkZ * 16);
          foundColor=zonePlannerMapChunk.data.get(pos);
          break;
        }
      }
 else {
        break;
      }
      rayPosition.add(rayDirection);
    }
  }
  if (found != null) {
    GL11.glDisable(GL11.GL_DEPTH_TEST);
    GL11.glDisable(GL11.GL_LIGHTING);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK,GL11.GL_LINE);
    GL11.glBegin(GL11.GL_QUADS);
    int r=(foundColor >> 16) & 0xFF;
    int g=(foundColor >> 8) & 0xFF;
    int b=(foundColor >> 0) & 0xFF;
    int a=(foundColor >> 24) & 0xFF;
    GL11.glColor4d(r / (double)0xFF + 0.3,g / (double)0xFF + 0.3,b / (double)0xFF + 0.3,0.7);
    ZonePlannerMapRenderer.instance.drawBlockCuboid(found.getX(),found.getY(),found.getZ());
    GL11.glEnd();
    GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK,GL11.GL_FILL);
    GL11.glDisable(GL11.GL_BLEND);
    GL11.glEnable(GL11.GL_LIGHTING);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
  }
  GL11.glDisable(GL11.GL_TEXTURE_2D);
  GL11.glDisable(GL11.GL_LIGHTING);
  GL11.glEnable(GL11.GL_BLEND);
  GL11.glBegin(GL11.GL_QUADS);
  for (int i=0; i < container.tile.layers.length; i++) {
    if (getPaintbrushBrush() != null && getPaintbrushBrush().colour.getMetadata() != i) {
      continue;
    }
    ZonePlan layer=container.tile.layers[i];
    if (getPaintbrushBrush() != null && getPaintbrushBrush().colour.getMetadata() == i && bufferLayer != null) {
      layer=bufferLayer;
    }
    if (!layer.getChunkPoses().isEmpty()) {
      for (int chunkX=chunkBaseX - radius; chunkX < chunkBaseX + radius; chunkX++) {
        for (int chunkZ=chunkBaseZ - radius; chunkZ < chunkBaseZ + radius; chunkZ++) {
          ChunkPos chunkPos=new ChunkPos(chunkX,chunkZ);
          if (layer.hasChunk(chunkPos)) {
            for (int blockX=chunkPos.getXStart(); blockX <= chunkPos.getXEnd(); blockX++) {
              for (int blockZ=chunkPos.getZStart(); blockZ <= chunkPos.getZEnd(); blockZ++) {
                if (layer.get(blockX,blockZ)) {
                  int height=256;
                  ZonePlannerMapChunk zonePlannerMapChunk=ZonePlannerMapDataClient.instance.getLoadedChunk(new ZonePlannerMapChunkKey(chunkPos,Minecraft.getMinecraft().theWorld.provider.getDimension(),getLevel()));
                  if (zonePlannerMapChunk != null) {
                    int finalBlockX=blockX;
                    int finalBlockZ=blockZ;
                    BlockPos pos=zonePlannerMapChunk.data.keySet().stream().filter(blockPos -> {
                      return blockPos.getX() == finalBlockX - chunkPos.chunkXPos * 16 && blockPos.getZ() == finalBlockZ - chunkPos.chunkZPos * 16;
                    }
).findFirst().orElse(null);
                    if (pos != null) {
                      height=pos.getY();
                    }
                  }
                  int color=EnumDyeColor.byMetadata(i).getMapColor().colorValue;
                  int r=(color >> 16) & 0xFF;
                  int g=(color >> 8) & 0xFF;
                  int b=(color >> 0) & 0xFF;
                  int a=(color >> 24) & 0xFF;
                  GL11.glColor4d(r / (double)0xFF,g / (double)0xFF,b / (double)0xFF,0.3);
                  ZonePlannerMapRenderer.instance.drawBlockCuboid(blockX,height + 0.1,blockZ,height,0.6);
                }
              }
            }
          }
        }
      }
    }
  }
  GL11.glEnd();
  GL11.glDisable(GL11.GL_BLEND);
  GL11.glEnable(GL11.GL_LIGHTING);
  GL11.glEnable(GL11.GL_TEXTURE_2D);
  lastSelected=found;
  GL11.glPopMatrix();
  GL11.glDisable(GL12.GL_RESCALE_NORMAL);
  GL11.glMatrixMode(GL11.GL_PROJECTION);
  GL11.glViewport(0,0,Minecraft.getMinecraft().displayWidth,Minecraft.getMinecraft().displayHeight);
  GL11.glPopMatrix();
  GL11.glMatrixMode(GL11.GL_MODELVIEW);
  GL11.glPopMatrix();
  RenderHelper.disableStandardItemLighting();
  GL11.glColor4d(1,1,1,1);
  GL11.glDisable(GL11.GL_BLEND);
}

Fixed version (ground truth):
@SuppressWarnings("String_Node_Str") @Override protected void drawForegroundLayer(){
  camY+=scaleSpeed;
  scaleSpeed*=0.7F;
{
    ChunkPos chunkPos=new ChunkPos((int)positionX >> 4,(int)positionZ >> 4);
    ZonePlannerMapChunk zonePlannerMapChunk=ZonePlannerMapDataClient.instance.getLoadedChunk(new ZonePlannerMapChunkKey(chunkPos,Minecraft.getMinecraft().theWorld.provider.getDimension(),getLevel()));
    BlockPos pos=null;
    if (zonePlannerMapChunk != null) {
      pos=zonePlannerMapChunk.data.keySet().stream().filter(blockPos -> blockPos.getX() == (int)positionX - chunkPos.getXStart() && blockPos.getZ() == (int)positionZ - chunkPos.getZStart()).findAny().orElse(null);
    }
    if (pos != null && pos.getY() + 10 > camY) {
      camY=Math.max(camY,pos.getY() + 10);
    }
  }
  int x=guiLeft;
  int y=guiTop;
  if (lastSelected != null) {
    String text="String_Node_Str" + lastSelected.getX() + "String_Node_Str"+ lastSelected.getY()+ "String_Node_Str"+ lastSelected.getZ();
    fontRendererObj.drawString(text,x + 130,y + 130,0x404040);
  }
  int offsetX=8;
  int offsetY=9;
  int sizeX=213;
  int sizeY=100;
  GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);
  GL11.glPushMatrix();
  GL11.glMatrixMode(GL11.GL_PROJECTION);
  GL11.glPushMatrix();
  GL11.glLoadIdentity();
  ScaledResolution scaledResolution=new ScaledResolution(Minecraft.getMinecraft());
  GL11.glViewport((x + offsetX) * scaledResolution.getScaleFactor(),Minecraft.getMinecraft().displayHeight - (sizeY + y + offsetY) * scaledResolution.getScaleFactor(),sizeX * scaledResolution.getScaleFactor(),sizeY * scaledResolution.getScaleFactor());
  GL11.glScalef(scaledResolution.getScaleFactor(),scaledResolution.getScaleFactor(),1);
  GLU.gluPerspective(70.0F,(float)sizeX / sizeY,1F,1000.0F);
  GL11.glMatrixMode(GL11.GL_MODELVIEW);
  GL11.glLoadIdentity();
  RenderHelper.enableStandardItemLighting();
  GlStateManager.enableRescaleNormal();
  GL11.glRotatef(90,1,0,0);
  GL11.glPushMatrix();
  GL11.glTranslatef(-positionX,-camY,-positionZ);
  GlStateManager.disableBlend();
  GlStateManager.disableAlpha();
  Minecraft.getMinecraft().getRenderManager().renderEngine.bindTexture(new ResourceLocation("String_Node_Str","String_Node_Str"));
  int chunkBaseX=(int)positionX >> 4;
  int chunkBaseZ=(int)positionZ >> 4;
  int radius=8;
  for (int chunkX=chunkBaseX - radius; chunkX < chunkBaseX + radius; chunkX++) {
    for (int chunkZ=chunkBaseZ - radius; chunkZ < chunkBaseZ + radius; chunkZ++) {
      GL11.glCallList(ZonePlannerMapRenderer.instance.drawChunk(new ZonePlannerMapChunkKey(new ChunkPos(chunkX,chunkZ),container.tile.getWorld().provider.getDimension(),getLevel())));
    }
  }
  BlockPos found=null;
  int foundColor=0;
  if (Mouse.getX() / scaledResolution.getScaleFactor() > x + offsetX && Mouse.getX() / scaledResolution.getScaleFactor() < x + offsetX + sizeX && scaledResolution.getScaledHeight() - Mouse.getY() / scaledResolution.getScaleFactor() > y + offsetY && scaledResolution.getScaledHeight() - Mouse.getY() / scaledResolution.getScaleFactor() < y + offsetY + sizeY) {
    FloatBuffer projectionBuffer=BufferUtils.createFloatBuffer(16);
    FloatBuffer modelViewBuffer=BufferUtils.createFloatBuffer(16);
    IntBuffer viewportBuffer=BufferUtils.createIntBuffer(16);
    GL11.glGetFloat(GL11.GL_PROJECTION_MATRIX,projectionBuffer);
    GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX,modelViewBuffer);
    GL11.glGetInteger(GL11.GL_VIEWPORT,viewportBuffer);
    FloatBuffer positionNearBuffer=BufferUtils.createFloatBuffer(3);
    FloatBuffer positionFarBuffer=BufferUtils.createFloatBuffer(3);
    GLU.gluUnProject(Mouse.getX(),Mouse.getY(),0f,modelViewBuffer,projectionBuffer,viewportBuffer,positionNearBuffer);
    GLU.gluUnProject(Mouse.getX(),Mouse.getY(),1f,modelViewBuffer,projectionBuffer,viewportBuffer,positionFarBuffer);
    Vector3d rayStart=new Vector3d(positionNearBuffer.get(0),positionNearBuffer.get(1),positionNearBuffer.get(2));
    Vector3d rayPosition=new Vector3d(rayStart);
    Vector3d rayDirection=new Vector3d(positionFarBuffer.get(0),positionFarBuffer.get(1),positionFarBuffer.get(2));
    rayDirection.sub(rayStart);
    rayDirection.normalize();
    rayDirection.scale(0.1);
    for (int i=0; i < 10000; i++) {
      int chunkX=(int)rayPosition.getX() >> 4;
      int chunkZ=(int)rayPosition.getZ() >> 4;
      ZonePlannerMapChunk zonePlannerMapChunk=ZonePlannerMapDataClient.instance.getLoadedChunk(new ZonePlannerMapChunkKey(new ChunkPos(chunkX,chunkZ),Minecraft.getMinecraft().theWorld.provider.getDimension(),getLevel()));
      if (zonePlannerMapChunk != null) {
        BlockPos pos=new BlockPos(Math.round(rayPosition.getX()) - chunkX * 16,Math.round(rayPosition.getY()),Math.round(rayPosition.getZ()) - chunkZ * 16);
        if (zonePlannerMapChunk.data.containsKey(pos)) {
          found=new BlockPos(pos.getX() + chunkX * 16,pos.getY(),pos.getZ() + chunkZ * 16);
          foundColor=zonePlannerMapChunk.data.get(pos);
          break;
        }
      }
 else {
        break;
      }
      rayPosition.add(rayDirection);
    }
  }
  if (found != null) {
    GlStateManager.disableDepth();
    GlStateManager.disableLighting();
    GlStateManager.enableBlend();
    GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK,GL11.GL_LINE);
    GL11.glBegin(GL11.GL_QUADS);
    int r=(foundColor >> 16) & 0xFF;
    int g=(foundColor >> 8) & 0xFF;
    int b=(foundColor >> 0) & 0xFF;
    int a=(foundColor >> 24) & 0xFF;
    GL11.glColor4d(r / (double)0xFF + 0.3,g / (double)0xFF + 0.3,b / (double)0xFF + 0.3,0.7);
    ZonePlannerMapRenderer.instance.drawBlockCuboid(found.getX(),found.getY(),found.getZ());
    GL11.glEnd();
    GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK,GL11.GL_FILL);
    GlStateManager.disableBlend();
    GlStateManager.enableLighting();
    GlStateManager.enableLighting();
    GlStateManager.enableDepth();
  }
  GlStateManager.disableTexture2D();
  GlStateManager.disableLighting();
  GlStateManager.enableBlend();
  GL11.glBegin(GL11.GL_QUADS);
  for (int i=0; i < container.tile.layers.length; i++) {
    if (getPaintbrushBrush() != null && getPaintbrushBrush().colour.getMetadata() != i) {
      continue;
    }
    ZonePlan layer=container.tile.layers[i];
    if (getPaintbrushBrush() != null && getPaintbrushBrush().colour.getMetadata() == i && bufferLayer != null) {
      layer=bufferLayer;
    }
    if (!layer.getChunkPoses().isEmpty()) {
      for (int chunkX=chunkBaseX - radius; chunkX < chunkBaseX + radius; chunkX++) {
        for (int chunkZ=chunkBaseZ - radius; chunkZ < chunkBaseZ + radius; chunkZ++) {
          ChunkPos chunkPos=new ChunkPos(chunkX,chunkZ);
          if (layer.hasChunk(chunkPos)) {
            for (int blockX=chunkPos.getXStart(); blockX <= chunkPos.getXEnd(); blockX++) {
              for (int blockZ=chunkPos.getZStart(); blockZ <= chunkPos.getZEnd(); blockZ++) {
                if (layer.get(blockX,blockZ)) {
                  int height=256;
                  ZonePlannerMapChunk zonePlannerMapChunk=ZonePlannerMapDataClient.instance.getLoadedChunk(new ZonePlannerMapChunkKey(chunkPos,Minecraft.getMinecraft().theWorld.provider.getDimension(),getLevel()));
                  if (zonePlannerMapChunk != null) {
                    int finalBlockX=blockX;
                    int finalBlockZ=blockZ;
                    BlockPos pos=zonePlannerMapChunk.data.keySet().stream().filter(blockPos -> {
                      return blockPos.getX() == finalBlockX - chunkPos.chunkXPos * 16 && blockPos.getZ() == finalBlockZ - chunkPos.chunkZPos * 16;
                    }
).findFirst().orElse(null);
                    if (pos != null) {
                      height=pos.getY();
                    }
                  }
                  int color=EnumDyeColor.byMetadata(i).getMapColor().colorValue;
                  int r=(color >> 16) & 0xFF;
                  int g=(color >> 8) & 0xFF;
                  int b=(color >> 0) & 0xFF;
                  int a=(color >> 24) & 0xFF;
                  GL11.glColor4d(r / (double)0xFF,g / (double)0xFF,b / (double)0xFF,0.3);
                  ZonePlannerMapRenderer.instance.drawBlockCuboid(blockX,height + 0.1,blockZ,height,0.6);
                }
              }
            }
          }
        }
      }
    }
  }
  GL11.glEnd();
  GlStateManager.disableBlend();
  GlStateManager.disableLighting();
  GlStateManager.enableTexture2D();
  lastSelected=found;
  GL11.glPopMatrix();
  GlStateManager.disableRescaleNormal();
  GL11.glMatrixMode(GL11.GL_PROJECTION);
  GL11.glViewport(0,0,Minecraft.getMinecraft().displayWidth,Minecraft.getMinecraft().displayHeight);
  GL11.glPopMatrix();
  GL11.glMatrixMode(GL11.GL_MODELVIEW);
  GL11.glPopMatrix();
  RenderHelper.disableStandardItemLighting();
  GL11.glColor4d(1,1,1,1);
  GlStateManager.disableBlend();
}