Skip to content

Commit

Permalink
Fix stupid mistakes with porting and PR such
Browse files Browse the repository at this point in the history
  • Loading branch information
Dragon-Seeker committed Oct 18, 2024
1 parent a9b3535 commit 957906f
Show file tree
Hide file tree
Showing 14 changed files with 211 additions and 151 deletions.
9 changes: 8 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ loom {
name = "Testmod Server"
source sourceSets.testmod
}
testmodClient_renderDoc {
client()
ideConfigGenerated project.rootProject == project
name = "Testmod Client - (RenderDoc)"
source sourceSets.testmod
vmArg "-Dowo.renderdocPath=${System.getenv('renderDocPath')}"
}
}

accessWidenerPath = file("src/main/resources/owo.accesswidener")
Expand All @@ -129,7 +136,7 @@ dependencies {
// modLocalRuntime("dev.emi:emi-fabric:${project.emi_version}")

modCompileOnly("com.terraformersmc:modmenu:${project.modmenu_version}")
modLocalRuntime("com.terraformersmc:modmenu:${project.modmenu_version}")
//modLocalRuntime("com.terraformersmc:modmenu:${project.modmenu_version}")

include api("io.wispforest:endec:0.1.5")
include api("io.wispforest.endec:netty:0.1.2")
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ emi_version=1.1.6+1.20.6
jankson_version=1.2.2

# https://maven.terraformersmc.com/releases/com/terraformersmc/modmenu
modmenu_version=11.0.0-rc.2
modmenu_version=12.0.0-alpha.1

# https://maven.nucleoid.xyz/xyz/nucleoid/server-translations-api/
stapi_version=2.3.1+1.21-pre2
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public boolean charTyped(char chr, int modifiers) {

@Override
public void render(DrawContext context, int mouseX, int mouseY, float partialTicks) {
ScissorStack.push(this.adapter.x(), this.adapter.y(), this.adapter.width(), this.adapter.height(), context.getMatrices());
ScissorStack.push(this.adapter.x(), this.adapter.y(), this.adapter.width(), this.adapter.height(), context);
this.adapter.render(context, mouseX, mouseY, partialTicks);
ScissorStack.pop();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,4 @@ private <T, U> Optional<U> addRecipeSpecificRemainders(Optional instance, Functi

return mappedValue;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
public interface DrawContextAccessor {

@Accessor("vertexConsumers")
VertexConsumerProvider.Immediate getVertexConsumers();
VertexConsumerProvider.Immediate owo$getVertexConsumers();
}
5 changes: 5 additions & 0 deletions src/main/java/io/wispforest/owo/shader/GlProgram.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.wispforest.owo.mixin.shader.ShaderProgramAccessor;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gl.*;
import net.minecraft.client.render.RenderPhase;
import net.minecraft.client.render.VertexFormat;
import net.minecraft.resource.ResourceFactory;
import net.minecraft.util.Identifier;
Expand Down Expand Up @@ -59,6 +60,10 @@ public GlProgram(Identifier id, VertexFormat vertexFormat) {
);
}

public RenderPhase.ShaderProgram renderPhaseProgram() {
return new RenderPhase.ShaderProgram(programKey);
}

/**
* Bind this program and execute
* potential preparation work
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ protected void mountChild(@Nullable Component child, Consumer<Component> layoutF
protected void drawChildren(OwoUIDrawContext context, int mouseX, int mouseY, float partialTicks, float delta, List<? extends Component> children) {
if (!this.allowOverflow) {
var padding = this.padding.get();
ScissorStack.push(this.x + padding.left(), this.y + padding.top(), this.width - padding.horizontal(), this.height - padding.vertical(), context.getMatrices());
ScissorStack.push(this.x + padding.left(), this.y + padding.top(), this.width - padding.horizontal(), this.height - padding.vertical(), context);
}

var focusHandler = this.focusHandler();
Expand All @@ -360,6 +360,8 @@ protected void drawChildren(OwoUIDrawContext context, int mouseX, int mouseY, fl
}

if (!this.allowOverflow) {
//context.getVertexConsumers().draw();

ScissorStack.pop();
}
}
Expand Down
177 changes: 76 additions & 101 deletions src/main/java/io/wispforest/owo/ui/core/OwoUIDrawContext.java

Large diffs are not rendered by default.

45 changes: 45 additions & 0 deletions src/main/java/io/wispforest/owo/ui/core/OwoUIRenderLayers.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package io.wispforest.owo.ui.core;

import com.mojang.blaze3d.systems.RenderSystem;
import io.wispforest.owo.client.OwoClient;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.RenderPhase;
import net.minecraft.client.render.VertexFormat;
import net.minecraft.client.render.VertexFormats;

import static net.minecraft.client.render.RenderPhase.*;

public class OwoUIRenderLayers {

public static final RenderLayer.MultiPhase GUI_TRIANGLE_FAN = RenderLayer.of(
"owo:gui_triangle_fan_default_blend",
VertexFormats.POSITION_COLOR,
VertexFormat.DrawMode.TRIANGLE_FAN,
786432,
RenderLayer.MultiPhaseParameters.builder().program(GUI_PROGRAM).transparency(TRANSLUCENT_TRANSPARENCY).depthTest(LEQUAL_DEPTH_TEST).build(false)
);

public static final RenderLayer.MultiPhase GUI_TRIANGLE_STRIP = RenderLayer.of(
"owo:gui_triangle_strip_default_blend",
VertexFormats.POSITION_COLOR,
VertexFormat.DrawMode.TRIANGLE_FAN,
786432,
RenderLayer.MultiPhaseParameters.builder().program(GUI_PROGRAM).transparency(TRANSLUCENT_TRANSPARENCY).depthTest(LEQUAL_DEPTH_TEST).build(false)
);

public static final RenderLayer.MultiPhase GUI_SPECTRUM = RenderLayer.of(
"owo:gui_spectrum",
VertexFormats.POSITION_COLOR,
VertexFormat.DrawMode.QUADS,
786432,
RenderLayer.MultiPhaseParameters.builder().program(OwoClient.HSV_PROGRAM.renderPhaseProgram()).depthTest(LEQUAL_DEPTH_TEST).build(false)
);

public static final RenderLayer.MultiPhase GUI_NO_DEPTH = RenderLayer.of(
"owo:gui_no_depth",
VertexFormats.POSITION_COLOR,
VertexFormat.DrawMode.QUADS,
786432,
RenderLayer.MultiPhaseParameters.builder().program(GUI_PROGRAM).transparency(TRANSLUCENT_TRANSPARENCY).build(false)
);
}
52 changes: 25 additions & 27 deletions src/main/java/io/wispforest/owo/ui/util/NinePatchTexture.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,46 +64,44 @@ public void draw(OwoUIDrawContext context, PositionedRectangle rectangle) {
}

public void draw(OwoUIDrawContext context, int x, int y, int width, int height) {
context.batchRenderLayer(this.texture, RenderLayer::getGuiTextured, layerFactory -> {
int rightEdge = this.cornerPatchSize().width() + this.centerPatchSize().width();
int bottomEdge = this.cornerPatchSize().height() + this.centerPatchSize().height();

context.drawTexture(RenderLayer::getGuiTextured, this.texture, x, y, this.u, this.v, this.cornerPatchSize().width(), this.cornerPatchSize().height(), this.textureSize.width(), this.textureSize.height());
context.drawTexture(RenderLayer::getGuiTextured, this.texture, x + width - this.cornerPatchSize().width(), y, this.u + rightEdge, this.v, this.cornerPatchSize().width(), this.cornerPatchSize().height(), this.textureSize.width(), this.textureSize.height());
context.drawTexture(RenderLayer::getGuiTextured, this.texture, x, y + height - this.cornerPatchSize().height(), this.u, this.v + bottomEdge, this.cornerPatchSize().width(), this.cornerPatchSize().height(), this.textureSize.width(), this.textureSize.height());
context.drawTexture(RenderLayer::getGuiTextured, this.texture, x + width - this.cornerPatchSize().width(), y + height - this.cornerPatchSize().height(), this.u + rightEdge, this.v + bottomEdge, this.cornerPatchSize().width(), this.cornerPatchSize().height(), this.textureSize.width(), this.textureSize.height());

if (this.repeat) {
this.drawRepeated(context, RenderLayer::getGuiTextured, x, y, width, height);
} else {
this.drawStretched(context, RenderLayer::getGuiTextured, x, y, width, height);
}
});
int rightEdge = this.cornerPatchSize().width() + this.centerPatchSize().width();
int bottomEdge = this.cornerPatchSize().height() + this.centerPatchSize().height();

context.drawTexture(RenderLayer::getGuiTextured, this.texture, x, y, this.u, this.v, this.cornerPatchSize().width(), this.cornerPatchSize().height(), this.textureSize.width(), this.textureSize.height());
context.drawTexture(RenderLayer::getGuiTextured, this.texture, x + width - this.cornerPatchSize().width(), y, this.u + rightEdge, this.v, this.cornerPatchSize().width(), this.cornerPatchSize().height(), this.textureSize.width(), this.textureSize.height());
context.drawTexture(RenderLayer::getGuiTextured, this.texture, x, y + height - this.cornerPatchSize().height(), this.u, this.v + bottomEdge, this.cornerPatchSize().width(), this.cornerPatchSize().height(), this.textureSize.width(), this.textureSize.height());
context.drawTexture(RenderLayer::getGuiTextured, this.texture, x + width - this.cornerPatchSize().width(), y + height - this.cornerPatchSize().height(), this.u + rightEdge, this.v + bottomEdge, this.cornerPatchSize().width(), this.cornerPatchSize().height(), this.textureSize.width(), this.textureSize.height());

if (this.repeat) {
this.drawRepeated(context, x, y, width, height);
} else {
this.drawStretched(context, x, y, width, height);
}
}

protected void drawStretched(OwoUIDrawContext context, Function<Identifier, RenderLayer> layerFactory, int x, int y, int width, int height) {
protected void drawStretched(OwoUIDrawContext context, int x, int y, int width, int height) {
int doubleCornerHeight = this.cornerPatchSize().height() * 2;
int doubleCornerWidth = this.cornerPatchSize().width() * 2;

int rightEdge = this.cornerPatchSize().width() + this.centerPatchSize().width();
int bottomEdge = this.cornerPatchSize().height() + this.centerPatchSize().height();

if (width > doubleCornerWidth && height > doubleCornerHeight) {
context.drawTexture(layerFactory, this.texture, x + this.cornerPatchSize().width(), y + this.cornerPatchSize().height(), this.u + this.cornerPatchSize().width(), this.v + this.cornerPatchSize().height(), width - doubleCornerWidth, height - doubleCornerHeight, this.centerPatchSize().width(), this.centerPatchSize().height(), this.textureSize.width(), this.textureSize.height());
context.drawTexture(RenderLayer::getGuiTextured, this.texture, x + this.cornerPatchSize().width(), y + this.cornerPatchSize().height(), this.u + this.cornerPatchSize().width(), this.v + this.cornerPatchSize().height(), width - doubleCornerWidth, height - doubleCornerHeight, this.centerPatchSize().width(), this.centerPatchSize().height(), this.textureSize.width(), this.textureSize.height());
}

if (width > doubleCornerWidth) {
context.drawTexture(layerFactory, this.texture, x + this.cornerPatchSize().width(), y, this.u + this.cornerPatchSize().width(), this.v, width - doubleCornerWidth, this.cornerPatchSize().height(), this.centerPatchSize().width(), this.cornerPatchSize().height(), this.textureSize.width(), this.textureSize.height());
context.drawTexture(layerFactory, this.texture, x + this.cornerPatchSize().width(), y + height - this.cornerPatchSize().height(), this.u + this.cornerPatchSize().width(), this.v + bottomEdge, width - doubleCornerWidth, this.cornerPatchSize().height(), this.centerPatchSize().width(), this.cornerPatchSize().height(), this.textureSize.width(), this.textureSize.height());
context.drawTexture(RenderLayer::getGuiTextured, this.texture, x + this.cornerPatchSize().width(), y, this.u + this.cornerPatchSize().width(), this.v, width - doubleCornerWidth, this.cornerPatchSize().height(), this.centerPatchSize().width(), this.cornerPatchSize().height(), this.textureSize.width(), this.textureSize.height());
context.drawTexture(RenderLayer::getGuiTextured, this.texture, x + this.cornerPatchSize().width(), y + height - this.cornerPatchSize().height(), this.u + this.cornerPatchSize().width(), this.v + bottomEdge, width - doubleCornerWidth, this.cornerPatchSize().height(), this.centerPatchSize().width(), this.cornerPatchSize().height(), this.textureSize.width(), this.textureSize.height());
}

if (height > doubleCornerHeight) {
context.drawTexture(layerFactory, this.texture, x, y + this.cornerPatchSize().height(), this.u, this.v + this.cornerPatchSize().height(), this.cornerPatchSize().width(), height - doubleCornerHeight, this.cornerPatchSize().width(), this.centerPatchSize().height(), this.textureSize.width(), this.textureSize.height());
context.drawTexture(layerFactory, this.texture, x + width - this.cornerPatchSize().width(), y + this.cornerPatchSize().height(), this.u + rightEdge, this.v + this.cornerPatchSize().height(), this.cornerPatchSize().width(), height - doubleCornerHeight, this.cornerPatchSize().width(), this.centerPatchSize().height(), this.textureSize.width(), this.textureSize.height());
context.drawTexture(RenderLayer::getGuiTextured, this.texture, x, y + this.cornerPatchSize().height(), this.u, this.v + this.cornerPatchSize().height(), this.cornerPatchSize().width(), height - doubleCornerHeight, this.cornerPatchSize().width(), this.centerPatchSize().height(), this.textureSize.width(), this.textureSize.height());
context.drawTexture(RenderLayer::getGuiTextured, this.texture, x + width - this.cornerPatchSize().width(), y + this.cornerPatchSize().height(), this.u + rightEdge, this.v + this.cornerPatchSize().height(), this.cornerPatchSize().width(), height - doubleCornerHeight, this.cornerPatchSize().width(), this.centerPatchSize().height(), this.textureSize.width(), this.textureSize.height());
}
}

protected void drawRepeated(OwoUIDrawContext context, Function<Identifier, RenderLayer> layerFactory, int x, int y, int width, int height) {
protected void drawRepeated(OwoUIDrawContext context, int x, int y, int width, int height) {
int doubleCornerHeight = this.cornerPatchSize().height() * 2;
int doubleCornerWidth = this.cornerPatchSize().width() * 2;

Expand All @@ -118,7 +116,7 @@ protected void drawRepeated(OwoUIDrawContext context, Function<Identifier, Rende
int leftoverWidth = width - doubleCornerWidth;
while (leftoverWidth > 0) {
int drawWidth = Math.min(this.centerPatchSize().width(), leftoverWidth);
context.drawTexture(layerFactory, this.texture, x + this.cornerPatchSize().width() + leftoverWidth - drawWidth, y + this.cornerPatchSize().height() + leftoverHeight - drawHeight, this.u + this.cornerPatchSize().width() + this.centerPatchSize().width() - drawWidth, this.v + this.cornerPatchSize().height() + this.centerPatchSize().height() - drawHeight, drawWidth, drawHeight, drawWidth, drawHeight, this.textureSize.width(), this.textureSize.height());
context.drawTexture(RenderLayer::getGuiTextured, this.texture, x + this.cornerPatchSize().width() + leftoverWidth - drawWidth, y + this.cornerPatchSize().height() + leftoverHeight - drawHeight, this.u + this.cornerPatchSize().width() + this.centerPatchSize().width() - drawWidth, this.v + this.cornerPatchSize().height() + this.centerPatchSize().height() - drawHeight, drawWidth, drawHeight, drawWidth, drawHeight, this.textureSize.width(), this.textureSize.height());

leftoverWidth -= this.centerPatchSize().width();
}
Expand All @@ -131,8 +129,8 @@ protected void drawRepeated(OwoUIDrawContext context, Function<Identifier, Rende
while (leftoverWidth > 0) {
int drawWidth = Math.min(this.centerPatchSize().width(), leftoverWidth);

context.drawTexture(layerFactory, this.texture, x + this.cornerPatchSize().width() + leftoverWidth - drawWidth, y, this.u + this.cornerPatchSize().width() + this.centerPatchSize().width() - drawWidth, this.v, drawWidth, this.cornerPatchSize().height(), drawWidth, this.cornerPatchSize().height(), this.textureSize.width(), this.textureSize.height());
context.drawTexture(layerFactory, this.texture, x + this.cornerPatchSize().width() + leftoverWidth - drawWidth, y + height - this.cornerPatchSize().height(), this.u + this.cornerPatchSize().width() + this.centerPatchSize().width() - drawWidth, this.v + bottomEdge, drawWidth, this.cornerPatchSize().height(), drawWidth, this.cornerPatchSize().height(), this.textureSize.width(), this.textureSize.height());
context.drawTexture(RenderLayer::getGuiTextured, this.texture, x + this.cornerPatchSize().width() + leftoverWidth - drawWidth, y, this.u + this.cornerPatchSize().width() + this.centerPatchSize().width() - drawWidth, this.v, drawWidth, this.cornerPatchSize().height(), drawWidth, this.cornerPatchSize().height(), this.textureSize.width(), this.textureSize.height());
context.drawTexture(RenderLayer::getGuiTextured, this.texture, x + this.cornerPatchSize().width() + leftoverWidth - drawWidth, y + height - this.cornerPatchSize().height(), this.u + this.cornerPatchSize().width() + this.centerPatchSize().width() - drawWidth, this.v + bottomEdge, drawWidth, this.cornerPatchSize().height(), drawWidth, this.cornerPatchSize().height(), this.textureSize.width(), this.textureSize.height());

leftoverWidth -= this.centerPatchSize().width();
}
Expand All @@ -142,8 +140,8 @@ protected void drawRepeated(OwoUIDrawContext context, Function<Identifier, Rende
int leftoverHeight = height - doubleCornerHeight;
while (leftoverHeight > 0) {
int drawHeight = Math.min(this.centerPatchSize().height(), leftoverHeight);
context.drawTexture(layerFactory, this.texture, x, y + this.cornerPatchSize().height() + leftoverHeight - drawHeight, this.u, this.v + this.cornerPatchSize().height() + this.centerPatchSize().height() - drawHeight, this.cornerPatchSize().width(), drawHeight, this.cornerPatchSize().width(), drawHeight, this.textureSize.width(), this.textureSize.height());
context.drawTexture(layerFactory, this.texture, x + width - this.cornerPatchSize().width(), y + this.cornerPatchSize().height() + leftoverHeight - drawHeight, this.u + rightEdge, this.v + this.cornerPatchSize().height() + this.centerPatchSize().height() - drawHeight, this.cornerPatchSize().width(), drawHeight, this.cornerPatchSize().width(), drawHeight, this.textureSize.width(), this.textureSize.height());
context.drawTexture(RenderLayer::getGuiTextured, this.texture, x, y + this.cornerPatchSize().height() + leftoverHeight - drawHeight, this.u, this.v + this.cornerPatchSize().height() + this.centerPatchSize().height() - drawHeight, this.cornerPatchSize().width(), drawHeight, this.cornerPatchSize().width(), drawHeight, this.textureSize.width(), this.textureSize.height());
context.drawTexture(RenderLayer::getGuiTextured, this.texture, x + width - this.cornerPatchSize().width(), y + this.cornerPatchSize().height() + leftoverHeight - drawHeight, this.u + rightEdge, this.v + this.cornerPatchSize().height() + this.centerPatchSize().height() - drawHeight, this.cornerPatchSize().width(), drawHeight, this.cornerPatchSize().width(), drawHeight, this.textureSize.width(), this.textureSize.height());

leftoverHeight -= this.centerPatchSize().height();
}
Expand Down
Loading

0 comments on commit 957906f

Please sign in to comment.