Use clearDepth() in panels instead of 3D depth hack
This commit is contained in:
parent
72dca1457b
commit
b280e3c6c5
@ -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)
|
||||
|
||||
|
@ -440,14 +440,11 @@ abstract class MatteryScreen<T : MatteryMenu>(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<T : MatteryMenu>(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<T : MatteryMenu>(menu: T, inventory: Inventory, tit
|
||||
}
|
||||
}
|
||||
|
||||
if (depth > 500f) {
|
||||
poseStack.popPose()
|
||||
}
|
||||
|
||||
RenderSystem.enableDepthTest()
|
||||
}
|
||||
|
||||
|
@ -26,31 +26,29 @@ abstract class AbstractSlotPanel<out S : MatteryScreen<*>> @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<out S : MatteryScreen<*>> @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()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<out S : Screen> @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<out S : Screen> @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<out S : Screen> @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<out S : Screen> @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 {
|
||||
|
Loading…
Reference in New Issue
Block a user