Repository: neoforged/NeoForge (Java)

Issue:
VanillaTweaks "No Spyglass Overlay" is incompatible with NeoForge
**NeoForge Version:** 20.4.65-beta

**Steps to Reproduce:**
 1. Download and install the "No Spyglass Overlay" resource pack from the [VanillaTweaks website](https://vanillatweaks.net/picker/resource-packs/) (in Unobtrusive)
 2. Use the spyglass
 3. The black borders are still present in NeoForge, unlike in Minecraft Vanilla

**Description of issue:**

NeoForge:
![2023-12-30_13 01 46](https://github.com/neoforged/NeoForge/assets/68275908/284f0007-83f8-4f10-8f06-42a8095194f1)

Vanilla:
![2023-12-30_13 02 43](https://github.com/neoforged/NeoForge/assets/68275908/e75b5c77-ab98-4807-928f-1576a5cf780c)



Discussion: This is the vanilla tweaks resourcepack. It seems to consist of overriding one texture file and overriding a shader file. The shader part is likely the issue. Might not be solvable depending on how neoforge handles shaders
[VanillaTweaks_r929072.zip](https://github.com/neoforged/NeoForge/files/13805238/VanillaTweaks_r929072.zip)

This issue seems to be caused by a difference between 1.19 and 1.20's value for the GUI far plane, which causes an assumption by the resource pack's shader to not hold true.

As recent as 1.19.x, we had a patch in `GameRenderer` to hook into the GUI far plane calculations, in order to account for the layered screen feature Forge provides:

https://github.com/neoforged/NeoForge/blob/50db51a366350cc1b76e9beccf60eeab06d369f3/patches/minecraft/net/minecraft/client/renderer/GameRenderer.java.patch#L75-L89

The `ForgeHooksClient#getGuiFarPlane()` accounted for the overlay background and each layered screen, such that having no layered screens would be equivalent to the vanilla values:

https://github.com/neoforged/NeoForge/blob/50db51a366350cc1b76e9beccf60eeab06d369f3/src/main/java/net/minecraftforge/client/ForgeHooksClient.java#L252-L258

However, since at least 1.20.1, the GUI far plane value was adjusted, from its previous value of `3000` to a new value of `21000`:

https://github.com/neoforged/NeoForge/blob/6302718cc167b4b8b0e18cfc09696670788ee1f8/patches/minecraft/net/minecraft/client/renderer/GameRenderer.java.patch#L78-L92

This means that the values NeoForge uses for calculating the GUI far plane (and the plane at which the overlay is rendered at) are different from vanilla's, even in the case of having no layered screens. 

This means the assumption made by the resource pack's vertex shader to detecth the spyglass overlay being rendered -- that the spyglass overlay is layered at a specific depth `-11100 < depth < -11075` -- always hold false, causing the corresponding fragment shader to never discard the black-colored overlay texture fragment(s).

The solution is likely to adjust the return value of `ClientHooks#getGuiFarPlane()` (and/or its calling sites) to correspond to the new vanilla values.



Fix (patch):
diff --git a/patches/net/minecraft/client/renderer/GameRenderer.java.patch b/patches/net/minecraft/client/renderer/GameRenderer.java.patch
index 62ac6a5530d..ac2738c8435 100644
--- a/patches/net/minecraft/client/renderer/GameRenderer.java.patch
+++ b/patches/net/minecraft/client/renderer/GameRenderer.java.patch
@@ -74,7 +74,7 @@
              posestack.pushPose();
              posestack.setIdentity();
 -            posestack.translate(0.0F, 0.0F, -11000.0F);
-+            posestack.translate(0.0D, 0.0D, 1000F - net.neoforged.neoforge.client.ClientHooks.getGuiFarPlane());
++            posestack.translate(0.0D, 0.0D, 10000F - net.neoforged.neoforge.client.ClientHooks.getGuiFarPlane());
              RenderSystem.applyModelViewMatrix();
              Lighting.setupFor3DItems();
              GuiGraphics guigraphics = new GuiGraphics(this.minecraft, this.renderBuffers.bufferSource());
diff --git a/src/main/java/net/neoforged/neoforge/client/ClientHooks.java b/src/main/java/net/neoforged/neoforge/client/ClientHooks.java
index 93b1a1a752a..27ba92f7e93 100644
--- a/src/main/java/net/neoforged/neoforge/client/ClientHooks.java
+++ b/src/main/java/net/neoforged/neoforge/client/ClientHooks.java
@@ -233,10 +233,10 @@ public static void popGuiLayer(Minecraft minecraft) {
     }
 
     public static float getGuiFarPlane() {
-        // 1000 units for the overlay background,
+        // 11000 units for the overlay background,
         // and 10000 units for each layered Screen,
 
-        return 1000.0F + 10000.0F * (1 + guiLayers.size());
+        return 11000.0F + 10000.0F * (1 + guiLayers.size());
     }
 
     public static String getArmorTexture(Entity entity, ItemStack armor, String _default, EquipmentSlot slot, String type) {
@@ -376,7 +376,7 @@ public static void drawScreen(Screen screen, GuiGraphics guiGraphics, int mouseX
         guiLayers.forEach(layer -> {
             // Prevent the background layers from thinking the mouse is over their controls and showing them as highlighted.
             drawScreenInternal(layer, guiGraphics, Integer.MAX_VALUE, Integer.MAX_VALUE, partialTick);
-            guiGraphics.pose().translate(0, 0, 2000);
+            guiGraphics.pose().translate(0, 0, 10000);
         });
         drawScreenInternal(screen, guiGraphics, mouseX, mouseY, partialTick);
         guiGraphics.pose().popPose();