Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
lcy0x1 committed Sep 19, 2024
1 parent e65f2b5 commit 531f769
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
7 changes: 1 addition & 6 deletions src/main/java/net/neoforged/neoforge/client/ClientHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@
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 @@ -247,12 +246,8 @@ public static void popGuiLayer(Minecraft minecraft) {
}

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

// 11000 units for the overlay background and 10000 units for each layered Scree
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@

package net.neoforged.neoforge.client.gui;

import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.VertexFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.function.BooleanSupplier;
import net.minecraft.client.DeltaTracker;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.LayeredDraw;
import net.minecraft.client.renderer.RenderStateShard;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.resources.ResourceLocation;
import net.neoforged.fml.ModLoader;
import net.neoforged.neoforge.client.event.RegisterGuiLayersEvent;
Expand Down Expand Up @@ -69,8 +73,10 @@ private void renderInner(GuiGraphics guiGraphics, DeltaTracker partialTick) {
layer.layer().render(guiGraphics, partialTick);
NeoForge.EVENT_BUS.post(new RenderGuiLayerEvent.Post(guiGraphics, partialTick, layer.name(), layer.layer()));
}

guiGraphics.pose().translate(0.0F, 0.0F, Z_SEPARATION);
// clear depth values to keep hud rendered at the same depth
guiGraphics.pose().translate(0, 0, -1000);
guiGraphics.fill(LayerRenderType.GUI, 0, 0, guiGraphics.guiWidth(), guiGraphics.guiHeight(), -1);
guiGraphics.pose().translate(0, 0, 1000);
}

guiGraphics.pose().popPose();
Expand All @@ -87,4 +93,21 @@ public void initModdedLayers() {
public int getLayerCount() {
return this.layers.size();
}

private static class LayerRenderType extends RenderType {
public static final RenderType GUI = create(
"reverse_gui",
DefaultVertexFormat.POSITION_COLOR,
VertexFormat.Mode.QUADS,
786432,
RenderType.CompositeState.builder()
.setShaderState(RENDERTYPE_GUI_SHADER)
.setWriteMaskState(RenderStateShard.DEPTH_WRITE)
.setDepthTestState(GREATER_DEPTH_TEST)
.createCompositeState(false));

public LayerRenderType(String name, VertexFormat format, VertexFormat.Mode mode, int bufferSize, boolean affectsCrumbling, boolean sortOnUpload, Runnable setupState, Runnable clearState) {
super(name, format, mode, bufferSize, affectsCrumbling, sortOnUpload, setupState, clearState);
}
}
}

0 comments on commit 531f769

Please sign in to comment.