Skip to content

Commit 9bc7ebe

Browse files
committed
Make it actually compile and launch the game, needs more work to move away from OpenGL-specific APIs
1 parent a30cdbf commit 9bc7ebe

9 files changed

Lines changed: 70 additions & 76 deletions

File tree

worldeditcui-fabric/src/main/java/org/enginehub/worldeditcui/event/listeners/CUIListenerWorldRender.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010
package org.enginehub.worldeditcui.event.listeners;
1111

1212
import com.mojang.blaze3d.buffers.GpuBufferSlice;
13-
import com.mojang.blaze3d.opengl.GlConst;
1413
import com.mojang.blaze3d.opengl.GlStateManager;
15-
import com.mojang.blaze3d.platform.DestFactor;
16-
import com.mojang.blaze3d.platform.SourceFactor;
1714
import com.mojang.blaze3d.systems.RenderSystem;
1815
import net.minecraft.client.Minecraft;
1916
import net.minecraft.client.renderer.fog.FogRenderer;
@@ -104,15 +101,9 @@ public void onRender(final float partialTicks) {
104101
RenderSystem.setShaderFog(this.minecraft.gameRenderer.fogRenderer.getBuffer(FogRenderer.FogMode.NONE));
105102
final Matrix4fStack poseStack = RenderSystem.getModelViewStack();
106103
poseStack.pushMatrix();
107-
GlStateManager._disableCull();
108104
GlStateManager._enableBlend();
109105
// RenderSystem.disableTexture();
110106
GlStateManager._enableDepthTest();
111-
GlStateManager._blendFuncSeparate(
112-
GlConst.toGl(SourceFactor.SRC_ALPHA),
113-
GlConst.toGl(DestFactor.ONE_MINUS_SRC_ALPHA),
114-
GlConst.toGl(SourceFactor.SRC_ALPHA),
115-
GlConst.toGl(DestFactor.ONE_MINUS_SRC_ALPHA));
116107
GlStateManager._depthMask(true);
117108
BufferBuilderRenderSink.LineWidth.set(LineStyle.DEFAULT_WIDTH);
118109

@@ -127,7 +118,6 @@ public void onRender(final float partialTicks) {
127118
GlStateManager._depthFunc(GL32.GL_LEQUAL);
128119
// RenderSystem.enableTexture();
129120
GlStateManager._disableBlend();
130-
GlStateManager._enableCull();
131121
poseStack.popMatrix();
132122
RenderSystem.setShaderFog(fogStart);
133123
profiler.pop();

worldeditcui-fabric/src/main/java/org/enginehub/worldeditcui/fabric/FabricModWorldEditCUI.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
1616
import net.fabricmc.fabric.api.client.keymapping.v1.KeyMappingHelper;
1717
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
18-
import net.fabricmc.fabric.api.client.rendering.v1.world.WorldRenderContext;
19-
import net.fabricmc.fabric.api.client.rendering.v1.world.WorldRenderEvents;
18+
import net.fabricmc.fabric.api.client.rendering.v1.level.LevelExtractionContext;
19+
import net.fabricmc.fabric.api.client.rendering.v1.level.LevelRenderContext;
20+
import net.fabricmc.fabric.api.client.rendering.v1.level.LevelRenderEvents;
2021
import net.fabricmc.fabric.api.networking.v1.PacketSender;
2122
import net.minecraft.client.KeyMapping;
2223
import net.minecraft.client.Minecraft;
@@ -98,15 +99,15 @@ public void onInitialize() {
9899
ClientLifecycleEvents.CLIENT_STARTED.register(this::onGameInitDone);
99100
CUINetworking.subscribeToCuiPacket(this::onPluginMessage);
100101
ClientPlayConnectionEvents.JOIN.register(this::onJoinGame);
101-
WorldRenderEvents.END_EXTRACTION.register(ctx -> {
102+
LevelRenderEvents.END_EXTRACTION.register(ctx -> {
102103
// MC now handles this separately to the actual render, due to it occurring across threads.
103104
// We need to store this for later use during actual render.
104-
lastPartialTicks = ctx.tickCounter().getRealtimeDeltaTicks();
105+
this.onEndExtraction(ctx);
105106
});
106-
WorldRenderEvents.END_MAIN.register(ctx -> {
107+
LevelRenderEvents.END_MAIN.register(ctx -> {
107108
try {
108109
RenderSystem.getModelViewStack().pushMatrix();
109-
RenderSystem.getModelViewStack().mul(ctx.matrices().last().pose());
110+
RenderSystem.getModelViewStack().mul(ctx.poseStack().last().pose());
110111
// RenderSystem.applyModelViewMatrix();
111112
this.onPostRenderEntities(ctx);
112113
} finally {
@@ -185,7 +186,11 @@ public void onJoinGame(final ClientPacketListener handler, final PacketSender se
185186
this.helo(handler);
186187
}
187188

188-
public void onPostRenderEntities(final WorldRenderContext ctx) {
189+
private void onEndExtraction(final LevelExtractionContext ctx) {
190+
this.lastPartialTicks = ctx.deltaTracker().getRealtimeDeltaTicks();
191+
}
192+
193+
public void onPostRenderEntities(final LevelRenderContext ctx) {
189194
if (this.visible) {
190195
this.worldRenderListener.onRender(lastPartialTicks);
191196
}

worldeditcui-fabric/src/main/java/org/enginehub/worldeditcui/gui/CUIConfigList.java

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import com.mojang.logging.LogUtils;
1414
import net.minecraft.ChatFormatting;
1515
import net.minecraft.client.Minecraft;
16-
import net.minecraft.client.gui.GuiGraphics;
16+
import net.minecraft.client.gui.GuiGraphicsExtractor;
1717
import net.minecraft.client.gui.components.Button;
1818
import net.minecraft.client.gui.components.ContainerObjectSelectionList;
1919
import net.minecraft.client.gui.components.CycleButton;
@@ -104,26 +104,33 @@ protected void updateFromConfig() {
104104
}
105105

106106
@Override
107-
public void renderContent(GuiGraphics gfx, int mouseX, int mouseY, boolean isMouseOver, float partialTick) {
108-
super.renderContent(gfx, mouseX, mouseY, isMouseOver, partialTick);
107+
public void extractContent(GuiGraphicsExtractor gfx, int mouseX, int mouseY, boolean isMouseOver, float partialTick) {
108+
super.extractContent(gfx, mouseX, mouseY, isMouseOver, partialTick);
109109

110110
this.toggleBotton.setX(getRowLeft() + 105);
111111
this.toggleBotton.setY(getY());
112-
this.toggleBotton.render(gfx, mouseX, mouseY, partialTick);
112+
this.toggleBotton.extractRenderState(gfx, mouseX, mouseY, partialTick);
113113
}
114114
}
115115

116116
public class ColorConfigEntry extends ConfigEntry {
117117
private final EditBox textField;
118+
private String currentInput;
118119

119120
public ColorConfigEntry(String tag) {
120121
super(tag);
121122

122123
Colour cValue = (Colour)configuration.getConfigArray().get(tag);
123124
textField = new EditBox(CUIConfigList.this.minecraft.font, 0, 0, BUTTON_WIDTH, BUTTON_HEIGHT, Component.literal(cValue.hexString()));
124125
textField.setMaxLength(9); // # + 8 hex chars
125-
textField.setValue(cValue.hexString());
126+
this.currentInput = cValue.hexString();
127+
textField.setValue(this.currentInput);
126128
textField.setResponder(updated -> {
129+
if (!isAcceptableColorInput(updated)) {
130+
textField.setValue(this.currentInput);
131+
return;
132+
}
133+
this.currentInput = updated;
127134
Colour tested = Colour.parseRgbaOrNull(updated);
128135
if (tested != null) {
129136
configuration.changeValue(tag, tested);
@@ -139,21 +146,22 @@ public ColorConfigEntry(String tag) {
139146
.result()
140147
.orElseGet(() -> FormattedCharSequence.forward(string, invalidFormat));
141148
});
142-
textField.setFilter(value -> {
143-
// filter for #AARRGGBB
144-
if (!value.isEmpty() && value.charAt(0) != '#') { // does not start with hex
145-
return false;
146-
}
149+
}
147150

148-
for (int i = 1; i < value.length(); i++) { // any characters that are not valid in a hex string
149-
final char c = value.charAt(i);
150-
if ((c < '0' || c > '9') && (c < 'A' || c > 'F') && (c < 'a' || c > 'f')) {
151-
return false;
152-
}
151+
private boolean isAcceptableColorInput(final String value) {
152+
// filter for #AARRGGBB
153+
if (!value.isEmpty() && value.charAt(0) != '#') { // does not start with hex
154+
return false;
155+
}
156+
157+
for (int i = 1; i < value.length(); i++) { // any characters that are not valid in a hex string
158+
final char c = value.charAt(i);
159+
if ((c < '0' || c > '9') && (c < 'A' || c > 'F') && (c < 'a' || c > 'f')) {
160+
return false;
153161
}
162+
}
154163

155-
return true;
156-
});
164+
return true;
157165
}
158166

159167
@Override
@@ -168,15 +176,16 @@ public ColorConfigEntry(String tag) {
168176

169177
@Override
170178
protected void updateFromConfig() {
171-
this.textField.setValue(((Colour)configuration.getConfigArray().get(tag)).hexString());
179+
this.currentInput = ((Colour)configuration.getConfigArray().get(tag)).hexString();
180+
this.textField.setValue(this.currentInput);
172181
}
173182

174183
@Override
175-
public void renderContent(GuiGraphics gfx, int mouseX, int mouseY, boolean isMouseOver, float partialTick) {
176-
super.renderContent(gfx, mouseX, mouseY, isMouseOver, partialTick);
184+
public void extractContent(GuiGraphicsExtractor gfx, int mouseX, int mouseY, boolean isMouseOver, float partialTick) {
185+
super.extractContent(gfx, mouseX, mouseY, isMouseOver, partialTick);
177186
this.textField.setX(getRowLeft() + 105);
178187
this.textField.setY(getY());
179-
this.textField.render(gfx, mouseX, mouseY, partialTick);
188+
this.textField.extractRenderState(gfx, mouseX, mouseY, partialTick);
180189
}
181190
}
182191

@@ -203,7 +212,7 @@ public ConfigEntry(String tag) {
203212
}
204213

205214
@Override
206-
public void renderContent(GuiGraphics gfx, int mouseX, int mouseY, boolean hovered, float partialTick) {
215+
public void extractContent(GuiGraphicsExtractor gfx, int mouseX, int mouseY, boolean hovered, float partialTick) {
207216
// new API handles entry position internally
208217
int left = this.getX();
209218
int top = this.getY(); // or getRowTop()
@@ -212,11 +221,11 @@ public void renderContent(GuiGraphics gfx, int mouseX, int mouseY, boolean hover
212221

213222
this.textField.setX(textLeft);
214223
this.textField.setY(top);
215-
this.textField.render(gfx, mouseX, mouseY, partialTick);
224+
this.textField.extractRenderState(gfx, mouseX, mouseY, partialTick);
216225

217226
this.resetButton.setX(left + 190);
218227
this.resetButton.setY(top);
219-
this.resetButton.render(gfx, mouseX, mouseY, partialTick);
228+
this.resetButton.extractRenderState(gfx, mouseX, mouseY, partialTick);
220229
}
221230

222231
protected abstract void updateFromConfig();

worldeditcui-fabric/src/main/java/org/enginehub/worldeditcui/gui/CUIConfigPanel.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
*/
1010
package org.enginehub.worldeditcui.gui;
1111

12-
import net.minecraft.client.gui.GuiGraphics;
13-
import net.minecraft.client.gui.components.AbstractWidget;
12+
import net.minecraft.client.gui.GuiGraphicsExtractor;
1413
import net.minecraft.client.gui.components.Button;
1514
import net.minecraft.client.gui.screens.Screen;
1615
import net.minecraft.network.chat.CommonComponents;
@@ -27,7 +26,6 @@ public class CUIConfigPanel extends Screen {
2726

2827
private final Screen parent;
2928
final CUIConfiguration configuration;
30-
private AbstractWidget done;
3129
private CUIConfigList configList;
3230
private final Component screenTitle;
3331

@@ -42,23 +40,19 @@ public CUIConfigPanel(Screen parent, CUIConfiguration configuration) {
4240
protected void init() {
4341
super.init();
4442

45-
done = this.addWidget(Button.builder(CommonComponents.GUI_DONE, (button) -> {
43+
this.addRenderableWidget(Button.builder(CommonComponents.GUI_DONE, (button) -> {
4644
configuration.configChanged();
4745
assert minecraft != null;
4846
this.minecraft.setScreen(parent);
4947
}).bounds((this.width - BUTTON_DONE_WIDTH) / 2, this.height - (BUTTON_HEIGHT + 7), BUTTON_DONE_WIDTH, BUTTON_HEIGHT).build());
5048

5149
this.configList = CUIConfigList.create(this, this.minecraft);
52-
this.addWidget(this.configList);
50+
this.addRenderableWidget(this.configList);
5351
}
5452

5553
@Override
56-
public void render(GuiGraphics gfx, int mouseX, int mouseY, float delta) {
57-
super.render(gfx, mouseX, mouseY, delta);
58-
59-
this.configList.render(gfx, mouseX, mouseY, delta);
60-
gfx.drawCenteredString(this.font, screenTitle, this.width / 2, 8, 0xFFFFFF);
61-
62-
this.done.render(gfx, mouseX, mouseY, delta);
54+
public void extractRenderState(GuiGraphicsExtractor gfx, int mouseX, int mouseY, float delta) {
55+
super.extractRenderState(gfx, mouseX, mouseY, delta);
56+
gfx.centeredText(this.font, screenTitle, this.width / 2, 8, 0xFFFFFF);
6357
}
6458
}

worldeditcui-fabric/src/main/java/org/enginehub/worldeditcui/render/BufferBuilderRenderSink.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
*/
1010
package org.enginehub.worldeditcui.render;
1111

12+
import com.mojang.blaze3d.opengl.GlConst;
1213
import com.mojang.blaze3d.opengl.GlStateManager;
1314
import com.mojang.blaze3d.vertex.BufferBuilder;
1415
import com.mojang.blaze3d.vertex.Tesselator;
1516
import com.mojang.blaze3d.vertex.VertexFormat;
1617
import org.jetbrains.annotations.Nullable;
1718
import org.joml.Vector3f;
19+
import com.mojang.blaze3d.platform.CompareOp;
1820
import org.lwjgl.opengl.GL11;
1921
import org.lwjgl.opengl.GL32;
2022

@@ -38,7 +40,7 @@ public class BufferBuilderRenderSink implements RenderSink {
3840

3941
// line state
4042
private float lastLineWidth = -1;
41-
private int lastDepthFunc = -1;
43+
private @Nullable CompareOp lastDepthTest;
4244

4345
public BufferBuilderRenderSink(final TypeFactory types) {
4446
this(types, () -> {}, () -> {});
@@ -79,14 +81,14 @@ public RenderSink color(final float r, final float g, final float b, final float
7981
public boolean apply(final LineStyle line, final RenderStyle.RenderType type) {
8082
if (line.renderType.matches(type))
8183
{
82-
if (line.lineWidth != this.lastLineWidth || line.renderType.depthFunc() != this.lastDepthFunc) {
84+
if (line.lineWidth != this.lastLineWidth || line.renderType.depthTest() != this.lastDepthTest) {
8385
this.flush();
8486
if (this.active && this.activeRenderType != null) {
8587
this.canFlush = true;
8688
this.builder = Tesselator.getInstance().begin(this.activeRenderType.mode, this.activeRenderType.format);
8789
}
8890
LineWidth.set(this.lastLineWidth = line.lineWidth);
89-
GlStateManager._depthFunc(this.lastDepthFunc = line.renderType.depthFunc());
91+
GlStateManager._depthFunc(GlConst.toGl(this.lastDepthTest = line.renderType.depthTest()));
9092
}
9193
return true;
9294
}

worldeditcui-fabric/src/main/java/org/enginehub/worldeditcui/render/RenderStyle.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
*/
1010
package org.enginehub.worldeditcui.render;
1111

12+
import com.mojang.blaze3d.platform.CompareOp;
1213
import org.enginehub.worldeditcui.config.Colour;
13-
import org.lwjgl.opengl.GL32;
1414

1515
/**
1616
* Render style adapter, can be one of the built-in {@link ConfiguredColour}s
@@ -28,28 +28,28 @@ public enum RenderType
2828
/**
2929
* Render type to draw lines regardless of depth
3030
*/
31-
ANY(GL32.GL_ALWAYS),
31+
ANY(CompareOp.ALWAYS_PASS),
3232

3333
/**
3434
* Render type for "hidden" lines (under world geometry)
3535
*/
36-
HIDDEN(GL32.GL_GEQUAL),
36+
HIDDEN(CompareOp.GREATER_THAN_OR_EQUAL),
3737

3838
/**
3939
* Render type for visible lines (over world geometry)
4040
*/
41-
VISIBLE(GL32.GL_LESS);
41+
VISIBLE(CompareOp.LESS_THAN);
4242

43-
final int depthFunc;
43+
final CompareOp depthTest;
4444

45-
private RenderType(int depthFunc)
45+
private RenderType(final CompareOp depthTest)
4646
{
47-
this.depthFunc = depthFunc;
47+
this.depthTest = depthTest;
4848
}
4949

50-
public int depthFunc()
50+
public CompareOp depthTest()
5151
{
52-
return this.depthFunc;
52+
return this.depthTest;
5353
}
5454

5555
public boolean matches(RenderType other)
@@ -67,4 +67,4 @@ public boolean matches(RenderType other)
6767
public abstract Colour getColour();
6868

6969
public abstract LineStyle[] getLines();
70-
}
70+
}

worldeditcui-fabric/src/main/java/org/enginehub/worldeditcui/render/VanillaPipelineProvider.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
package org.enginehub.worldeditcui.render;
1111

1212
import com.mojang.blaze3d.pipeline.BlendFunction;
13+
import com.mojang.blaze3d.pipeline.ColorTargetState;
1314
import com.mojang.blaze3d.pipeline.RenderPipeline;
1415
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
1516
import com.mojang.blaze3d.vertex.VertexFormat;
@@ -26,7 +27,7 @@ public static class DefaultTypeFactory implements BufferBuilderRenderSink.TypeFa
2627
RenderPipeline.builder(RenderPipeline.builder(RenderPipelines.MATRICES_PROJECTION_SNIPPET)
2728
.withVertexShader("core/position_color")
2829
.withFragmentShader("core/position_color")
29-
.withBlend(BlendFunction.TRANSLUCENT)
30+
.withColorTargetState(new ColorTargetState(BlendFunction.TRANSLUCENT))
3031
.withVertexFormat(DefaultVertexFormat.POSITION_COLOR, VertexFormat.Mode.QUADS)
3132
.buildSnippet())
3233
.withLocation("pipeline/wecui_quads").withCull(false).build()

worldeditcui-fabric/src/main/java/org/enginehub/worldeditcui/render/shapes/Render3DGrid.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
*/
1010
package org.enginehub.worldeditcui.render.shapes;
1111

12-
import com.mojang.blaze3d.opengl.GlStateManager;
13-
import com.mojang.blaze3d.systems.RenderSystem;
1412
import net.minecraft.util.Mth;
1513
import org.enginehub.worldeditcui.event.listeners.CUIRenderContext;
1614
import org.enginehub.worldeditcui.render.LineStyle;
@@ -88,8 +86,6 @@ public void render(CUIRenderContext ctx)
8886

8987
if (this.spacing != 1.0)
9088
{
91-
GlStateManager._disableCull();
92-
9389
double[] vertices = {
9490
x1, y1, z1, x2, y1, z1, x2, y1, z2, x1, y1, z2, // bottom
9591
x1, y2, z1, x2, y2, z1, x2, y2, z2, x1, y2, z2, // top
@@ -112,9 +108,6 @@ public void render(CUIRenderContext ctx)
112108
ctx.endQuads();
113109
}
114110
}
115-
116-
ctx.flush(); // todo: only needed because of disable/enable cull
117-
GlStateManager._enableCull();
118111
}
119112

120113
if (this.spacing < Render3DGrid.MIN_SPACING)

0 commit comments

Comments
 (0)