Skip to content

Commit 2f2ee0a

Browse files
committed
refactor render code to be easier to port
1 parent 61c62a2 commit 2f2ee0a

File tree

11 files changed

+324
-331
lines changed

11 files changed

+324
-331
lines changed

.editorconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ ij_java_case_statement_on_separate_line = true
7373
ij_java_catch_on_new_line = false
7474
ij_java_class_annotation_wrap = split_into_lines
7575
ij_java_class_brace_style = end_of_line
76-
ij_java_class_count_to_use_import_on_demand = 5
76+
ij_java_class_count_to_use_import_on_demand = 500
7777
ij_java_class_names_in_javadoc = 1
7878
ij_java_deconstruction_list_wrap = normal
7979
ij_java_do_not_indent_top_level_class_members = false
@@ -148,7 +148,7 @@ ij_java_method_parameters_right_paren_on_new_line = false
148148
ij_java_method_parameters_wrap = off
149149
ij_java_modifier_list_wrap = false
150150
ij_java_multi_catch_types_wrap = normal
151-
ij_java_names_count_to_use_import_on_demand = 3
151+
ij_java_names_count_to_use_import_on_demand = 300
152152
ij_java_new_line_after_lparen_in_annotation = false
153153
ij_java_new_line_after_lparen_in_deconstruction_pattern = true
154154
ij_java_new_line_after_lparen_in_record_header = false

src/main/java/com/cleanroommc/modularui/api/IMuiScreen.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
import com.cleanroommc.modularui.core.mixin.GuiContainerAccessor;
44
import com.cleanroommc.modularui.screen.ClientScreenHandler;
55
import com.cleanroommc.modularui.screen.ModularScreen;
6-
76
import com.cleanroommc.modularui.screen.viewport.ModularGuiContext;
7+
import com.cleanroommc.modularui.utils.Platform;
8+
89
import net.minecraft.client.gui.GuiScreen;
910
import net.minecraft.client.gui.inventory.GuiContainer;
1011
import net.minecraft.inventory.Slot;
11-
1212
import net.minecraftforge.fml.relauncher.Side;
1313
import net.minecraftforge.fml.relauncher.SideOnly;
1414

@@ -60,6 +60,10 @@ default void handleDrawBackground(int tint, IntConsumer drawFunction) {
6060
drawFunction.accept(tint);
6161
}
6262
ClientScreenHandler.drawDarkBackground(getGuiScreen(), tint);
63+
// after this JEI will draw itself
64+
// for some reason JEI is too stupid to set up opengl properly
65+
// without this (enableTexture2D() specifically) every item in JEI will be texture less (white)
66+
Platform.setupDrawTex();
6367
}
6468

