Some 1.20 portings

This commit is contained in:
DBotThePony 2023-06-08 13:51:04 +07:00
parent 817630cb79
commit 8a0cfaa90d
Signed by: DBot
GPG Key ID: DCC23B5715498507
7 changed files with 108 additions and 67 deletions

View File

@ -3,6 +3,7 @@ package ru.dbotthepony.mc.otm.client.render
import com.google.common.collect.ImmutableList import com.google.common.collect.ImmutableList
import com.mojang.blaze3d.vertex.BufferBuilder import com.mojang.blaze3d.vertex.BufferBuilder
import com.mojang.blaze3d.vertex.VertexConsumer import com.mojang.blaze3d.vertex.VertexConsumer
import com.mojang.blaze3d.vertex.VertexSorting
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap
import it.unimi.dsi.fastutil.objects.ReferenceArraySet import it.unimi.dsi.fastutil.objects.ReferenceArraySet
import net.minecraft.client.renderer.MultiBufferSource import net.minecraft.client.renderer.MultiBufferSource
@ -62,7 +63,7 @@ private fun equals(existing: ImmutableList<RenderType>?, types: ImmutableList<Re
* *
* Allows to batch OTM's geometry * Allows to batch OTM's geometry
*/ */
class DynamicBufferSource(val minimalInitialBufferSize: Int = 0, val maximalInitialBufferSize: Int = Int.MAX_VALUE) : MultiBufferSource { class DynamicBufferSource(val minimalInitialBufferSize: Int = 0, val maximalInitialBufferSize: Int = Int.MAX_VALUE, val vertexSorting: VertexSorting = VertexSorting.DISTANCE_TO_ORIGIN) : MultiBufferSource {
init { init {
require(minimalInitialBufferSize >= 0) { "Invalid minimal buffer size $minimalInitialBufferSize" } require(minimalInitialBufferSize >= 0) { "Invalid minimal buffer size $minimalInitialBufferSize" }
require(maximalInitialBufferSize >= minimalInitialBufferSize) { "Maximal buffer size $maximalInitialBufferSize must be greater or equal to minimal buffer size $minimalInitialBufferSize" } require(maximalInitialBufferSize >= minimalInitialBufferSize) { "Maximal buffer size $maximalInitialBufferSize must be greater or equal to minimal buffer size $minimalInitialBufferSize" }
@ -142,13 +143,6 @@ class DynamicBufferSource(val minimalInitialBufferSize: Int = 0, val maximalInit
it.add(next) it.add(next)
next = State(RenderType.waterMask(), ImmutableList.of(next.type), true, false) next = State(RenderType.waterMask(), ImmutableList.of(next.type), true, false)
it.add(next) it.add(next)
// TODO
// it.add(State(AtlasMatterySprite.renderTypeDepth, ImmutableList.of(RenderType.waterMask()), true))
// TODO
// it.add(State(AtlasMatterySprite.renderTypeNoDepth, ImmutableList.of(RenderType.waterMask()), true))
// TODO
// it.add(State(AtlasMatterySprite.renderTypeWorld, ImmutableList.of(Sheets.signSheet()), true))
} }
private fun determineHeight(input: State, seen: MutableSet<State>) { private fun determineHeight(input: State, seen: MutableSet<State>) {
@ -356,7 +350,7 @@ class DynamicBufferSource(val minimalInitialBufferSize: Int = 0, val maximalInit
for (state in bufferList) { for (state in bufferList) {
if (state.dirty) { if (state.dirty) {
state.dirty = false state.dirty = false
state.type.end(state.builder, 0, 0, 0) state.type.end(state.builder, vertexSorting)
} }
} }
} }
@ -366,7 +360,7 @@ class DynamicBufferSource(val minimalInitialBufferSize: Int = 0, val maximalInit
if (state.dirty) { if (state.dirty) {
state.dirty = false state.dirty = false
type.end(state.builder, 0, 0, 0) type.end(state.builder, vertexSorting)
} }
} }
@ -375,7 +369,7 @@ class DynamicBufferSource(val minimalInitialBufferSize: Int = 0, val maximalInit
if (state.dirty) { if (state.dirty) {
state.dirty = false state.dirty = false
type.end(state.builder, 0, 0, 0) type.end(state.builder, vertexSorting)
} }
for (ustate in state.dependants) { for (ustate in state.dependants) {
@ -386,7 +380,7 @@ class DynamicBufferSource(val minimalInitialBufferSize: Int = 0, val maximalInit
private fun endBatchChain(state: State) { private fun endBatchChain(state: State) {
if (state.dirty) { if (state.dirty) {
state.dirty = false state.dirty = false
state.type.end(state.builder, 0, 0, 0) state.type.end(state.builder, vertexSorting)
} }
for (ustate in state.dependants) { for (ustate in state.dependants) {
@ -395,7 +389,9 @@ class DynamicBufferSource(val minimalInitialBufferSize: Int = 0, val maximalInit
} }
companion object { companion object {
val GUI = DynamicBufferSource(maximalInitialBufferSize = 2 shl 8) @JvmField
val GUI = DynamicBufferSource(maximalInitialBufferSize = 2 shl 8, vertexSorting = VertexSorting.ORTHOGRAPHIC_Z)
@JvmField
val WORLD = DynamicBufferSource(minimalInitialBufferSize = 2 shl 12) val WORLD = DynamicBufferSource(minimalInitialBufferSize = 2 shl 12)
/** /**

View File

@ -4,6 +4,7 @@ import com.mojang.blaze3d.vertex.PoseStack
import com.mojang.blaze3d.vertex.Tesselator import com.mojang.blaze3d.vertex.Tesselator
import com.mojang.blaze3d.vertex.VertexConsumer import com.mojang.blaze3d.vertex.VertexConsumer
import net.minecraft.client.gui.Font import net.minecraft.client.gui.Font
import net.minecraft.client.gui.GuiGraphics
import net.minecraft.client.renderer.MultiBufferSource import net.minecraft.client.renderer.MultiBufferSource
import net.minecraft.core.Vec3i import net.minecraft.core.Vec3i
import net.minecraft.network.chat.Component import net.minecraft.network.chat.Component
@ -104,12 +105,7 @@ private fun Font.drawScaledDuckTyped(poseStack: PoseStack, buffer: MultiBufferSo
} }
private fun Font.drawDuckTyped(poseStack: PoseStack, text: Any, x: Float, y: Float, color: Int): Int { private fun Font.drawDuckTyped(poseStack: PoseStack, text: Any, x: Float, y: Float, color: Int): Int {
return when (text) { return drawDuckTyped(poseStack, DynamicBufferSource.GUI, text, x, y, color)
is Component -> draw(poseStack, text, x, y, color)
is String -> draw(poseStack, text, x, y, color)
is FormattedCharSequence -> draw(poseStack, text, x, y, color)
else -> throw ClassCastException(text::class.qualifiedName)
}
} }
private fun Font.drawDuckTyped( private fun Font.drawDuckTyped(
@ -240,6 +236,35 @@ private fun Font.drawScaledAlignedDuckTyped(
} }
} }
private fun GuiGraphics.drawScaledAlignedDuckTyped(
poseStack: PoseStack,
buffer: MultiBufferSource,
text: Any,
scale: Float,
align: TextAlign,
x: Float,
y: Float,
color: Int,
drawShadow: Boolean = false,
displayMode: Font.DisplayMode = Font.DisplayMode.NORMAL,
packedLightCoords: Int = 15728880,
effectColor: Int = 0
): Int {
return when (align) {
TextAlign.TOP_LEFT -> drawScaledDuckTyped(poseStack, buffer, text, scale, x, y, color, drawShadow, displayMode, packedLightCoords, effectColor)
TextAlign.TOP_CENTER -> drawScaledDuckTyped(poseStack, buffer, text, scale, (x - widthDuckTyped(text) * scale / 2f), y, color, drawShadow, displayMode, packedLightCoords, effectColor)
TextAlign.TOP_RIGHT -> drawScaledDuckTyped(poseStack, buffer, text, scale, (x - widthDuckTyped(text) * scale), y, color, drawShadow, displayMode, packedLightCoords, effectColor)
TextAlign.CENTER_LEFT -> drawScaledDuckTyped(poseStack, buffer, text, scale, x, (y - lineHeight / 2f * scale), color, drawShadow, displayMode, packedLightCoords, effectColor)
TextAlign.CENTER_CENTER -> drawScaledDuckTyped(poseStack, buffer, text, scale, (x - widthDuckTyped(text) * scale / 2f), (y - lineHeight * scale / 2f), color, drawShadow, displayMode, packedLightCoords, effectColor)
TextAlign.CENTER_RIGHT -> drawScaledDuckTyped(poseStack, buffer, text, scale, (x - widthDuckTyped(text) * scale), (y - lineHeight * scale / 2f), color, drawShadow, displayMode, packedLightCoords, effectColor)
TextAlign.BOTTOM_LEFT -> drawScaledDuckTyped(poseStack, buffer, text, scale, x, (y - lineHeight * scale), color, drawShadow, displayMode, packedLightCoords, effectColor)
TextAlign.BOTTOM_CENTER -> drawScaledDuckTyped(poseStack, buffer, text, scale, (x - widthDuckTyped(text) * scale / 2f), (y - lineHeight * scale), color, drawShadow, displayMode, packedLightCoords, effectColor)
TextAlign.BOTTOM_RIGHT -> drawScaledDuckTyped(poseStack, buffer, text, scale, (x - widthDuckTyped(text) * scale), (y - lineHeight * scale), color, drawShadow, displayMode, packedLightCoords, effectColor)
}
}
fun Font.drawAligned(poseStack: PoseStack, text: String, align: TextAlign, x: Float, y: Float, color: Int) = drawAlignedDuckTyped(poseStack, text, align, x, y, color) fun Font.drawAligned(poseStack: PoseStack, text: String, align: TextAlign, x: Float, y: Float, color: Int) = drawAlignedDuckTyped(poseStack, text, align, x, y, color)
fun Font.drawAligned(poseStack: PoseStack, text: Component, align: TextAlign, x: Float, y: Float, color: Int) = drawAlignedDuckTyped(poseStack, text, align, x, y, color) fun Font.drawAligned(poseStack: PoseStack, text: Component, align: TextAlign, x: Float, y: Float, color: Int) = drawAlignedDuckTyped(poseStack, text, align, x, y, color)
fun Font.drawAligned(poseStack: PoseStack, text: FormattedCharSequence, align: TextAlign, x: Float, y: Float, color: Int) = drawAlignedDuckTyped(poseStack, text, align, x, y, color) fun Font.drawAligned(poseStack: PoseStack, text: FormattedCharSequence, align: TextAlign, x: Float, y: Float, color: Int) = drawAlignedDuckTyped(poseStack, text, align, x, y, color)
@ -271,3 +296,19 @@ fun Font.drawScaledAligned(poseStack: PoseStack, buffer: MultiBufferSource, text
fun Font.drawScaledAligned(poseStack: PoseStack, buffer: MultiBufferSource, text: String, scale: Float, align: TextAlign, x: Float, y: Float, drawShadow: Boolean = false, displayMode: Font.DisplayMode = Font.DisplayMode.NORMAL, packedLightCoords: Int = 15728880, effectColor: Int = 0, color: RGBAColor) = drawScaledAligned(poseStack, buffer, text, scale, align, x, y, color.toInt(), drawShadow, displayMode, packedLightCoords, effectColor) fun Font.drawScaledAligned(poseStack: PoseStack, buffer: MultiBufferSource, text: String, scale: Float, align: TextAlign, x: Float, y: Float, drawShadow: Boolean = false, displayMode: Font.DisplayMode = Font.DisplayMode.NORMAL, packedLightCoords: Int = 15728880, effectColor: Int = 0, color: RGBAColor) = drawScaledAligned(poseStack, buffer, text, scale, align, x, y, color.toInt(), drawShadow, displayMode, packedLightCoords, effectColor)
fun Font.drawScaledAligned(poseStack: PoseStack, buffer: MultiBufferSource, text: Component, scale: Float, align: TextAlign, x: Float, y: Float, drawShadow: Boolean = false, displayMode: Font.DisplayMode = Font.DisplayMode.NORMAL, packedLightCoords: Int = 15728880, effectColor: Int = 0, color: RGBAColor) = drawScaledAligned(poseStack, buffer, text, scale, align, x, y, color.toInt(), drawShadow, displayMode, packedLightCoords, effectColor) fun Font.drawScaledAligned(poseStack: PoseStack, buffer: MultiBufferSource, text: Component, scale: Float, align: TextAlign, x: Float, y: Float, drawShadow: Boolean = false, displayMode: Font.DisplayMode = Font.DisplayMode.NORMAL, packedLightCoords: Int = 15728880, effectColor: Int = 0, color: RGBAColor) = drawScaledAligned(poseStack, buffer, text, scale, align, x, y, color.toInt(), drawShadow, displayMode, packedLightCoords, effectColor)
fun Font.drawScaledAligned(poseStack: PoseStack, buffer: MultiBufferSource, text: FormattedCharSequence, scale: Float, align: TextAlign, x: Float, y: Float, drawShadow: Boolean = false, displayMode: Font.DisplayMode = Font.DisplayMode.NORMAL, packedLightCoords: Int = 15728880, effectColor: Int = 0, color: RGBAColor) = drawScaledAligned(poseStack, buffer, text, scale, align, x, y, color.toInt(), drawShadow, displayMode, packedLightCoords, effectColor) fun Font.drawScaledAligned(poseStack: PoseStack, buffer: MultiBufferSource, text: FormattedCharSequence, scale: Float, align: TextAlign, x: Float, y: Float, drawShadow: Boolean = false, displayMode: Font.DisplayMode = Font.DisplayMode.NORMAL, packedLightCoords: Int = 15728880, effectColor: Int = 0, color: RGBAColor) = drawScaledAligned(poseStack, buffer, text, scale, align, x, y, color.toInt(), drawShadow, displayMode, packedLightCoords, effectColor)
fun GuiGraphics.drawAligned(font: Font, text: String, align: TextAlign, x: Float, y: Float, color: Int) = drawAlignedDuckTyped(poseStack, text, align, x, y, color)
fun GuiGraphics.drawAligned(font: Font, text: Component, align: TextAlign, x: Float, y: Float, color: Int) = drawAlignedDuckTyped(poseStack, text, align, x, y, color)
fun GuiGraphics.drawAligned(font: Font, text: FormattedCharSequence, align: TextAlign, x: Float, y: Float, color: Int) = drawAlignedDuckTyped(poseStack, text, align, x, y, color)
fun GuiGraphics.drawAligned(font: Font, text: String, align: TextAlign, x: Float, y: Float, color: RGBAColor) = drawAligned(poseStack, text, align, x, y, color.toInt())
fun GuiGraphics.drawAligned(font: Font, text: Component, align: TextAlign, x: Float, y: Float, color: RGBAColor) = drawAligned(poseStack, text, align, x, y, color.toInt())
fun GuiGraphics.drawAligned(font: Font, text: FormattedCharSequence, align: TextAlign, x: Float, y: Float, color: RGBAColor) = drawAligned(poseStack, text, align, x, y, color.toInt())
fun GuiGraphics.drawScaledAligned(font: Font, text: String, scale: Float, align: TextAlign, x: Float, y: Float, color: Int) = drawScaledAlignedDuckTyped(poseStack, text, scale, align, x, y, color)
fun GuiGraphics.drawScaledAligned(font: Font, text: Component, scale: Float, align: TextAlign, x: Float, y: Float, color: Int) = drawScaledAlignedDuckTyped(poseStack, text, scale, align, x, y, color)
fun GuiGraphics.drawScaledAligned(font: Font, text: FormattedCharSequence, scale: Float, align: TextAlign, x: Float, y: Float, color: Int) = drawScaledAlignedDuckTyped(poseStack, text, scale, align, x, y, color)
fun GuiGraphics.drawScaledAligned(font: Font, text: String, scale: Float, align: TextAlign, x: Float, y: Float, color: RGBAColor) = drawScaledAligned(poseStack, text, scale, align, x, y, color.toInt())
fun GuiGraphics.drawScaledAligned(font: Font, text: Component, scale: Float, align: TextAlign, x: Float, y: Float, color: RGBAColor) = drawScaledAligned(poseStack, text, scale, align, x, y, color.toInt())
fun GuiGraphics.drawScaledAligned(font: Font, text: FormattedCharSequence, scale: Float, align: TextAlign, x: Float, y: Float, color: RGBAColor) = drawScaledAligned(poseStack, text, scale, align, x, y, color.toInt())

View File

@ -6,6 +6,7 @@ import com.mojang.blaze3d.vertex.PoseStack
import it.unimi.dsi.fastutil.objects.ReferenceArraySet import it.unimi.dsi.fastutil.objects.ReferenceArraySet
import net.minecraft.client.gui.ComponentPath import net.minecraft.client.gui.ComponentPath
import net.minecraft.client.gui.Font import net.minecraft.client.gui.Font
import net.minecraft.client.gui.GuiGraphics
import net.minecraft.client.gui.components.events.GuiEventListener import net.minecraft.client.gui.components.events.GuiEventListener
import net.minecraft.client.gui.navigation.FocusNavigationEvent import net.minecraft.client.gui.navigation.FocusNavigationEvent
import net.minecraft.client.gui.navigation.ScreenRectangle import net.minecraft.client.gui.navigation.ScreenRectangle
@ -697,8 +698,8 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
} }
} }
protected open fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) {} protected open fun innerRender(graphics: GuiGraphics, mouseX: Float, mouseY: Float, partialTick: Float) {}
protected open fun innerRenderTooltips(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float): Boolean { protected open fun innerRenderTooltips(graphics: GuiGraphics, mouseX: Float, mouseY: Float, partialTick: Float): Boolean {
return false return false
} }
@ -742,11 +743,13 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
} }
} }
fun render(poseStack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) { fun render(graphics: GuiGraphics, mouseX: Float, mouseY: Float, partialTick: Float) {
if (!isVisible()) { if (!isVisible()) {
return return
} }
val poseStack = graphics.pose()
performLayoutIfNeeded() performLayoutIfNeeded()
val parent = this.parent val parent = this.parent
@ -789,7 +792,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
poseStack.pushPose() poseStack.pushPose()
poseStack.translate(absoluteX.toDouble(), absoluteY.toDouble(), 10.0) poseStack.translate(absoluteX.toDouble(), absoluteY.toDouble(), 10.0)
RenderSystem.setShaderColor(1f, 1f, 1f, if (isFlashFrameRecursive) 0.5f else 1f) RenderSystem.setShaderColor(1f, 1f, 1f, if (isFlashFrameRecursive) 0.5f else 1f)
innerRender(poseStack, mouseX, mouseY, partialTick) innerRender(graphics, mouseX, mouseY, partialTick)
RenderSystem.setShaderColor(1f, 1f, 1f, 1f) RenderSystem.setShaderColor(1f, 1f, 1f, 1f)
poseStack.popPose() poseStack.popPose()
} }
@ -798,7 +801,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
child.absoluteX = absoluteX + child.x + xOffset child.absoluteX = absoluteX + child.x + xOffset
child.absoluteY = absoluteY + child.y + yOffset child.absoluteY = absoluteY + child.y + yOffset
child.render(poseStack, mouseX, mouseY, partialTick) child.render(graphics, mouseX, mouseY, partialTick)
} }
if (scissor) { if (scissor) {
@ -921,7 +924,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
return null to ItemStack.EMPTY return null to ItemStack.EMPTY
} }
fun renderTooltips(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float): Boolean { fun renderTooltips(graphics: GuiGraphics, mouseX: Float, mouseY: Float, partialTick: Float): Boolean {
if (!isVisible()) { if (!isVisible()) {
return false return false
} }
@ -933,12 +936,12 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
} }
for (child in visibleChildrenInternal) { for (child in visibleChildrenInternal) {
if (child.renderTooltips(stack, mouseX, mouseY, partialTick)) { if (child.renderTooltips(graphics, mouseX, mouseY, partialTick)) {
return true return true
} }
} }
if (innerRenderTooltips(stack, mouseX, mouseY, partialTick)) { if (innerRenderTooltips(graphics, mouseX, mouseY, partialTick)) {
return true return true
} }
@ -947,22 +950,20 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
val tooltipList = tooltipList val tooltipList = tooltipList
if (tooltip != null) { if (tooltip != null) {
screen.renderComponentTooltip( graphics.renderComponentTooltip(
stack, font,
listOf(tooltip), listOf(tooltip),
mouseX.toInt(), mouseX.toInt(),
mouseY.toInt(), mouseY.toInt()
font
) )
return true return true
} else if (tooltipList != null) { } else if (tooltipList != null) {
screen.renderComponentTooltip( graphics.renderComponentTooltip(
stack, font,
tooltipList, tooltipList,
mouseX.toInt(), mouseX.toInt(),
mouseY.toInt(), mouseY.toInt(),
font
) )
return true return true

View File

@ -1,6 +1,7 @@
package ru.dbotthepony.mc.otm.client.screen.panels package ru.dbotthepony.mc.otm.client.screen.panels
import com.mojang.blaze3d.vertex.PoseStack import com.mojang.blaze3d.vertex.PoseStack
import net.minecraft.client.gui.GuiGraphics
import net.minecraft.client.gui.screens.Screen import net.minecraft.client.gui.screens.Screen
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen
import net.minecraft.client.gui.screens.inventory.InventoryScreen import net.minecraft.client.gui.screens.inventory.InventoryScreen
@ -89,7 +90,7 @@ class EntityRendererPanel<out S : Screen> @JvmOverloads constructor(
} }
} }
override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) { override fun innerRender(graphics: GuiGraphics, mouseX: Float, mouseY: Float, partialTick: Float) {
if (entity.isDeadOrDying) { if (entity.isDeadOrDying) {
return return
} }
@ -98,7 +99,7 @@ class EntityRendererPanel<out S : Screen> @JvmOverloads constructor(
val renderY = (height * 0.9f).toInt() val renderY = (height * 0.9f).toInt()
InventoryScreen.renderEntityInInventoryFollowsMouse( InventoryScreen.renderEntityInInventoryFollowsMouse(
stack, graphics,
renderX, renderX,
renderY, renderY,
renderScale, renderScale,
@ -123,8 +124,8 @@ class EntityRendererPanel<out S : Screen> @JvmOverloads constructor(
} }
} }
override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) { override fun innerRender(graphics: GuiGraphics, mouseX: Float, mouseY: Float, partialTick: Float) {
ExoPackInventoryScreen.ENTITY_RECTANGLE.render(stack) ExoPackInventoryScreen.ENTITY_RECTANGLE.render(graphics.pose())
} }
companion object { companion object {

View File

@ -3,6 +3,7 @@ package ru.dbotthepony.mc.otm.client.screen.panels
import com.mojang.blaze3d.platform.InputConstants import com.mojang.blaze3d.platform.InputConstants
import com.mojang.blaze3d.systems.RenderSystem import com.mojang.blaze3d.systems.RenderSystem
import com.mojang.blaze3d.vertex.PoseStack import com.mojang.blaze3d.vertex.PoseStack
import net.minecraft.client.gui.GuiGraphics
import net.minecraft.client.gui.narration.NarratableEntry import net.minecraft.client.gui.narration.NarratableEntry
import net.minecraft.client.gui.narration.NarratableEntry.NarrationPriority import net.minecraft.client.gui.narration.NarratableEntry.NarrationPriority
import net.minecraft.client.gui.narration.NarrationElementOutput import net.minecraft.client.gui.narration.NarrationElementOutput
@ -50,7 +51,8 @@ open class FramePanel<out S : Screen>(
} }
} }
override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) { override fun innerRender(graphics: GuiGraphics, mouseX: Float, mouseY: Float, partialTick: Float) {
val stack = graphics.pose()
val width: Float val width: Float
val height: Float val height: Float
@ -194,13 +196,13 @@ open class FramePanel<out S : Screen>(
return super.keyPressedInternal(key, scancode, mods) return super.keyPressedInternal(key, scancode, mods)
} }
override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) { override fun innerRender(graphics: GuiGraphics, mouseX: Float, mouseY: Float, partialTick: Float) {
RECTANGLE.render(stack, width = width, height = height) RECTANGLE.render(graphics.pose(), width = width, height = height)
// title // title
val title = title ?: return val title = title ?: return
RenderSystem.depthFunc(GL30.GL_ALWAYS) RenderSystem.depthFunc(GL30.GL_ALWAYS)
font.draw(stack, title, 8f, 5f, 4210752) font.drawAligned(graphics.pose(), title, TextAlign.TOP_LEFT, 8f, 5f, 4210752)
RenderSystem.depthFunc(GL30.GL_ALWAYS) RenderSystem.depthFunc(GL30.GL_ALWAYS)
} }

View File

@ -1,6 +1,6 @@
package ru.dbotthepony.mc.otm.client.screen.panels package ru.dbotthepony.mc.otm.client.screen.panels
import com.mojang.blaze3d.vertex.PoseStack import net.minecraft.client.gui.GuiGraphics
import net.minecraft.client.gui.screens.Screen import net.minecraft.client.gui.screens.Screen
import net.minecraft.network.chat.Component import net.minecraft.network.chat.Component
import ru.dbotthepony.mc.otm.client.render.TextAlign import ru.dbotthepony.mc.otm.client.render.TextAlign
@ -31,33 +31,33 @@ open class Label<out S : Screen> @JvmOverloads constructor(
var color = RGBAColor.SLATE_GRAY var color = RGBAColor.SLATE_GRAY
var align = TextAlign.TOP_LEFT var align = TextAlign.TOP_LEFT
override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) { override fun innerRender(graphics: GuiGraphics, mouseX: Float, mouseY: Float, partialTick: Float) {
clearDepth(stack) clearDepth(graphics.pose())
if (shadow) { if (shadow) {
when (align) { when (align) {
TextAlign.TOP_LEFT -> font.drawAligned(stack, text, align, shadowX, shadowY, shadowColor.toInt()) TextAlign.TOP_LEFT -> font.drawAligned(graphics.pose(), text, align, shadowX, shadowY, shadowColor.toInt())
TextAlign.TOP_CENTER -> font.drawAligned(stack, text, align, shadowX + width / 2f, shadowY, shadowColor.toInt()) TextAlign.TOP_CENTER -> font.drawAligned(graphics.pose(), text, align, shadowX + width / 2f, shadowY, shadowColor.toInt())
TextAlign.TOP_RIGHT -> font.drawAligned(stack, text, align, shadowX + width, shadowY, shadowColor.toInt()) TextAlign.TOP_RIGHT -> font.drawAligned(graphics.pose(), text, align, shadowX + width, shadowY, shadowColor.toInt())
TextAlign.CENTER_LEFT -> font.drawAligned(stack, text, align, shadowX, height / 2f + shadowY, shadowColor.toInt()) TextAlign.CENTER_LEFT -> font.drawAligned(graphics.pose(), text, align, shadowX, height / 2f + shadowY, shadowColor.toInt())
TextAlign.CENTER_CENTER -> font.drawAligned(stack, text, align, shadowX + width / 2f, height / 2f + shadowY, shadowColor.toInt()) TextAlign.CENTER_CENTER -> font.drawAligned(graphics.pose(), text, align, shadowX + width / 2f, height / 2f + shadowY, shadowColor.toInt())
TextAlign.CENTER_RIGHT -> font.drawAligned(stack, text, align, shadowX + width, height / 2f + shadowY, shadowColor.toInt()) TextAlign.CENTER_RIGHT -> font.drawAligned(graphics.pose(), text, align, shadowX + width, height / 2f + shadowY, shadowColor.toInt())
TextAlign.BOTTOM_LEFT -> font.drawAligned(stack, text, align, shadowX, height + shadowY, shadowColor.toInt()) TextAlign.BOTTOM_LEFT -> font.drawAligned(graphics.pose(), text, align, shadowX, height + shadowY, shadowColor.toInt())
TextAlign.BOTTOM_CENTER -> font.drawAligned(stack, text, align, shadowX + width / 2f, height + shadowY, shadowColor.toInt()) TextAlign.BOTTOM_CENTER -> font.drawAligned(graphics.pose(), text, align, shadowX + width / 2f, height + shadowY, shadowColor.toInt())
TextAlign.BOTTOM_RIGHT -> font.drawAligned(stack, text, align, shadowX + width, height + shadowY, shadowColor.toInt()) TextAlign.BOTTOM_RIGHT -> font.drawAligned(graphics.pose(), text, align, shadowX + width, height + shadowY, shadowColor.toInt())
} }
} }
when (align) { when (align) {
TextAlign.TOP_LEFT -> font.drawAligned(stack, text, align, 0f, 0f, color.toInt()) TextAlign.TOP_LEFT -> font.drawAligned(graphics.pose(), text, align, 0f, 0f, color.toInt())
TextAlign.TOP_CENTER -> font.drawAligned(stack, text, align, width / 2f, 0f, color.toInt()) TextAlign.TOP_CENTER -> font.drawAligned(graphics.pose(), text, align, width / 2f, 0f, color.toInt())
TextAlign.TOP_RIGHT -> font.drawAligned(stack, text, align, width - (if (shadow) shadowX else 0f), 0f, color.toInt()) TextAlign.TOP_RIGHT -> font.drawAligned(graphics.pose(), text, align, width - (if (shadow) shadowX else 0f), 0f, color.toInt())
TextAlign.CENTER_LEFT -> font.drawAligned(stack, text, align, 0f, height / 2f, color.toInt()) TextAlign.CENTER_LEFT -> font.drawAligned(graphics.pose(), text, align, 0f, height / 2f, color.toInt())
TextAlign.CENTER_CENTER -> font.drawAligned(stack, text, align, width / 2f, height / 2f, color.toInt()) TextAlign.CENTER_CENTER -> font.drawAligned(graphics.pose(), text, align, width / 2f, height / 2f, color.toInt())
TextAlign.CENTER_RIGHT -> font.drawAligned(stack, text, align, width - (if (shadow) shadowX else 0f), height / 2f, color.toInt()) TextAlign.CENTER_RIGHT -> font.drawAligned(graphics.pose(), text, align, width - (if (shadow) shadowX else 0f), height / 2f, color.toInt())
TextAlign.BOTTOM_LEFT -> font.drawAligned(stack, text, align, 0f, height, color.toInt()) TextAlign.BOTTOM_LEFT -> font.drawAligned(graphics.pose(), text, align, 0f, height, color.toInt())
TextAlign.BOTTOM_CENTER -> font.drawAligned(stack, text, align, width / 2f, height, color.toInt()) TextAlign.BOTTOM_CENTER -> font.drawAligned(graphics.pose(), text, align, width / 2f, height, color.toInt())
TextAlign.BOTTOM_RIGHT -> font.drawAligned(stack, text, align, width - (if (shadow) shadowX else 0f), height, color.toInt()) TextAlign.BOTTOM_RIGHT -> font.drawAligned(graphics.pose(), text, align, width - (if (shadow) shadowX else 0f), height, color.toInt())
} }
} }

View File

@ -1,6 +1,6 @@
package ru.dbotthepony.mc.otm.client.screen.panels package ru.dbotthepony.mc.otm.client.screen.panels
import com.mojang.blaze3d.vertex.PoseStack import net.minecraft.client.gui.GuiGraphics
import net.minecraft.client.gui.components.Renderable import net.minecraft.client.gui.components.Renderable
import net.minecraft.client.gui.components.events.GuiEventListener import net.minecraft.client.gui.components.events.GuiEventListener
import net.minecraft.client.gui.screens.Screen import net.minecraft.client.gui.screens.Screen
@ -13,15 +13,15 @@ class Panel2Widget<out S: Screen, out P : EditablePanel<S>>(
require(panel.parent == null) { "Widget wrapped panels can't have a parent ($panel has parent ${panel.parent})" } require(panel.parent == null) { "Widget wrapped panels can't have a parent ($panel has parent ${panel.parent})" }
} }
override fun render(poseStack: PoseStack, mouseX: Int, mouseY: Int, partialTick: Float) { override fun render(graphics: GuiGraphics, mouseX: Int, mouseY: Int, partialTick: Float) {
panel.tick() panel.tick()
val xFloat = mouseX.toFloat() val xFloat = mouseX.toFloat()
val yFloat = mouseY.toFloat() val yFloat = mouseY.toFloat()
panel.tickHover(xFloat, yFloat) panel.tickHover(xFloat, yFloat)
panel.render(poseStack, xFloat, yFloat, partialTick) panel.render(graphics, xFloat, yFloat, partialTick)
panel.renderTooltips(poseStack, xFloat, yFloat, partialTick) panel.renderTooltips(graphics, xFloat, yFloat, partialTick)
} }
override fun mouseMoved(mouseX: Double, mouseY: Double) { override fun mouseMoved(mouseX: Double, mouseY: Double) {