forked from CleanroomMC/ModularUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClientScreenHandler.java
More file actions
565 lines (507 loc) · 24.1 KB
/
ClientScreenHandler.java
File metadata and controls
565 lines (507 loc) · 24.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
package com.cleanroommc.modularui.screen;
import com.cleanroommc.modularui.ModularUI;
import com.cleanroommc.modularui.ModularUIConfig;
import com.cleanroommc.modularui.api.IMuiScreen;
import com.cleanroommc.modularui.api.MCHelper;
import com.cleanroommc.modularui.api.widget.IGuiElement;
import com.cleanroommc.modularui.api.widget.IVanillaSlot;
import com.cleanroommc.modularui.core.mixin.GuiAccessor;
import com.cleanroommc.modularui.core.mixin.GuiContainerAccessor;
import com.cleanroommc.modularui.core.mixin.GuiScreenAccessor;
import com.cleanroommc.modularui.drawable.GuiDraw;
import com.cleanroommc.modularui.drawable.Stencil;
import com.cleanroommc.modularui.overlay.OverlayStack;
import com.cleanroommc.modularui.screen.viewport.GuiContext;
import com.cleanroommc.modularui.screen.viewport.LocatedWidget;
import com.cleanroommc.modularui.screen.viewport.ModularGuiContext;
import com.cleanroommc.modularui.utils.Animator;
import com.cleanroommc.modularui.utils.Color;
import com.cleanroommc.modularui.utils.FpsCounter;
import com.cleanroommc.modularui.widget.sizer.Area;
import com.cleanroommc.modularui.widgets.ItemSlot;
import com.cleanroommc.modularui.widgets.RichTextWidget;
import com.cleanroommc.modularui.widgets.slot.ModularSlot;
import com.cleanroommc.modularui.widgets.slot.SlotGroup;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiLabel;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.client.event.GuiContainerEvent;
import net.minecraftforge.client.event.GuiOpenEvent;
import net.minecraftforge.client.event.GuiScreenEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.jetbrains.annotations.Nullable;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import java.awt.*;
import java.io.IOException;
import java.util.Objects;
import java.util.function.Predicate;
@SideOnly(Side.CLIENT)
public class ClientScreenHandler {
private static final GuiContext defaultContext = new GuiContext();
private static ModularScreen currentScreen = null;
private static Character lastChar = null;
private static final FpsCounter fpsCounter = new FpsCounter();
private static long ticks = 0L;
@SubscribeEvent
public static void onGuiOpen(GuiOpenEvent event) {
defaultContext.reset();
if (event.getGui() instanceof IMuiScreen muiScreen) {
Objects.requireNonNull(muiScreen.getScreen(), "ModularScreen must not be null!");
if (currentScreen != muiScreen.getScreen()) {
if (hasScreen()) {
currentScreen.onCloseParent();
currentScreen = null;
lastChar = null;
}
currentScreen = muiScreen.getScreen();
fpsCounter.reset();
}
} else if (hasScreen() && getMCScreen() != null && event.getGui() != getMCScreen()) {
currentScreen.onCloseParent();
currentScreen = null;
lastChar = null;
}
}
@SubscribeEvent
public static void onGuiInit(GuiScreenEvent.InitGuiEvent.Post event) {
defaultContext.updateScreenArea(event.getGui().width, event.getGui().height);
if (checkGui(event.getGui())) {
currentScreen.onResize(event.getGui().width, event.getGui().height);
}
OverlayStack.foreach(ms -> ms.onResize(event.getGui().width, event.getGui().height), false);
}
@SubscribeEvent(priority = EventPriority.HIGH)
public static void onGuiInputLow(GuiScreenEvent.KeyboardInputEvent.Pre event) throws IOException {
defaultContext.updateEventState();
if (checkGui(event.getGui())) currentScreen.getContext().updateEventState();
if (handleKeyboardInput(currentScreen, event.getGui())) {
event.setCanceled(true);
}
}
@SubscribeEvent(priority = EventPriority.HIGH)
public static void onGuiInputLow(GuiScreenEvent.MouseInputEvent.Pre event) throws IOException {
defaultContext.updateEventState();
if (checkGui(event.getGui())) currentScreen.getContext().updateEventState();
if (handleMouseInput(Mouse.getEventButton(), currentScreen, event.getGui())) {
event.setCanceled(true);
return;
}
int w = Mouse.getEventDWheel();
if (w == 0) return;
ModularScreen.UpOrDown upOrDown = w > 0 ? ModularScreen.UpOrDown.UP : ModularScreen.UpOrDown.DOWN;
checkGui(event.getGui());
if (doAction(currentScreen, ms -> ms.onMouseScroll(upOrDown, Math.abs(w)))) {
event.setCanceled(true);
}
}
@SubscribeEvent(priority = EventPriority.LOW)
public static void onGuiDraw(GuiScreenEvent.DrawScreenEvent.Pre event) {
int mx = event.getMouseX(), my = event.getMouseY();
float pt = event.getRenderPartialTicks();
defaultContext.updateState(mx, my, pt);
defaultContext.reset();
if (checkGui(event.getGui())) {
currentScreen.getContext().updateState(mx, my, pt);
drawScreen(currentScreen, currentScreen.getScreenWrapper().getGuiScreen(), mx, my, pt);
event.setCanceled(true);
}
}
@SubscribeEvent
public static void onGuiDraw(GuiScreenEvent.DrawScreenEvent.Post event) {
OverlayStack.draw(event.getMouseX(), event.getMouseY(), event.getRenderPartialTicks());
}
@SubscribeEvent
public static void onTick(TickEvent.ClientTickEvent event) {
if (event.phase == TickEvent.Phase.START) {
OverlayStack.onTick();
defaultContext.tick();
if (checkGui()) {
currentScreen.onUpdate();
}
ticks++;
}
}
@SubscribeEvent
public static void preDraw(TickEvent.RenderTickEvent event) {
if (event.phase == TickEvent.Phase.START) {
GL11.glEnable(GL11.GL_STENCIL_TEST);
}
Stencil.reset();
}
public static long getTicks() {
return ticks;
}
public static void onFrameUpdate() {
OverlayStack.foreach(ModularScreen::onFrameUpdate, true);
if (currentScreen != null) currentScreen.onFrameUpdate();
Animator.advance();
}
private static boolean doAction(@Nullable ModularScreen muiScreen, Predicate<ModularScreen> action) {
return OverlayStack.interact(action, true) || (muiScreen != null && action.test(muiScreen));
}
private static boolean handleMouseInput(int button, @Nullable ModularScreen muiScreen, GuiScreen mcScreen) throws IOException {
GameSettings gameSettings = Minecraft.getMinecraft().gameSettings;
GuiScreenAccessor acc = (GuiScreenAccessor) mcScreen;
if (Mouse.getEventButtonState()) {
if (gameSettings.touchscreen) {
int val = acc.getTouchValue();
if (val > 0) {
// we will cancel the event now, so we have to set the value
// otherwise the screen will handle it
acc.setTouchValue(val + 1);
return true;
}
}
acc.setEventButton(button);
acc.setLastMouseEvent(Minecraft.getSystemTime());
return doAction(muiScreen, ms -> ms.onMousePressed(button));
}
if (button != -1) {
if (gameSettings.touchscreen) {
int val = acc.getTouchValue();
if (val - 1 > 0) {
// we will cancel the event now, so we have to set the value
// otherwise the screen will handle it
acc.setTouchValue(val - 1);
return true;
}
}
acc.setEventButton(-1);
return doAction(muiScreen, ms -> ms.onMouseRelease(button));
}
if (acc.getEventButton() != -1 && acc.getLastMouseEvent() > 0L) {
long l = Minecraft.getSystemTime() - acc.getLastMouseEvent();
return doAction(muiScreen, ms -> ms.onMouseDrag(acc.getEventButton(), l));
}
return false;
}
/**
* This replicates vanilla behavior while also injecting custom behavior for consistency
*/
private static boolean handleKeyboardInput(@Nullable ModularScreen muiScreen, GuiScreen mcScreen) throws IOException {
char c0 = Keyboard.getEventCharacter();
int key = Keyboard.getEventKey();
boolean state = Keyboard.getEventKeyState();
if (state) {
// pressing a key
lastChar = c0;
return doAction(muiScreen, ms -> ms.onKeyPressed(c0, key)) || keyTyped(mcScreen, c0, key);
} else {
// releasing a key
// for some reason when you press E after joining a world the button will not trigger the press event,
// but ony the release event, causing this to be null
if (lastChar == null) return false;
// when the key is released, the event char is empty
if (doAction(muiScreen, ms -> ms.onKeyRelease(lastChar, key))) return true;
if (key == 0 && c0 >= ' ') {
return keyTyped(mcScreen, c0, key);
}
}
return false;
}
private static boolean keyTyped(GuiScreen screen, char typedChar, int keyCode) throws IOException {
if (currentScreen == null) return false;
// debug mode C + CTRL + SHIFT + ALT
if (keyCode == 46 && GuiScreen.isCtrlKeyDown() && GuiScreen.isShiftKeyDown() && GuiScreen.isAltKeyDown()) {
ModularUIConfig.guiDebugMode = !ModularUIConfig.guiDebugMode;
return true;
}
if (keyCode == 1 || Minecraft.getMinecraft().gameSettings.keyBindInventory.isActiveAndMatches(keyCode)) {
if (currentScreen.getContext().hasDraggable()) {
currentScreen.getContext().dropDraggable();
} else {
currentScreen.getPanelManager().closeTopPanel(true);
}
return true;
}
return false;
}
public static void dragSlot(long timeSinceLastClick) {
if (hasScreen() && getMCScreen() instanceof GuiScreenAccessor container) {
ModularGuiContext ctx = currentScreen.getContext();
container.invokeMouseClickMove(ctx.getAbsMouseX(), ctx.getAbsMouseY(), ctx.getMouseButton(), timeSinceLastClick);
}
}
public static void clickSlot() {
if (hasScreen() && getMCScreen() instanceof GuiScreenAccessor screen) {
ModularGuiContext ctx = currentScreen.getContext();
try {
screen.invokeMouseClicked(ctx.getAbsMouseX(), ctx.getMouseY(), ctx.getMouseButton());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
public static void releaseSlot() {
if (hasScreen() && getMCScreen() instanceof GuiScreenAccessor screen) {
ModularGuiContext ctx = currentScreen.getContext();
screen.invokeMouseReleased(ctx.getAbsMouseX(), ctx.getAbsMouseY(), ctx.getMouseButton());
}
}
public static boolean shouldDrawWorldBackground() {
return ModularUI.isBlurLoaded() || Minecraft.getMinecraft().world == null;
}
public static void drawDarkBackground(GuiScreen screen, int tint) {
if (hasScreen()) {
float alpha = currentScreen.getMainPanel().getAlpha();
// vanilla color values as hex
int color = 0x101010;
int startAlpha = 0xc0;
int endAlpha = 0xd0;
GuiDraw.drawVerticalGradientRect(0, 0, screen.width, screen.height, Color.withAlpha(color, (int) (startAlpha * alpha)), Color.withAlpha(color, (int) (endAlpha * alpha)));
}
}
public static void drawScreen(ModularScreen muiScreen, GuiScreen mcScreen, int mouseX, int mouseY, float partialTicks) {
if (mcScreen instanceof GuiContainer container) {
drawContainer(muiScreen, container, mouseX, mouseY, partialTicks);
} else {
drawScreenInternal(muiScreen, mcScreen, mouseX, mouseY, partialTicks);
}
}
public static void drawScreenInternal(ModularScreen muiScreen, GuiScreen mcScreen, int mouseX, int mouseY, float partialTicks) {
Stencil.reset();
Stencil.apply(muiScreen.getScreenArea(), null);
muiScreen.drawScreen(mouseX, mouseY, partialTicks);
GlStateManager.disableLighting();
GlStateManager.disableDepth();
drawVanillaElements(mcScreen, mouseX, mouseY, partialTicks);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
GlStateManager.enableRescaleNormal();
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240.0F, 240.0F);
RenderHelper.disableStandardItemLighting();
muiScreen.drawForeground(partialTicks);
GlStateManager.enableLighting();
GlStateManager.enableDepth();
GlStateManager.enableRescaleNormal();
RenderHelper.enableStandardItemLighting();
Stencil.remove();
}
public static void drawContainer(ModularScreen muiScreen, GuiContainer mcScreen, int mouseX, int mouseY, float partialTicks) {
GuiContainerAccessor acc = (GuiContainerAccessor) mcScreen;
Stencil.reset();
Stencil.apply(muiScreen.getScreenArea(), null);
mcScreen.drawDefaultBackground();
int x = mcScreen.getGuiLeft();
int y = mcScreen.getGuiTop();
acc.invokeDrawGuiContainerBackgroundLayer(partialTicks, mouseX, mouseY);
muiScreen.drawScreen(mouseX, mouseY, partialTicks);
GlStateManager.disableLighting();
GlStateManager.disableDepth();
// mainly for invtweaks compat
drawVanillaElements(mcScreen, mouseX, mouseY, partialTicks);
GlStateManager.pushMatrix();
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
GlStateManager.enableRescaleNormal();
acc.setHoveredSlot(null);
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240.0F, 240.0F);
GlStateManager.enableRescaleNormal();
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
RenderHelper.disableStandardItemLighting();
acc.invokeDrawGuiContainerForegroundLayer(mouseX, mouseY);
muiScreen.drawForeground(partialTicks);
RenderHelper.enableGUIStandardItemLighting();
acc.setHoveredSlot(null);
IGuiElement hovered = muiScreen.getContext().getHovered();
if (hovered instanceof IVanillaSlot vanillaSlot) {
acc.setHoveredSlot(vanillaSlot.getVanillaSlot());
}
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
GlStateManager.pushMatrix();
GlStateManager.translate(x, y, 0);
MinecraftForge.EVENT_BUS.post(new GuiContainerEvent.DrawForeground(mcScreen, mouseX, mouseY));
GlStateManager.popMatrix();
InventoryPlayer inventoryplayer = Minecraft.getMinecraft().player.inventory;
ItemStack itemstack = acc.getDraggedStack().isEmpty() ? inventoryplayer.getItemStack() : acc.getDraggedStack();
GlStateManager.translate((float) x, (float) y, 0.0F);
if (!itemstack.isEmpty()) {
int k2 = acc.getDraggedStack().isEmpty() ? 8 : 16;
String s = null;
if (!acc.getDraggedStack().isEmpty() && acc.getIsRightMouseClick()) {
itemstack = itemstack.copy();
itemstack.setCount(MathHelper.ceil((float) itemstack.getCount() / 2.0F));
} else if (acc.getDragSplitting() && acc.getDragSplittingSlots().size() > 1) {
itemstack = itemstack.copy();
itemstack.setCount(acc.getDragSplittingRemnant());
if (itemstack.isEmpty()) {
s = TextFormatting.YELLOW + "0";
}
}
drawItemStack(mcScreen, itemstack, mouseX - x - 8, mouseY - y - k2, s);
}
if (!acc.getReturningStack().isEmpty()) {
float f = (float) (Minecraft.getSystemTime() - acc.getReturningStackTime()) / 100.0F;
if (f >= 1.0F) {
f = 1.0F;
acc.setReturningStack(ItemStack.EMPTY);
}
int l2 = acc.getReturningStackDestSlot().xPos - acc.getTouchUpX();
int i3 = acc.getReturningStackDestSlot().yPos - acc.getTouchUpY();
int l1 = acc.getTouchUpX() + (int) ((float) l2 * f);
int i2 = acc.getTouchUpY() + (int) ((float) i3 * f);
drawItemStack(mcScreen, acc.getReturningStack(), l1, i2, null);
}
GlStateManager.popMatrix();
GlStateManager.enableLighting();
GlStateManager.enableDepth();
GlStateManager.enableRescaleNormal();
RenderHelper.enableStandardItemLighting();
Stencil.remove();
}
private static void drawItemStack(GuiContainer mcScreen, ItemStack stack, int x, int y, String altText) {
GlStateManager.translate(0.0F, 0.0F, 32.0F);
((GuiAccessor) mcScreen).setZLevel(200f);
((GuiScreenAccessor) mcScreen).getItemRender().zLevel = 200.0F;
FontRenderer font = stack.getItem().getFontRenderer(stack);
if (font == null) font = ((GuiScreenAccessor) mcScreen).getFontRenderer();
GlStateManager.enableDepth();
((GuiScreenAccessor) mcScreen).getItemRender().renderItemAndEffectIntoGUI(stack, x, y);
((GuiScreenAccessor) mcScreen).getItemRender().renderItemOverlayIntoGUI(font, stack, x, y - (((GuiContainerAccessor) mcScreen).getDraggedStack().isEmpty() ? 0 : 8), altText);
GlStateManager.disableDepth();
((GuiAccessor) mcScreen).setZLevel(0f);
((GuiScreenAccessor) mcScreen).getItemRender().zLevel = 0.0F;
}
private static void drawVanillaElements(GuiScreen mcScreen, int mouseX, int mouseY, float partialTicks) {
for (GuiButton guiButton : ((GuiScreenAccessor) mcScreen).getButtonList()) {
guiButton.drawButton(Minecraft.getMinecraft(), mouseX, mouseY, partialTicks);
}
for (GuiLabel guiLabel : ((GuiScreenAccessor) mcScreen).getLabelList()) {
guiLabel.drawLabel(Minecraft.getMinecraft(), mouseX, mouseY);
}
}
public static void drawDebugScreen(@Nullable ModularScreen muiScreen, @Nullable ModularScreen fallback) {
fpsCounter.onDraw();
if (!ModularUIConfig.guiDebugMode) return;
if (muiScreen == null) {
if (checkGui()) {
muiScreen = currentScreen;
} else {
if (fallback == null) return;
muiScreen = fallback;
}
}
GlStateManager.disableDepth();
GlStateManager.disableLighting();
GlStateManager.enableBlend();
ModularGuiContext context = muiScreen.getContext();
int mouseX = context.getAbsMouseX(), mouseY = context.getAbsMouseY();
int screenH = muiScreen.getScreenArea().height;
int color = Color.argb(180, 40, 115, 220);
int lineY = screenH - 13;
Minecraft.getMinecraft().fontRenderer.drawStringWithShadow("Mouse Pos: " + mouseX + ", " + mouseY, 5, lineY, color);
lineY -= 11;
Minecraft.getMinecraft().fontRenderer.drawStringWithShadow("FPS: " + fpsCounter.getFps(), 5, screenH - 24, color);
LocatedWidget locatedHovered = muiScreen.getPanelManager().getTopWidgetLocated(true);
if (locatedHovered != null) {
drawSegmentLine(lineY -= 4, color);
lineY -= 10;
IGuiElement hovered = locatedHovered.getElement();
locatedHovered.applyMatrix(context);
GlStateManager.pushMatrix();
context.applyToOpenGl();
Area area = hovered.getArea();
IGuiElement parent = hovered.getParent();
GuiDraw.drawBorder(0, 0, area.width, area.height, color, 1f);
if (hovered.hasParent()) {
GuiDraw.drawBorder(-area.rx, -area.ry, parent.getArea().width, parent.getArea().height, Color.withAlpha(color, 0.3f), 1f);
}
GlStateManager.popMatrix();
locatedHovered.unapplyMatrix(context);
GuiDraw.drawText("Pos: " + area.x + ", " + area.y + " Rel: " + area.rx + ", " + area.ry, 5, lineY, 1, color, false);
lineY -= 11;
GuiDraw.drawText("Size: " + area.width + ", " + area.height, 5, lineY, 1, color, false);
lineY -= 11;
GuiDraw.drawText("Class: " + hovered, 5, lineY, 1, color, false);
if (hovered.hasParent()) {
drawSegmentLine(lineY -= 4, color);
lineY -= 10;
area = parent.getArea();
GuiDraw.drawText("Parent size: " + area.width + ", " + area.height, 5, lineY, 1, color, false);
lineY -= 11;
GuiDraw.drawText("Parent: " + parent, 5, lineY, 1, color, false);
}
if (hovered instanceof ItemSlot slotWidget) {
drawSegmentLine(lineY -= 4, color);
lineY -= 10;
ModularSlot slot = slotWidget.getSlot();
GuiDraw.drawText("Slot Index: " + slot.getSlotIndex(), 5, lineY, 1, color, false);
lineY -= 11;
GuiDraw.drawText("Slot Number: " + slot.slotNumber, 5, lineY, 1, color, false);
lineY -= 11;
if (slotWidget.isSynced()) {
SlotGroup slotGroup = slot.getSlotGroup();
boolean allowShiftTransfer = slotGroup != null && slotGroup.allowShiftTransfer();
GuiDraw.drawText("Shift-Click Priority: " + (allowShiftTransfer ? slotGroup.getShiftClickPriority() : "DISABLED"), 5, lineY, 1, color, false);
}
} else if(hovered instanceof RichTextWidget richTextWidget) {
drawSegmentLine(lineY -= 4, color);
lineY -= 10;
Object hoveredElement = richTextWidget.getHoveredElement();
GuiDraw.drawText("Hovered: " + hoveredElement, 5, lineY, 1, color, false);
}
}
// dot at mouse pos
GuiDraw.drawRect(mouseX, mouseY, 1, 1, Color.withAlpha(Color.GREEN.main, 0.8f));
GlStateManager.color(1f, 1f, 1f, 1f);
}
private static void drawSegmentLine(int y, int color) {
GuiDraw.drawRect(5, y, 140, 1, color);
}
public static void updateGuiArea(GuiContainer container, Rectangle area) {
GuiContainerAccessor acc = (GuiContainerAccessor) container;
acc.setGuiLeft(area.x);
acc.setGuiTop(area.y);
acc.setXSize(area.width);
acc.setYSize(area.height);
}
public static boolean hasScreen() {
return currentScreen != null;
}
@Nullable
public static GuiScreen getMCScreen() {
return MCHelper.getCurrentScreen();
}
@Nullable
public static ModularScreen getMuiScreen() {
return currentScreen;
}
private static boolean checkGui() {
return MCHelper.hasMc() && checkGui(Minecraft.getMinecraft().currentScreen);
}
private static boolean checkGui(GuiScreen screen) {
if (!MCHelper.hasMc() || currentScreen == null || !(screen instanceof IMuiScreen muiScreen)) return false;
if (screen != Minecraft.getMinecraft().currentScreen || muiScreen.getScreen() != currentScreen) {
defaultContext.reset();
currentScreen = null;
lastChar = null;
return false;
}
return true;
}
public static GuiContext getDefaultContext() {
return defaultContext;
}
public static GuiContext getBestContext() {
if (checkGui()) {
return currentScreen.getContext();
}
return defaultContext;
}
}