Skip to content

Commit

Permalink
Fix HUD elements at high Z values vanishing when many elements are re…
Browse files Browse the repository at this point in the history
…gistered (#1404)
  • Loading branch information
XFactHD authored Aug 1, 2024
1 parent fe951c2 commit 5700ea2
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 4 deletions.
6 changes: 5 additions & 1 deletion patches/net/minecraft/client/gui/Gui.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -390,14 +390,18 @@
this.toolHighlightTimer = (int)(40.0 * this.minecraft.options.notificationDisplayTime().get());
} else if (this.toolHighlightTimer > 0) {
this.toolHighlightTimer--;
@@ -1292,8 +_,13 @@
@@ -1292,8 +_,17 @@
}
}

+ @org.jetbrains.annotations.ApiStatus.Internal
+ public void initModdedOverlays() {
+ this.layerManager.initModdedLayers();
+ }
+
+ public int getLayerCount() {
+ return this.layerManager.getLayerCount();
+ }
+
@OnlyIn(Dist.CLIENT)
- public static enum HeartType {
Expand Down
11 changes: 11 additions & 0 deletions patches/net/minecraft/client/renderer/PanoramaRenderer.java.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- a/net/minecraft/client/renderer/PanoramaRenderer.java
+++ b/net/minecraft/client/renderer/PanoramaRenderer.java
@@ -30,6 +_,8 @@
p_334063_.blit(PANORAMA_OVERLAY, 0, 0, p_333839_, p_333923_, 0.0F, 0.0F, 16, 128, 16, 128);
p_334063_.setColor(1.0F, 1.0F, 1.0F, 1.0F);
RenderSystem.disableBlend();
+ // Neo: disable depth test again to prevent issues with extended far plane values for screen layers and HUD layers
+ RenderSystem.disableDepthTest();
}

private static float wrap(float p_249058_, float p_249548_) {
10 changes: 7 additions & 3 deletions src/main/java/net/neoforged/neoforge/client/ClientHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
import net.neoforged.neoforge.client.extensions.common.IClientItemExtensions;
import net.neoforged.neoforge.client.extensions.common.IClientMobEffectExtensions;
import net.neoforged.neoforge.client.gui.ClientTooltipComponentManager;
import net.neoforged.neoforge.client.gui.GuiLayerManager;
import net.neoforged.neoforge.client.gui.map.MapDecorationRendererManager;
import net.neoforged.neoforge.client.model.data.ModelData;
import net.neoforged.neoforge.common.NeoForge;
Expand Down Expand Up @@ -245,10 +246,13 @@ public static void popGuiLayer(Minecraft minecraft) {
}

public static float getGuiFarPlane() {
// 11000 units for the overlay background,
// and 10000 units for each layered Screen,
// 11000 units for the overlay background and 10000 units for each layered Screen or 200 units for each HUD layer, whichever ends up higher

return 11000.0F + 10000.0F * (1 + guiLayers.size());
float depth = 10_000F * (1 + guiLayers.size());
if (Minecraft.getInstance().level != null) {
depth = Math.max(depth, GuiLayerManager.Z_SEPARATION * Minecraft.getInstance().gui.getLayerCount());
}
return 11_000F + depth;
}

public static ResourceLocation getArmorTexture(Entity entity, ItemStack armor, ArmorMaterial.Layer layer, boolean innerModel, EquipmentSlot slot) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,8 @@ public void initModdedLayers() {
initialized = true;
ModLoader.postEvent(new RegisterGuiLayersEvent(this.layers));
}

public int getLayerCount() {
return this.layers.size();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,27 @@ private static LayeredDraw.Layer makeLeftOverlay(DynamicTest test, int height, i
gui.leftHeight += height + 1;
};
}

@TestHolder(description = "Checks that the depth budget for GUI layers gets adjusted as necessary")
static void testGuiLayerDepthBudget(DynamicTest test) {
test.framework().modEventBus().addListener((RegisterGuiLayersEvent event) -> {
// Register some placeholder layers
for (int i = 0; i < 50; i++) {
event.registerAboveAll(ResourceLocation.fromNamespaceAndPath(test.createModId(), "fake_" + i), (guiGraphics, deltaTracker) -> {});
}
// Register the real layer
event.registerAboveAll(ResourceLocation.fromNamespaceAndPath(test.createModId(), "high_depth_test"), (guiGraphics, deltaTracker) -> {
if (test.framework().tests().isEnabled(test.id())) {
guiGraphics.fill(guiGraphics.guiWidth() - 50, 0, guiGraphics.guiWidth(), 50, 0xFFFF0000);
}
});
});

test.eventListeners().forge().addListener((ClientChatEvent chatEvent) -> {
if (chatEvent.getMessage().equalsIgnoreCase("gui layer depth test")) {
test.requestConfirmation(Minecraft.getInstance().player, Component.literal(
"Do you see a red square in the top right corner of the screen?"));
}
});
}
}

0 comments on commit 5700ea2

Please sign in to comment.