Merge branch '1.21' into new-container-api
This commit is contained in:
commit
dc73ac7b55
@ -14,6 +14,8 @@ import net.minecraft.world.inventory.tooltip.TooltipComponent
|
||||
import net.minecraft.world.item.ItemStack
|
||||
import ru.dbotthepony.mc.otm.client.minecraft
|
||||
import ru.dbotthepony.kommons.math.RGBAColor
|
||||
import ru.dbotthepony.mc.otm.client.screen.panels.ScreenPos
|
||||
import java.util.Arrays
|
||||
import kotlin.math.PI
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
@ -45,6 +47,73 @@ class MGUIGraphics(val parent: GuiGraphics) {
|
||||
drawLine(pose.last().pose(), startX, startY, endX, endY, width, z, color)
|
||||
}
|
||||
|
||||
fun drawLine(
|
||||
points: Iterable<LinePoint>,
|
||||
width: Float,
|
||||
color: RGBAColor = RGBAColor.WHITE
|
||||
) {
|
||||
drawLine(pose.last().pose(), points, width, color)
|
||||
}
|
||||
|
||||
fun drawLine(
|
||||
points: Array<out LinePoint>,
|
||||
width: Float,
|
||||
color: RGBAColor = RGBAColor.WHITE
|
||||
) {
|
||||
drawLine(pose.last().pose(), points, width, color)
|
||||
}
|
||||
|
||||
fun drawLine(
|
||||
width: Float,
|
||||
color: RGBAColor,
|
||||
vararg points: LinePoint,
|
||||
) {
|
||||
drawLine(pose.last().pose(), points, width, color)
|
||||
}
|
||||
|
||||
fun drawLine(
|
||||
width: Float,
|
||||
color: RGBAColor,
|
||||
points: Iterable<LinePoint>,
|
||||
) {
|
||||
drawLine(pose.last().pose(), points, width, color)
|
||||
}
|
||||
|
||||
fun drawLine(
|
||||
width: Float,
|
||||
color: RGBAColor,
|
||||
z: Float,
|
||||
points: List<ScreenPos>,
|
||||
) {
|
||||
require(points.size >= 2) { "Degenerate point list: only ${points.size} defined" }
|
||||
|
||||
val result = ArrayList<LinePoint>(points.size)
|
||||
|
||||
for (i in 1 until points.size) {
|
||||
val (x0, y0) = points[i - 1]
|
||||
val (x1, y1) = points[i]
|
||||
|
||||
result.add(
|
||||
LinePoint(
|
||||
x0, y0,
|
||||
x1, y1,
|
||||
z
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
drawLine(pose.last().pose(), result, width, color)
|
||||
}
|
||||
|
||||
fun drawLine(
|
||||
width: Float,
|
||||
color: RGBAColor,
|
||||
z: Float,
|
||||
vararg points: ScreenPos,
|
||||
) {
|
||||
drawLine(width, color, z, Arrays.asList(*points))
|
||||
}
|
||||
|
||||
fun renderRect(
|
||||
x: Float,
|
||||
y: Float,
|
||||
|
@ -294,6 +294,65 @@ fun renderColoredSphere(pose: PoseStack, radius: Float, color: RGBAColor = RGBAC
|
||||
BufferUploader.drawWithShader(builder.buildOrThrow())
|
||||
}
|
||||
|
||||
private fun uploadLineSegment(
|
||||
builder: BufferBuilder,
|
||||
matrix: Matrix4f,
|
||||
startX: Float,
|
||||
startY: Float,
|
||||
endX: Float,
|
||||
endY: Float,
|
||||
width: Float,
|
||||
z: Float,
|
||||
color: RGBAColor = RGBAColor.WHITE
|
||||
) {
|
||||
val length = ((startX - endX).pow(2f) + (startY - endY).pow(2f)).pow(0.5f)
|
||||
var angle = acos((endX - startX) / length)
|
||||
|
||||
if (startY > endY)
|
||||
angle *= -1f
|
||||
|
||||
val cos = cos(angle)
|
||||
val sin = sin(angle)
|
||||
|
||||
val y0 = -width
|
||||
|
||||
val y1 = width
|
||||
|
||||
val x2 = length
|
||||
val y2 = width
|
||||
|
||||
val x3 = length
|
||||
val y3 = -width
|
||||
|
||||
builder.vertex(matrix,
|
||||
startX - y0 * sin,
|
||||
startY + y0 * cos,
|
||||
z).color(color)
|
||||
|
||||
builder.vertex(matrix,
|
||||
startX - y1 * sin,
|
||||
startY + y1 * cos,
|
||||
z).color(color)
|
||||
|
||||
builder.vertex(matrix,
|
||||
startX + x2 * cos - y2 * sin,
|
||||
startY + x2 * sin + y2 * cos,
|
||||
z).color(color)
|
||||
|
||||
builder.vertex(matrix,
|
||||
startX + x3 * cos - y3 * sin,
|
||||
startY + x3 * sin + y3 * cos,
|
||||
z).color(color)
|
||||
}
|
||||
|
||||
data class LinePoint(
|
||||
val startX: Float,
|
||||
val startY: Float,
|
||||
val endX: Float,
|
||||
val endY: Float,
|
||||
val z: Float = 0f,
|
||||
)
|
||||
|
||||
fun drawLine(
|
||||
matrix: Matrix4f,
|
||||
startX: Float,
|
||||
@ -312,46 +371,46 @@ fun drawLine(
|
||||
RenderSystem.depthFunc(GL_ALWAYS)
|
||||
|
||||
val builder = tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR)
|
||||
uploadLineSegment(builder, matrix, startX, startY, endX, endY, width, z, color)
|
||||
BufferUploader.drawWithShader(builder.buildOrThrow())
|
||||
}
|
||||
|
||||
val length = ((startX - endX).pow(2f) + (startY - endY).pow(2f)).pow(0.5f)
|
||||
val angle = acos((endX - startX) / length)
|
||||
fun drawLine(
|
||||
matrix: Matrix4f,
|
||||
points: Iterable<LinePoint>,
|
||||
width: Float,
|
||||
color: RGBAColor = RGBAColor.WHITE
|
||||
) {
|
||||
val itr = points.iterator()
|
||||
|
||||
val cos = cos(angle)
|
||||
val sin = sin(angle)
|
||||
if (!itr.hasNext()) {
|
||||
throw IllegalArgumentException("No line points were provided")
|
||||
}
|
||||
|
||||
val y0 = -width
|
||||
RenderSystem.setShader(GameRenderer::getPositionColorShader)
|
||||
RenderSystem.enableBlend()
|
||||
RenderSystem.defaultBlendFunc()
|
||||
|
||||
val y1 = width
|
||||
if (!is3DContext)
|
||||
RenderSystem.depthFunc(GL_ALWAYS)
|
||||
|
||||
val x2 = length
|
||||
val y2 = width
|
||||
val builder = tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR)
|
||||
|
||||
val x3 = length
|
||||
val y3 = -width
|
||||
|
||||
builder.vertex(matrix,
|
||||
startX - y0 * sin,
|
||||
startY + y0 * cos,
|
||||
z).color(color)
|
||||
|
||||
builder.vertex(matrix,
|
||||
startX - y1 * sin,
|
||||
startY + y1 * cos,
|
||||
z).color(color)
|
||||
|
||||
builder.vertex(matrix,
|
||||
startX + x2 * cos - y2 * sin,
|
||||
startY + x2 * sin + y2 * cos,
|
||||
z).color(color)
|
||||
|
||||
builder.vertex(matrix,
|
||||
startX + x3 * cos - y3 * sin,
|
||||
startY + x3 * sin + y3 * cos,
|
||||
z).color(color)
|
||||
for ((startX, startY, endX, endY, z) in itr)
|
||||
uploadLineSegment(builder, matrix, startX, startY, endX, endY, width, z, color)
|
||||
|
||||
BufferUploader.drawWithShader(builder.buildOrThrow())
|
||||
}
|
||||
|
||||
fun drawLine(
|
||||
matrix: Matrix4f,
|
||||
points: Array<out LinePoint>,
|
||||
width: Float,
|
||||
color: RGBAColor = RGBAColor.WHITE
|
||||
) {
|
||||
return drawLine(matrix, points.asIterable(), width, color)
|
||||
}
|
||||
|
||||
data class ScissorRect(val xStart: Int, val yStart: Int, val xEnd: Int, val yEnd: Int, val lock: Boolean = false) {
|
||||
val width: Int
|
||||
get() = (xEnd - xStart).coerceAtLeast(0)
|
||||
|
@ -14,9 +14,13 @@ import net.minecraft.world.item.ItemStack
|
||||
import net.neoforged.neoforge.client.event.ContainerScreenEvent
|
||||
import net.neoforged.neoforge.common.NeoForge
|
||||
import org.lwjgl.opengl.GL11
|
||||
import ru.dbotthepony.kommons.util.getValue
|
||||
import ru.dbotthepony.kommons.util.setValue
|
||||
import ru.dbotthepony.kommons.math.RGBAColor
|
||||
import ru.dbotthepony.mc.otm.player.matteryPlayer
|
||||
import ru.dbotthepony.mc.otm.client.render.MGUIGraphics
|
||||
import ru.dbotthepony.mc.otm.client.moveMousePosScaled
|
||||
import ru.dbotthepony.mc.otm.client.render.LinePoint
|
||||
import ru.dbotthepony.mc.otm.client.render.WidgetLocation
|
||||
import ru.dbotthepony.mc.otm.client.render.Widgets18
|
||||
import ru.dbotthepony.mc.otm.client.render.translation
|
||||
@ -52,6 +56,7 @@ import ru.dbotthepony.mc.otm.menu.widget.LevelGaugeWidget
|
||||
import ru.dbotthepony.mc.otm.menu.widget.ProfiledLevelGaugeWidget
|
||||
import java.util.*
|
||||
import java.util.concurrent.CopyOnWriteArrayList
|
||||
import kotlin.collections.ArrayList
|
||||
import kotlin.collections.List
|
||||
import kotlin.collections.MutableSet
|
||||
import kotlin.collections.isNotEmpty
|
||||
@ -685,7 +690,13 @@ abstract class MatteryScreen<T : MatteryMenu>(menu: T, inventory: Inventory, tit
|
||||
for (panel in panelsReversed) {
|
||||
RenderSystem.depthFunc(GL11.GL_ALWAYS)
|
||||
RenderSystem.setShaderColor(1f, 1f, 1f, 1f)
|
||||
panel.render(wrap, mouseXf, mouseYf, partialTick)
|
||||
val segments = ArrayList<LinePoint>()
|
||||
|
||||
panel.render(wrap, mouseXf, mouseYf, partialTick, segments)
|
||||
|
||||
if (segments.isNotEmpty()) {
|
||||
wrap.drawLine(0.5f, RGBAColor.GOLD, segments)
|
||||
}
|
||||
}
|
||||
|
||||
if (!panelsReversed.any { it.updateCursor0() })
|
||||
|
@ -13,11 +13,13 @@ import net.minecraft.client.gui.navigation.ScreenRectangle
|
||||
import net.minecraft.client.gui.screens.Screen
|
||||
import net.minecraft.network.chat.Component
|
||||
import org.apache.logging.log4j.LogManager
|
||||
import ru.dbotthepony.kommons.math.RGBAColor
|
||||
import ru.dbotthepony.mc.otm.SystemTime
|
||||
import ru.dbotthepony.mc.otm.client.CursorType
|
||||
import ru.dbotthepony.mc.otm.client.render.MGUIGraphics
|
||||
import ru.dbotthepony.mc.otm.client.minecraft
|
||||
import ru.dbotthepony.mc.otm.client.moveMousePosScaled
|
||||
import ru.dbotthepony.mc.otm.client.render.LinePoint
|
||||
import ru.dbotthepony.mc.otm.client.render.RenderGravity
|
||||
import ru.dbotthepony.mc.otm.client.render.currentScissorRect
|
||||
import ru.dbotthepony.mc.otm.client.render.popScissorRect
|
||||
@ -889,12 +891,11 @@ open class EditablePanel<out S : Screen>(
|
||||
}
|
||||
}
|
||||
|
||||
fun render(graphics: MGUIGraphics, mouseX: Float, mouseY: Float, partialTick: Float) {
|
||||
fun render(graphics: MGUIGraphics, mouseX: Float, mouseY: Float, partialTick: Float, debugSegments: MutableList<LinePoint>) {
|
||||
once = true
|
||||
|
||||
if (!isVisible()) {
|
||||
if (!isVisible())
|
||||
return
|
||||
}
|
||||
|
||||
val poseStack = graphics.pose
|
||||
|
||||
@ -942,12 +943,19 @@ open class EditablePanel<out S : Screen>(
|
||||
child.absoluteX = absoluteX + child.x + xOffset
|
||||
child.absoluteY = absoluteY + child.y + yOffset
|
||||
|
||||
child.render(graphics, mouseX, mouseY, partialTick)
|
||||
child.render(graphics, mouseX, mouseY, partialTick, debugSegments)
|
||||
}
|
||||
|
||||
if (scissor) {
|
||||
popScissorRect()
|
||||
}
|
||||
|
||||
if (minecraft.entityRenderDispatcher.shouldRenderHitBoxes()) {
|
||||
debugSegments.add(LinePoint(absoluteX, absoluteY, absoluteX + width, absoluteY))
|
||||
debugSegments.add(LinePoint(absoluteX + width, absoluteY, absoluteX + width, absoluteY + height))
|
||||
debugSegments.add(LinePoint(absoluteX + width, absoluteY + height, absoluteX, absoluteY + height))
|
||||
debugSegments.add(LinePoint(absoluteX, absoluteY + height, absoluteX, absoluteY))
|
||||
}
|
||||
}
|
||||
|
||||
fun updateCursor0(): Boolean {
|
||||
|
@ -4,6 +4,8 @@ import net.minecraft.client.gui.GuiGraphics
|
||||
import net.minecraft.client.gui.components.Renderable
|
||||
import net.minecraft.client.gui.components.events.GuiEventListener
|
||||
import net.minecraft.client.gui.screens.Screen
|
||||
import ru.dbotthepony.kommons.math.RGBAColor
|
||||
import ru.dbotthepony.mc.otm.client.render.LinePoint
|
||||
import ru.dbotthepony.mc.otm.client.render.MGUIGraphics
|
||||
|
||||
// before 1.19.3 Renderable was Widget
|
||||
@ -21,11 +23,17 @@ class Panel2Widget<out S: Screen, out P : EditablePanel<S>>(
|
||||
val yFloat = mouseY.toFloat()
|
||||
|
||||
val wrap = MGUIGraphics(graphics)
|
||||
val segments = ArrayList<LinePoint>()
|
||||
|
||||
panel.tickHovered0(xFloat, yFloat, false)
|
||||
panel.tickHovered1()
|
||||
panel.tickHovered2()
|
||||
panel.render(wrap, xFloat, yFloat, partialTick)
|
||||
panel.render(wrap, xFloat, yFloat, partialTick, segments)
|
||||
|
||||
if (segments.isNotEmpty()) {
|
||||
wrap.drawLine(0.5f, RGBAColor.GOLD, segments)
|
||||
}
|
||||
|
||||
panel.renderTooltips(wrap, xFloat, yFloat, partialTick)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user