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 5fc44970c..13eccc6cf 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 @@ -530,7 +530,7 @@ fun determineTooltipPosition(x: Float, y: Float, width: Float, height: Float): P * * thanks Mojang */ -fun clearDepth(stack: PoseStack, x: Float, y: Float, width: Float, height: Float, depth: Float = -600f) { +fun clearDepth(stack: PoseStack, x: Float, y: Float, width: Float, height: Float, depth: Float = -500f) { val oldShader = RenderSystem.getShader() RenderSystem.setShader(GameRenderer::getPositionShader) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/MatteryScreen.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/MatteryScreen.kt index 3f0d1b7eb..82e06a3f1 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/MatteryScreen.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/MatteryScreen.kt @@ -440,14 +440,11 @@ abstract class MatteryScreen(menu: T, inventory: Inventory, tit RenderSystem.enableTexture() RenderSystem.activeTexture(GL13.GL_TEXTURE0) - var depth = -900f - for (i in panels.indices.reversed()) { val panel = panels[i] RenderSystem.depthFunc(GL11.GL_ALWAYS) - panel.accumulatedDepth = depth RenderSystem.setShaderColor(1f, 1f, 1f, 1f) - depth = depth.coerceAtLeast(panel.render(poseStack, mouseXf, mouseYf, partialTick)) + panel.render(poseStack, mouseXf, mouseYf, partialTick) } RenderSystem.depthFunc(GL11.GL_LESS) @@ -484,13 +481,6 @@ abstract class MatteryScreen(menu: T, inventory: Inventory, tit RenderSystem.disableDepthTest() - // forge's hard limit tooltip Z position to 500 units - // so if we have anything drawn above 500 units, lift it up - if (depth > 500f) { - poseStack.pushPose() - poseStack.translate(0.0, 0.0, depth - 500.0) - } - if (menu.carried.isEmpty) { val hoveredSlot = hoveredSlot @@ -505,10 +495,6 @@ abstract class MatteryScreen(menu: T, inventory: Inventory, tit } } - if (depth > 500f) { - poseStack.popPose() - } - RenderSystem.enableDepthTest() } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/AbstractSlotPanel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/AbstractSlotPanel.kt index 59278e712..5f854368e 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/AbstractSlotPanel.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/AbstractSlotPanel.kt @@ -26,31 +26,29 @@ abstract class AbstractSlotPanel> @JvmOverloads constru } protected open fun renderRegular(stack: PoseStack, itemstack: ItemStack, count_override: String? = null) { - RenderSystem.setShader { GameRenderer.getPositionTexShader() } - - var zHeight = 0.0 + RenderSystem.setShader(GameRenderer::getPositionTexShader) if (!itemstack.isEmpty) { RenderSystem.enableDepthTest() - val system_stack = RenderSystem.getModelViewStack() + val systemPoseStack = RenderSystem.getModelViewStack() - system_stack.pushPose() - system_stack.translate((absoluteX + 1).toDouble(), (absoluteY + 1).toDouble(), 0.0) + systemPoseStack.pushPose() + systemPoseStack.translate((absoluteX + 1f).toDouble(), (absoluteY + 1f).toDouble(), 0.0) RenderSystem.applyModelViewMatrix() RenderSystem.depthFunc(GL11.GL_LESS) // Thanks Mojang // Very cool // (for int x, int y, which are then cast into doubles anyway) - screen.itemRenderer.blitOffset = accumulatedDepth - 100 // force item to draw only 50 units "above" background + screen.itemRenderer.blitOffset = 1f // Z pos screen.itemRenderer.renderAndDecorateItem( requireNotNull(minecraft.player) { "yo, dude, what the fuck" }, itemstack, 0, 0, - (absoluteX + absoluteY * 1000).toInt() + (absoluteX + absoluteY * 1000f).toInt() ) RenderSystem.depthFunc(GL11.GL_ALWAYS) @@ -58,18 +56,15 @@ abstract class AbstractSlotPanel> @JvmOverloads constru screen.itemRenderer.blitOffset = 0f // too big accumulations can lead to Z near clipping issues - accumulate3DHeight(101f) - zHeight = 101.0 - system_stack.popPose() + systemPoseStack.popPose() RenderSystem.applyModelViewMatrix() + + clearDepth(stack) } if (isHovered) { - stack.pushPose() - stack.translate(0.0, 0.0, zHeight) drawColor = SLOT_HIGHLIGHT drawRect(stack, 1f, 1f, width - 1, height - 1) - stack.popPose() } } 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 ecb5a5576..106c7ea05 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 @@ -11,6 +11,7 @@ import net.minecraft.world.inventory.Slot import org.apache.logging.log4j.LogManager import ru.dbotthepony.mc.otm.client.minecraft import ru.dbotthepony.mc.otm.client.moveMousePosScaled +import ru.dbotthepony.mc.otm.client.render.ScissorRect import ru.dbotthepony.mc.otm.client.render.currentScissorRect import ru.dbotthepony.mc.otm.client.render.popScissorRect import ru.dbotthepony.mc.otm.client.render.pushScissorRect @@ -320,28 +321,12 @@ open class EditablePanel @JvmOverloads constructor( private var focusedAsParent = false - var accumulatedDepth = 0f - - fun accumulate3DHeight(value: Float) { - accumulatedDepth += value - } - val font: Font get() = if (screen is MatteryScreen<*>) screen.font else minecraft.font fun invalidateLayout() { layoutInvalidated = true } - fun most3DHeight(): Float { - var depth = accumulatedDepth - - for (child in children) { - depth = max(depth, child.most3DHeight()) - } - - return depth - } - init { this.x = x this.y = y @@ -388,13 +373,11 @@ open class EditablePanel @JvmOverloads constructor( return false } - fun render(poseStack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float): Float { + fun render(poseStack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) { if (!isVisible()) { - return 0f + return } - var depth = 0f - if (layoutInvalidated) { performLayout() } else if (boundsInvalidated) { @@ -431,12 +414,13 @@ open class EditablePanel @JvmOverloads constructor( ) } - val currentScissorRect = currentScissorRect + var currentScissorRect = currentScissorRect if (currentScissorRect == null || currentScissorRect.crossScaled(absoluteX, absoluteY, width, height)) { // do not render if we are getting cut off by screen scissor + clearDepth(poseStack, absoluteX, absoluteY, width, height) poseStack.pushPose() - poseStack.translate(absoluteX.toDouble(), absoluteY.toDouble(), accumulatedDepth.toDouble()) + poseStack.translate(absoluteX.toDouble(), absoluteY.toDouble(), 10.0) RenderSystem.setShaderColor(1f, 1f, 1f, 1f) innerRender(poseStack, mouseX, mouseY, partialTick) poseStack.popPose() @@ -444,19 +428,16 @@ open class EditablePanel @JvmOverloads constructor( for (child in children) { if (child.isVisible()) { - child.accumulatedDepth = accumulatedDepth + 1 child.absoluteX = absoluteX + child.x + xOffset child.absoluteY = absoluteY + child.y + yOffset - depth = max(depth, child.render(poseStack, mouseX, mouseY, partialTick)) + child.render(poseStack, mouseX, mouseY, partialTick) } } if (scissor) { popScissorRect() } - - return depth } open fun tickHover(mouseX: Float, mouseY: Float): Boolean {