From aa513343a5e01da80a137a4040e16effce0a664d Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Wed, 11 Oct 2023 17:40:21 +0700 Subject: [PATCH] Initial fixes for 1.20.2 --- .../dbotthepony/mc/otm/mixin/GuiGraphicsMixin.java | 4 +++- .../mc/otm/block/entity/blackhole/Explosions.kt | 3 ++- .../dbotthepony/mc/otm/client/render/RenderHelper.kt | 12 +++++++++--- .../mc/otm/client/screen/panels/EditablePanel.kt | 2 ++ .../otm/client/screen/panels/EntityRendererPanel.kt | 11 ++++------- 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/main/java/ru/dbotthepony/mc/otm/mixin/GuiGraphicsMixin.java b/src/main/java/ru/dbotthepony/mc/otm/mixin/GuiGraphicsMixin.java index 92ab70446..21986c504 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/mixin/GuiGraphicsMixin.java +++ b/src/main/java/ru/dbotthepony/mc/otm/mixin/GuiGraphicsMixin.java @@ -1,5 +1,6 @@ package ru.dbotthepony.mc.otm.mixin; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; @@ -13,7 +14,8 @@ import static ru.dbotthepony.mc.otm.client.render.RenderHelperKt.pushScissorRect public abstract class GuiGraphicsMixin { @Overwrite public void enableScissor(int x0, int y0, int x1, int y1) { - pushScissorRect(x0, y0, x1 - x0, y1 - y0); + double scale = Minecraft.getInstance().getWindow().getGuiScale(); + pushScissorRect((int) (scale * x0), (int) (scale * y0), (int) (scale * (x1 - x0)), (int) (scale * (y1 - y0))); } @Overwrite diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/blackhole/Explosions.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/blackhole/Explosions.kt index 44d9aa00e..ed6136dd2 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/blackhole/Explosions.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/blackhole/Explosions.kt @@ -6,6 +6,7 @@ import net.minecraft.nbt.DoubleTag import net.minecraft.nbt.ListTag import net.minecraft.nbt.Tag import net.minecraft.server.level.ServerLevel +import net.minecraft.util.datafix.DataFixTypes import net.minecraft.world.level.BlockGetter import net.minecraft.world.level.Explosion import net.minecraft.world.level.ExplosionDamageCalculator @@ -671,7 +672,7 @@ class ExplosionQueue(private val level: ServerLevel) : SavedData() { val factory = ExplosionQueue(level) factory.load(it) factory - }, TODO()), + }, DataFixTypes.LEVEL), "otm_blackhole_explosion_queue" ) } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/RenderHelper.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/RenderHelper.kt index b64a244e0..e693e19cf 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/RenderHelper.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/RenderHelper.kt @@ -290,7 +290,7 @@ fun GuiGraphics.drawLine( drawLine(pose().last().pose(), startX, startY, endX, endY, width, z, color) } -data class ScissorRect(val x: Int, val y: Int, val width: Int, val height: Int) { +data class ScissorRect(val x: Int, val y: Int, val width: Int, val height: Int, val lock: Boolean = false) { fun withinBounds(x: Int, y: Int): Boolean { return (x in this.x .. this.x + width) && (y in this.y .. this.y + height) } @@ -330,7 +330,8 @@ data class ScissorRect(val x: Int, val y: Int, val width: Int, val height: Int) private val scissorStack = ArrayDeque() @Suppress("NAME_SHADOWING") -fun pushScissorRect(x: Int, y: Int, width: Int, height: Int) { +@JvmOverloads +fun pushScissorRect(x: Int, y: Int, width: Int, height: Int, lock: Boolean = false) { var x = x var y = y var width = width @@ -339,6 +340,11 @@ fun pushScissorRect(x: Int, y: Int, width: Int, height: Int) { val peek = scissorStack.lastOrNull() if (peek != null) { + if (peek.lock) { + scissorStack.add(peek) + return + } + x = x.coerceAtLeast(peek.x) y = y.coerceAtLeast(peek.y) width = width.coerceAtMost(peek.width) @@ -350,7 +356,7 @@ fun pushScissorRect(x: Int, y: Int, width: Int, height: Int) { } } - scissorStack.add(ScissorRect(x, y, width, height)) + scissorStack.add(ScissorRect(x, y, width, height, lock)) y = minecraft.window.height - y - height RenderSystem.enableScissor(x, y, width, height) } 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 ca4f83484..f47b2a27c 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 @@ -319,6 +319,7 @@ open class EditablePanel @JvmOverloads constructor( // Обрезать отрисовку потомков? var scissor = false + var scissorLock = false var scissorPadding = DockProperty.EMPTY var dock = Dock.NONE set(value) { @@ -868,6 +869,7 @@ open class EditablePanel @JvmOverloads constructor( ((absoluteY + top) * scale).toInt(), ((width - right - left) * scale).toInt() + 1, ((height - bottom - top) * scale).toInt() + 1, + scissorLock ) } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/EntityRendererPanel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/EntityRendererPanel.kt index a5da55b6c..10f1dd8e8 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/EntityRendererPanel.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/EntityRendererPanel.kt @@ -132,6 +132,7 @@ class EntityRendererPanel @JvmOverloads constructor( init { dock = Dock.FILL scissor = true + scissorLock = true } private val cosButton: EditablePanel? @@ -169,18 +170,14 @@ class EntityRendererPanel @JvmOverloads constructor( return } - val renderX = this.width.toInt() / 2 - val renderY = (this.height * 0.9f).toInt() - InventoryScreen.renderEntityInInventoryFollowsMouse( graphics, - renderX, - renderY, + 0, 0, this.width.toInt(), this.height.toInt(), renderScale, 0f, - absoluteX.toInt() + renderX - mouseX, - absoluteY + height * 0.15f - mouseY, + mouseX - absoluteX.toInt(), + mouseY - absoluteY + height * 0.15f, entity ) }