Skip to content

Commit

Permalink
[ui] fix RenderEffectWrapper, SlimSliderComponent and SmallCheckboxCo…
Browse files Browse the repository at this point in the history
…mponent, compile against 1.21.2 proper
  • Loading branch information
gliscowo committed Oct 22, 2024
1 parent 5606b5c commit 39728ef
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 16 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ org.gradle.jvmargs=-Xmx2G
# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_base_version=1.21.2
minecraft_version=1.21.2-rc2
yarn_mappings=1.21.2-rc2+build.1
minecraft_version=1.21.2
yarn_mappings=1.21.2+build.1
loader_version=0.16.7
# Mod Properties
mod_version=0.12.15
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/io/wispforest/owo/mixin/ui/RenderPhaseMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.wispforest.owo.mixin.ui;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import io.wispforest.owo.ui.container.RenderEffectWrapper;
import net.minecraft.client.gl.Framebuffer;
import net.minecraft.client.render.RenderPhase;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

@Mixin(RenderPhase.class)
public class RenderPhaseMixin {

@ModifyExpressionValue(method = "method_62272", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/MinecraftClient;getFramebuffer()Lnet/minecraft/client/gl/Framebuffer;"))
private static Framebuffer injectProperRenderTarget(Framebuffer original) {
if (RenderEffectWrapper.currentFramebuffer() != null) {
return RenderEffectWrapper.currentFramebuffer();
}

return original;
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.wispforest.owo.ui.component;

import com.mojang.blaze3d.systems.RenderSystem;
import io.wispforest.owo.ui.base.BaseComponent;
import io.wispforest.owo.ui.core.Component;
import io.wispforest.owo.ui.core.CursorStyle;
Expand Down Expand Up @@ -75,10 +74,10 @@ protected int determineVerticalContentSize(Sizing sizing) {
public void draw(OwoUIDrawContext context, int mouseX, int mouseY, float partialTicks, float delta) {
if (this.axis == Axis.HORIZONTAL) {
NinePatchTexture.draw(TRACK_TEXTURE, context, this.x + 1, this.y + 3, this.width - 2, 3);
context.drawTexture(RenderLayer::getGuiTextured, TEXTURE, (int) (this.x + (this.width - 4) * this.value.get()), this.y + 1, 4, 7, 0, 3, 4, 7, 16, 16);
context.drawTexture(RenderLayer::getGuiTextured, TEXTURE, (int) (this.x + (this.width - 4) * this.value.get()), this.y + 1, 0, 3, 4, 7, 4, 7, 16, 16);
} else {
NinePatchTexture.draw(TRACK_TEXTURE, context, this.x + 3, this.y + 1, 3, this.height - 2);
context.drawTexture(RenderLayer::getGuiTextured, TEXTURE, this.x + 1, (int) (this.y + (this.height - 4) * this.value.get()), 7, 4, 4, 3, 7, 4, 16, 16);
context.drawTexture(RenderLayer::getGuiTextured, TEXTURE, this.x + 1, (int) (this.y + (this.height - 4) * this.value.get()), 4, 3, 7, 4, 7, 4, 16, 16);
}
}

Expand All @@ -105,8 +104,8 @@ public boolean onMouseUp(double mouseX, double mouseY, int button) {

protected void setValueFromMouse(double mouseX, double mouseY) {
this.value(this.axis == Axis.VERTICAL
? this.min + (mouseY / this.height) * (this.max - this.min)
: this.min + (mouseX / this.width) * (this.max - this.min));
? this.min + (mouseY / this.height) * (this.max - this.min)
: this.min + (mouseX / this.width) * (this.max - this.min));
}

@Override
Expand Down Expand Up @@ -194,8 +193,8 @@ public void parseProperties(UIModel model, Element element, Map<String, Element>

public static Component parse(Element element) {
return element.getAttribute("direction").equals("vertical")
? new SlimSliderComponent(Axis.VERTICAL)
: new SlimSliderComponent(Axis.HORIZONTAL);
? new SlimSliderComponent(Axis.VERTICAL)
: new SlimSliderComponent(Axis.HORIZONTAL);
}

public static Function<Double, Text> valueTooltipSupplier(int decimalPlaces) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ public void draw(OwoUIDrawContext context, int mouseX, int mouseY, float partial
context.drawText(MinecraftClient.getInstance().textRenderer, this.label.get(), this.x + 13 + 2, this.y + 3, Color.WHITE.argb(), this.labelShadow);
}

context.drawTexture(RenderLayer::getGuiTextured, TEXTURE, this.x, this.y, 13, 13, 0, 0, 13, 13, 32, 16);
context.drawTexture(RenderLayer::getGuiTextured, TEXTURE, this.x, this.y, 0, 0, 13, 13, 13, 13, 32, 16);
if (this.checked) {
context.drawTexture(RenderLayer::getGuiTextured, TEXTURE, this.x, this.y, 13, 13, 16, 0, 13, 13, 32, 16);
context.drawTexture(RenderLayer::getGuiTextured, TEXTURE, this.x, this.y, 16, 0, 13, 13, 13, 13, 32, 16);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
import net.minecraft.client.gl.SimpleFramebuffer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.render.BufferRenderer;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.render.VertexFormat;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.math.RotationAxis;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
import org.joml.Matrix4f;
import org.lwjgl.opengl.GL30;

Expand All @@ -42,6 +42,8 @@
@ApiStatus.Experimental
public class RenderEffectWrapper<C extends Component> extends WrappingParentComponent<C> {

private static @Nullable Framebuffer currentFramebuffer = null;

protected static final List<Framebuffer> FRAMEBUFFERS = new ArrayList<>();
protected static int drawDepth = 0;

Expand All @@ -55,6 +57,7 @@ protected RenderEffectWrapper(C child) {
@Override
public void draw(OwoUIDrawContext context, int mouseX, int mouseY, float partialTicks, float delta) {
super.draw(context, mouseX, mouseY, partialTicks, delta);
context.draw();

try {
drawDepth++;
Expand All @@ -70,9 +73,14 @@ public void draw(OwoUIDrawContext context, int mouseX, int mouseY, float partial
ScissorStack.drawUnclipped(framebuffer::clear);
framebuffer.beginWrite(false);

var lastFramebuffer = currentFramebuffer;
currentFramebuffer = framebuffer;

this.drawChildren(context, mouseX, mouseY, partialTicks, delta, this.childView);
context.draw();

GlStateManager._glBindFramebuffer(GL30.GL_FRAMEBUFFER, previousFramebuffer);
currentFramebuffer = lastFramebuffer;

var iter = this.effects.listIterator();
while (iter.hasNext()) {
Expand Down Expand Up @@ -122,6 +130,11 @@ public void clearEffects() {
this.effects.clear();
}

@ApiStatus.Internal
public static @Nullable Framebuffer currentFramebuffer() {
return currentFramebuffer;
}

static {
WindowResizeCallback.EVENT.register((client, window) -> {
FRAMEBUFFERS.forEach(framebuffer -> {
Expand Down
7 changes: 4 additions & 3 deletions src/main/resources/owo.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
"ServerPlayerInteractionManagerMixin",
"SetComponentsLootFunctionAccessor",
"TagGroupLoaderMixin",
"ext.MergedComponentMapAccessor",
"ext.MergedComponentMapMixin",
"ext.ItemMixin",
"ext.ItemStackMixin",
"ext.MergedComponentMapAccessor",
"ext.MergedComponentMapMixin",
"itemgroup.ItemGroupAccessor",
"itemgroup.ItemMixin",
"itemgroup.ItemSettingsMixin",
Expand Down Expand Up @@ -54,10 +54,10 @@
"ClientLoginNetworkHandlerAccessor",
"DrawContextMixin",
"MinecraftClientMixin",
"itemgroup.StatusEffectsDisplayMixin",
"itemgroup.CreativeInventoryScreenAccessor",
"itemgroup.CreativeInventoryScreenMixin",
"itemgroup.MixinCreativeInventoryScreenMixin",
"itemgroup.StatusEffectsDisplayMixin",
"shader.ShaderProgramAccessor",
"text.TranslationStorageMixin",
"tweaks.OperatingSystemMixin",
Expand All @@ -70,6 +70,7 @@
"ui.EntityRendererMixin",
"ui.HandledScreenMixin",
"ui.MinecraftClientMixin",
"ui.RenderPhaseMixin",
"ui.RenderSystemMixin",
"ui.ScreenMixin",
"ui.SliderWidgetMixin",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ protected void init() {
.selectedColor(Color.ofArgb(0x7F3955E5))
.sizing(Sizing.fixed(160), Sizing.fixed(100))
).padding(Insets.of(5)).surface(Surface.DARK_PANEL)
));
).zIndex(1000));
})
);

Expand Down

0 comments on commit 39728ef

Please sign in to comment.