From ab7473db6c414b1e6c05a1ce6062ef50949be324 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Sat, 24 Sep 2022 18:09:37 +0700 Subject: [PATCH] Fix JEI flickering --- .../otm/client/screen/panels/EditablePanel.kt | 32 +++++++++++++++---- .../mc/otm/compat/jei/JEIPlugin.kt | 2 +- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/EditablePanel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/EditablePanel.kt index ddd56eacc..6b1ac035a 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/EditablePanel.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/EditablePanel.kt @@ -444,7 +444,7 @@ open class EditablePanel @JvmOverloads constructor( result.add(Rect2f(absoluteX, absoluteY, width, height)) for (children in children) { - if (children.isOutsideOfParent) { + if (children.isOutsideOfParent && children.isVisible()) { result.addAll(children.calculateAbsoluteRectangles()) } } @@ -557,16 +557,36 @@ open class EditablePanel @JvmOverloads constructor( return false } - fun render(poseStack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) { - if (!isVisible()) { - return - } - + fun performLayoutIfNeeded() { if (layoutInvalidated) { performLayout() } else if (boundsInvalidated) { updateBounds() } + } + + fun updateAbsoluteCoordinates() { + if (parent == null) { + absoluteX = x + absoluteY = y + } + + for (child in children) { + if (child.isVisible()) { + child.absoluteX = absoluteX + child.x + xOffset + child.absoluteY = absoluteY + child.y + yOffset + + child.updateAbsoluteCoordinates() + } + } + } + + fun render(poseStack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) { + if (!isVisible()) { + return + } + + performLayoutIfNeeded() val parent = this.parent diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/compat/jei/JEIPlugin.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/compat/jei/JEIPlugin.kt index 1498cbb6d..5402515d7 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/compat/jei/JEIPlugin.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/compat/jei/JEIPlugin.kt @@ -217,7 +217,7 @@ class JEIPlugin : IModPlugin { override fun registerGuiHandlers(registration: IGuiHandlerRegistration) { registration.addGenericGuiContainerHandler(MatteryScreen::class.java, object : IGuiContainerHandler> { override fun getGuiExtraAreas(containerScreen: MatteryScreen<*>): MutableList { - return containerScreen.panelsView.stream().map { it.calculateAbsoluteRectangles() }.flatMap { it.stream() }.map { it.toIntRect() }.collect(Collectors.toList()) + return containerScreen.panelsView.stream().map { it.performLayoutIfNeeded(); it.updateAbsoluteCoordinates(); it.calculateAbsoluteRectangles() }.flatMap { it.stream() }.map { it.toIntRect() }.collect(Collectors.toList()) } override fun getIngredientUnderMouse(