Initial fixes for 1.20.2

This commit is contained in:
DBotThePony 2023-10-11 17:40:21 +07:00
parent d841a5fe1a
commit aa513343a5
Signed by: DBot
GPG Key ID: DCC23B5715498507
5 changed files with 20 additions and 12 deletions

View File

@ -1,5 +1,6 @@
package ru.dbotthepony.mc.otm.mixin; package ru.dbotthepony.mc.otm.mixin;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.GuiGraphics;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Overwrite;
@ -13,7 +14,8 @@ import static ru.dbotthepony.mc.otm.client.render.RenderHelperKt.pushScissorRect
public abstract class GuiGraphicsMixin { public abstract class GuiGraphicsMixin {
@Overwrite @Overwrite
public void enableScissor(int x0, int y0, int x1, int y1) { 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 @Overwrite

View File

@ -6,6 +6,7 @@ import net.minecraft.nbt.DoubleTag
import net.minecraft.nbt.ListTag import net.minecraft.nbt.ListTag
import net.minecraft.nbt.Tag import net.minecraft.nbt.Tag
import net.minecraft.server.level.ServerLevel import net.minecraft.server.level.ServerLevel
import net.minecraft.util.datafix.DataFixTypes
import net.minecraft.world.level.BlockGetter import net.minecraft.world.level.BlockGetter
import net.minecraft.world.level.Explosion import net.minecraft.world.level.Explosion
import net.minecraft.world.level.ExplosionDamageCalculator import net.minecraft.world.level.ExplosionDamageCalculator
@ -671,7 +672,7 @@ class ExplosionQueue(private val level: ServerLevel) : SavedData() {
val factory = ExplosionQueue(level) val factory = ExplosionQueue(level)
factory.load(it) factory.load(it)
factory factory
}, TODO()), }, DataFixTypes.LEVEL),
"otm_blackhole_explosion_queue" "otm_blackhole_explosion_queue"
) )
} }

View File

@ -290,7 +290,7 @@ fun GuiGraphics.drawLine(
drawLine(pose().last().pose(), startX, startY, endX, endY, width, z, color) 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 { fun withinBounds(x: Int, y: Int): Boolean {
return (x in this.x .. this.x + width) && (y in this.y .. this.y + height) 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<ScissorRect>() private val scissorStack = ArrayDeque<ScissorRect>()
@Suppress("NAME_SHADOWING") @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 x = x
var y = y var y = y
var width = width var width = width
@ -339,6 +340,11 @@ fun pushScissorRect(x: Int, y: Int, width: Int, height: Int) {
val peek = scissorStack.lastOrNull() val peek = scissorStack.lastOrNull()
if (peek != null) { if (peek != null) {
if (peek.lock) {
scissorStack.add(peek)
return
}
x = x.coerceAtLeast(peek.x) x = x.coerceAtLeast(peek.x)
y = y.coerceAtLeast(peek.y) y = y.coerceAtLeast(peek.y)
width = width.coerceAtMost(peek.width) 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 y = minecraft.window.height - y - height
RenderSystem.enableScissor(x, y, width, height) RenderSystem.enableScissor(x, y, width, height)
} }

View File

@ -319,6 +319,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
// Обрезать отрисовку потомков? // Обрезать отрисовку потомков?
var scissor = false var scissor = false
var scissorLock = false
var scissorPadding = DockProperty.EMPTY var scissorPadding = DockProperty.EMPTY
var dock = Dock.NONE var dock = Dock.NONE
set(value) { set(value) {
@ -868,6 +869,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
((absoluteY + top) * scale).toInt(), ((absoluteY + top) * scale).toInt(),
((width - right - left) * scale).toInt() + 1, ((width - right - left) * scale).toInt() + 1,
((height - bottom - top) * scale).toInt() + 1, ((height - bottom - top) * scale).toInt() + 1,
scissorLock
) )
} }

View File

@ -132,6 +132,7 @@ class EntityRendererPanel<out S : Screen> @JvmOverloads constructor(
init { init {
dock = Dock.FILL dock = Dock.FILL
scissor = true scissor = true
scissorLock = true
} }
private val cosButton: EditablePanel<S>? private val cosButton: EditablePanel<S>?
@ -169,18 +170,14 @@ class EntityRendererPanel<out S : Screen> @JvmOverloads constructor(
return return
} }
val renderX = this.width.toInt() / 2
val renderY = (this.height * 0.9f).toInt()
InventoryScreen.renderEntityInInventoryFollowsMouse( InventoryScreen.renderEntityInInventoryFollowsMouse(
graphics, graphics,
renderX, 0, 0,
renderY,
this.width.toInt(), this.height.toInt(), this.width.toInt(), this.height.toInt(),
renderScale, renderScale,
0f, 0f,
absoluteX.toInt() + renderX - mouseX, mouseX - absoluteX.toInt(),
absoluteY + height * 0.15f - mouseY, mouseY - absoluteY + height * 0.15f,
entity entity
) )
} }