6569
/**

src/main/java/com/cleanroommc/modularui/drawable/GuiDraw.java

Lines changed: 185 additions & 301 deletions
Large diffs are not rendered by default.

src/main/java/com/cleanroommc/modularui/drawable/Stencil.java

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22

33
import com.cleanroommc.modularui.api.layout.IViewportStack;
44
import com.cleanroommc.modularui.screen.viewport.GuiContext;
5+
import com.cleanroommc.modularui.utils.Platform;
56
import com.cleanroommc.modularui.widget.sizer.Area;
67

7-
import net.minecraft.client.renderer.BufferBuilder;
88
import net.minecraft.client.renderer.GlStateManager;
9-
import net.minecraft.client.renderer.Tessellator;
10-
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
119

1210
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
1311
import org.jetbrains.annotations.Nullable;
@@ -118,21 +116,14 @@ private static void setStencilValue(Runnable stencilShape, int stencilValue, boo
118116
}
119117

120118
private static void drawRectangleStencilShape(int x, int y, int w, int h) {
121-
GlStateManager.disableTexture2D();
122-
GlStateManager.disableAlpha();
123-
GlStateManager.enableBlend();
124-
Tessellator tessellator = Tessellator.getInstance();
125-
BufferBuilder bufferbuilder = tessellator.getBuffer();
126-
float x0 = x, x1 = x + w, y0 = y, y1 = y + h;
127-
bufferbuilder.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION);
128-
bufferbuilder.pos(x0, y0, 0.0f).endVertex();
129-
bufferbuilder.pos(x0, y1, 0.0f).endVertex();
130-
bufferbuilder.pos(x1, y1, 0.0f).endVertex();
131-
bufferbuilder.pos(x1, y0, 0.0f).endVertex();
132-
tessellator.draw();
133-
GlStateManager.disableBlend();
134-
GlStateManager.enableAlpha();
135-
GlStateManager.enableTexture2D();
119+
Platform.setupDrawColor();
120+
Platform.startDrawing(Platform.DrawMode.QUADS, Platform.VertexFormat.POS, bufferBuilder -> {
121+
float x0 = x, x1 = x + w, y0 = y, y1 = y + h;
122+
bufferBuilder.pos(x0, y0, 0.0f).endVertex();
123+
bufferBuilder.pos(x0, y1, 0.0f).endVertex();
124+
bufferBuilder.pos(x1, y1, 0.0f).endVertex();
125+
bufferBuilder.pos(x1, y0, 0.0f).endVertex();
126+
});
136127
}
137128

138129
/**

src/main/java/com/cleanroommc/modularui/drawable/text/ComposedLine.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.cleanroommc.modularui.api.drawable.IIcon;
66
import com.cleanroommc.modularui.api.drawable.ITextLine;
77
import com.cleanroommc.modularui.screen.viewport.GuiContext;
8+
import com.cleanroommc.modularui.utils.Platform;
89

910
import net.minecraft.client.gui.FontRenderer;
1011

@@ -41,6 +42,7 @@ public void draw(GuiContext context, FontRenderer fr, float x, float y, int colo
4142
for (Object o : this.elements) {
4243
if (o instanceof String s) {
4344
float drawY = getHeight(fr) / 2f - fr.FONT_HEIGHT / 2f;
45+
Platform.setupDrawFont();
4446
fr.drawString(s, x, (int) (y + drawY), color, shadow);
4547
x += fr.getStringWidth(s);
4648
} else if (o instanceof IIcon icon) {

src/main/java/com/cleanroommc/modularui/drawable/text/TextLine.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.cleanroommc.modularui.api.drawable.ITextLine;
44
import com.cleanroommc.modularui.screen.viewport.GuiContext;
5+
import com.cleanroommc.modularui.utils.Platform;
56

67
import net.minecraft.client.gui.FontRenderer;
78

@@ -29,6 +30,7 @@ public int getHeight(FontRenderer fr) {
2930

3031
@Override
3132
public void draw(GuiContext context, FontRenderer fr, float x, float y, int color, boolean shadow) {
33+
Platform.setupDrawFont();
3234
fr.drawString(this.text, x, y, color, shadow);
3335
this.lastX = x;
3436
this.lastY = y;

src/main/java/com/cleanroommc/modularui/drawable/text/TextRenderer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.cleanroommc.modularui.drawable.Stencil;
55
import com.cleanroommc.modularui.screen.viewport.GuiContext;
66
import com.cleanroommc.modularui.utils.Alignment;
7+
import com.cleanroommc.modularui.utils.Platform;
78
import com.cleanroommc.modularui.widget.sizer.Area;
89

910
import net.minecraft.client.Minecraft;
@@ -237,12 +238,11 @@ protected int getStartX(float maxWidth, float lineWidth) {
237238

238239
protected void draw(String text, float x, float y) {
239240
if (this.simulate) return;
240-
GlStateManager.disableBlend();
241+
Platform.setupDrawFont();
241242
GlStateManager.pushMatrix();
242243
GlStateManager.scale(this.scale, this.scale, 0f);
243244
getFontRenderer().drawString(text, x / this.scale, y / this.scale, this.color, this.shadow);
244245
GlStateManager.popMatrix();
245-
GlStateManager.enableBlend();
246246
}
247247

248248
public int getColor() {

src/main/java/com/cleanroommc/modularui/overlay/OverlayStack.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import com.cleanroommc.modularui.screen.ModularScreen;
66

77
import net.minecraft.client.renderer.GlStateManager;
8-
import net.minecraft.client.renderer.RenderHelper;
98

109
import org.jetbrains.annotations.ApiStatus;
1110
import org.jetbrains.annotations.Nullable;
@@ -65,10 +64,6 @@ public static void draw(int mouseX, int mouseY, float partialTicks) {
6564
fallback = screen;
6665
}
6766
ClientScreenHandler.drawDebugScreen(hovered, fallback);
68-
GlStateManager.enableLighting();
69-
GlStateManager.enableDepth();
70-
GlStateManager.enableRescaleNormal();
71-
RenderHelper.enableStandardItemLighting();
7267
}
7368

7469
public static void open(ModularScreen screen) {

src/main/java/com/cleanroommc/modularui/screen/ClientScreenHandler.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.cleanroommc.modularui.utils.Animator;
2020
import com.cleanroommc.modularui.utils.Color;
2121
import com.cleanroommc.modularui.utils.FpsCounter;
22+
import com.cleanroommc.modularui.utils.Platform;
2223
import com.cleanroommc.modularui.widget.sizer.Area;
2324
import com.cleanroommc.modularui.widgets.RichTextWidget;
2425
import com.cleanroommc.modularui.widgets.slot.ItemSlot;
@@ -159,7 +160,7 @@ public static void onGuiDraw(GuiScreenEvent.DrawScreenEvent.Pre event) {
159160
}
160161
}
161162

162-
@SubscribeEvent
163+
@SubscribeEvent(priority = EventPriority.HIGH)
163164
public static void onGuiDraw(GuiScreenEvent.DrawScreenEvent.Post event) {
164165
OverlayStack.draw(event.getMouseX(), event.getMouseY(), event.getRenderPartialTicks());
165166
}
@@ -344,6 +345,11 @@ public static void drawScreen(ModularScreen muiScreen, GuiScreen mcScreen, int m
344345
public static void drawScreenInternal(ModularScreen muiScreen, GuiScreen mcScreen, int mouseX, int mouseY, float partialTicks) {
345346
Stencil.reset();
346347
Stencil.apply(muiScreen.getScreenArea(), null);
348+
Platform.setupDrawTex();
349+
GlStateManager.enableLighting();
350+
GlStateManager.enableDepth();
351+
GlStateManager.enableRescaleNormal();
352+
RenderHelper.enableStandardItemLighting();
347353
muiScreen.drawScreen();
348354
GlStateManager.disableLighting();
349355
GlStateManager.disableDepth();
@@ -365,6 +371,7 @@ public static void drawContainer(ModularScreen muiScreen, GuiContainer mcScreen,
365371

366372
Stencil.reset();
367373
Stencil.apply(muiScreen.getScreenArea(), null);
374+
Platform.setupDrawTex();
368375
mcScreen.drawDefaultBackground();
369376
int x = mcScreen.getGuiLeft();
370377
int y = mcScreen.getGuiTop();

src/main/java/com/cleanroommc/modularui/test/TestTile.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,8 @@ public ModularPanel openSecondWindow(PanelSyncManager syncManager, IPanelHandler
369369
.setDraggable(true)
370370
.size(100, 100);
371371
SlotGroup slotGroup = new SlotGroup("small_inv", 2);
372+
IntSyncValue timeSync = new IntSyncValue(() -> (int)java.lang.System.currentTimeMillis(), val -> {java.lang.System.out.println(val);});
373+
syncManager.syncValue(123456,timeSync);
372374
syncManager.registerSlotGroup(slotGroup);
373375
AtomicInteger number = new AtomicInteger(0);
374376
syncManager.syncValue("int_value", new IntSyncValue(number::get, number::set));

0 commit comments

Comments
 (0)