Skip to content

Commit

Permalink
Merge pull request #261 from Dragon-Seeker/1.21-FixConfigRendering
Browse files Browse the repository at this point in the history
[1.21] Fix config rendering be black and oddly hard to look at.
  • Loading branch information
gliscowo authored Jul 21, 2024
2 parents 01a30ec + 00ea745 commit 0bffb9c
Show file tree
Hide file tree
Showing 5 changed files with 316 additions and 113 deletions.
20 changes: 20 additions & 0 deletions src/main/java/io/wispforest/owo/mixin/ScreenAccessor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.wispforest.owo.mixin;

import net.minecraft.client.gui.CubeMapRenderer;
import net.minecraft.client.gui.RotatingCubeMapRenderer;
import net.minecraft.client.gui.screen.Screen;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(Screen.class)
public interface ScreenAccessor {
@Accessor("PANORAMA_RENDERER")
static CubeMapRenderer owo$PANORAMA_RENDERER() {
throw new UnsupportedOperationException();
}

@Accessor("ROTATING_PANORAMA_RENDERER")
static RotatingCubeMapRenderer owo$ROTATING_PANORAMA_RENDERER() {
throw new UnsupportedOperationException();
}
}
56 changes: 49 additions & 7 deletions src/main/java/io/wispforest/owo/ui/core/Surface.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package io.wispforest.owo.ui.core;

import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import io.wispforest.owo.client.OwoClient;
import io.wispforest.owo.mixin.ScreenAccessor;
import io.wispforest.owo.ui.parsing.UIModelParsingException;
import io.wispforest.owo.ui.parsing.UIParsing;
import io.wispforest.owo.ui.util.NinePatchTexture;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.CubeMapRenderer;
import net.minecraft.client.gui.RotatingCubeMapRenderer;
import net.minecraft.client.gui.tooltip.TooltipBackgroundRenderer;
import net.minecraft.client.render.*;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

Expand All @@ -36,10 +38,8 @@ public interface Surface {
);
};

Surface OPTIONS_BACKGROUND = (context, component) -> {
MinecraftClient.getInstance().gameRenderer.renderBlur(0);
MinecraftClient.getInstance().getFramebuffer().beginWrite(false);
};
Surface OPTIONS_BACKGROUND = Surface.panorama(ScreenAccessor.owo$ROTATING_PANORAMA_RENDERER(), false)
.and(Surface.blur(5, 10));

Surface TOOLTIP = (context, component) -> {
context.draw(() -> {
Expand All @@ -66,6 +66,48 @@ static Surface blur(float quality, float size) {
};
}

static Surface vanillaPanorama(boolean alwaysVisible) {
return panorama(new RotatingCubeMapRenderer(ScreenAccessor.owo$PANORAMA_RENDERER()), alwaysVisible);
}

static Surface panorama(RotatingCubeMapRenderer renderer, boolean alwaysVisible) {
return (context, component) -> {
if (!alwaysVisible && MinecraftClient.getInstance().world != null) return;

var client = MinecraftClient.getInstance();

int prevX = GlStateManager.Viewport.getX();
int prevY = GlStateManager.Viewport.getY();
int prevWidth = GlStateManager.Viewport.getWidth();
int prevHeight = GlStateManager.Viewport.getHeight();

var window = client.getWindow();
var scale = window.getScaleFactor();

var x = component.x();
var y = component.y();
var width = component.width();
var height = component.height();

RenderSystem.viewport(
(int) (x * scale),
(int) (window.getFramebufferHeight() - (y * scale) - height * scale),
MathHelper.clamp((int) (width * scale), 0, window.getFramebufferWidth()),
MathHelper.clamp((int) (height * scale), 0, window.getFramebufferHeight())
);

var delta = client.getRenderTickCounter().getLastDuration();

RenderSystem.disableDepthTest();

renderer.render(context, width, height, 1.0F, delta);

RenderSystem.enableDepthTest();

RenderSystem.viewport(prevX, prevY, prevWidth, prevHeight);
};
}

Surface BLANK = (context, component) -> {};

static Surface flat(int color) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/owo.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"NbtCompoundMixin",
"PacketByteBufMixin",
"RegistryOpsAccessor",
"ScreenAccessor",
"ScreenHandlerInvoker",
"ScreenHandlerMixin",
"ServerCommonNetworkHandlerAccessor",
Expand Down Expand Up @@ -43,9 +44,9 @@
"ui.access.BlockEntityAccessor"
],
"client": [
"ClientCommonNetworkHandlerAccessor",
"ClientConfigurationNetworkHandlerMixin",
"ClientLoginNetworkHandlerAccessor",
"ClientCommonNetworkHandlerAccessor",
"DrawContextMixin",
"MinecraftClientMixin",
"itemgroup.AbstractInventoryScreenMixin",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected void init() {
.child(Components.button(Text.of("Dirt Background"), button -> rootComponent.surface(Surface.OPTIONS_BACKGROUND)).horizontalSizing(Sizing.fixed(95)))
.child(Components.checkbox(Text.of("bruh")).onChanged(aBoolean -> this.client.player.sendMessage(Text.of("bruh: " + aBoolean))).margins(Insets.top(5)))
.padding(Insets.of(10))
.surface(Surface.flat(0x77000000))
.surface(Surface.vanillaPanorama(true))
.positioning(Positioning.relative(1, 1))
);

Expand Down
Loading

0 comments on commit 0bffb9c

Please sign in to comment.