Compare commits

..

2 Commits

Author SHA1 Message Date
mewhenthe
00b0014456 something more 2026-04-20 23:56:34 +02:00
mewhenthe
9de31e8c30 fix bug, I HATE MINECRAFT 2026-04-20 23:55:32 +02:00

View File

@@ -4,7 +4,9 @@ import com.mojang.blaze3d.systems.RenderSystem
import com.mojang.blaze3d.vertex.BufferBuilder import com.mojang.blaze3d.vertex.BufferBuilder
import com.mojang.blaze3d.vertex.BufferUploader import com.mojang.blaze3d.vertex.BufferUploader
import com.mojang.blaze3d.vertex.DefaultVertexFormat import com.mojang.blaze3d.vertex.DefaultVertexFormat
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.VertexFormat import com.mojang.blaze3d.vertex.VertexFormat
import net.minecraft.client.Minecraft import net.minecraft.client.Minecraft
import net.minecraft.client.gui.GuiGraphics import net.minecraft.client.gui.GuiGraphics
@@ -25,19 +27,17 @@ import kotlin.math.ceil
object ProgressBar { // TODO: variable length object ProgressBar { // TODO: variable length
val BAR: ResourceLocation = ResourceLocation.fromNamespaceAndPath(NeoComputers.MODID, "textures/gui/bar.png") val BAR: ResourceLocation = ResourceLocation.fromNamespaceAndPath(NeoComputers.MODID, "textures/gui/bar.png")
// val BAROLD: ResourceLocation = ResourceLocation.fromNamespaceAndPath(NeoComputers.MODID, "textures/gui/bar_old.png")
// val font: Font = Minecraft.getInstance().font
fun render(guiGraphics: GuiGraphics, x: Int, y: Int, value: Long, max: Long, mouseX: Int, mouseY: Int, width: Int=142, height: Int=14, tooltipfunc: (Int) -> String?) { // NOTE: OC never uses a different width and height, changing height is not recommended // NOTE: OC never uses a different width and height, changing height is not recommended
// RenderSystem.setShader { GameRenderer.getPositionTexShader() } fun render(guiGraphics: GuiGraphics, x: Int, y: Int, value: Long, max: Long, mouseX: Int, mouseY: Int, width: Int=142, height: Int=14, tooltipfunc: (Int) -> String?) {
// RenderSystem.setShaderTexture(0, BAROLD) guiGraphics.blit(BAR, x, y, 1, height, 0F, 0F, 1, 14, 3, 14)
// drawQuad(x, y, width, height, 0F, 0F, 15F, 15F) guiGraphics.blit(BAR, x+1, y, width-2, height, 1F, 0F, 1, 14, 3, 14)
renderEmptyBar(x, y, width, height) guiGraphics.blit(BAR, x+width-1, y, 1, height, 2F, 0F, 1, 14, 3, 14)
val frac = value.toFloat() / max.toFloat() val frac = value.toFloat() / max.toFloat()
val linew = ceil(frac*(width-2).toFloat()) val linew = ceil(frac*(width-2).toFloat())
guiGraphics.fill( guiGraphics.fill(
RenderType.guiOverlay(), RenderType.gui(),
x + 1, x + 1,
y + 1, y + 1,
x + 1 + (linew.toInt()), x + 1 + (linew.toInt()),
@@ -45,29 +45,9 @@ object ProgressBar { // TODO: variable length
0xFF66CC66.toInt() 0xFF66CC66.toInt()
) )
val tooltip = tooltipfunc((ceil(frac) * 100F).toInt()) ?: return val tooltip = tooltipfunc((ceil(frac * 100F)).toInt()) ?: return
if (mouseX > x && mouseX < x+width && mouseY > y && mouseY < y+height ) if (mouseX > x && mouseX < x+width && mouseY > y && mouseY < y+height )
guiGraphics.renderTooltip(Minecraft.getInstance().font, Component.literal(tooltip), mouseX, mouseY) guiGraphics.renderTooltip(Minecraft.getInstance().font, Component.literal(tooltip), mouseX, mouseY)
} }
private fun renderEmptyBar(x: Int, y: Int, width: Int, height: Int) {
RenderSystem.setShader { GameRenderer.getPositionTexShader() }
RenderSystem.setShaderTexture(0, BAR)
drawQuad(x, y, 1, height, 0F, 0F, 1F, 14F, 3F, 14F)
drawQuad(x+1, y, width-2, height, 1F, 0F, 2F, 14F, 3F, 14F)
drawQuad(x+width-1, y, 1, height, 2F, 0F, 3F, 14F, 3F, 14F)
}
private fun drawQuad(x: Int, y: Int, width: Int, height: Int, u1: Float, v1: Float, u2: Float, v2: Float, texwidth: Float=15F, texheight: Float=15F) { // this should really become a util func
var t: Tesselator = Tesselator.getInstance()
var builder: BufferBuilder = t.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX)
builder.addVertex(x.toFloat(), (y+height).toFloat(), 1f).setUv(u1/texwidth, v2/texheight)
builder.addVertex((x+width).toFloat(), (y+height).toFloat(), 1f).setUv(u2/texwidth, v2/texheight)
builder.addVertex((x+width).toFloat(), y.toFloat(), 1f).setUv(u2/texwidth, v1/texheight)
builder.addVertex(x.toFloat(), y.toFloat(), 1f).setUv(u1/texwidth,v1/texheight)
BufferUploader.drawWithShader(builder.build()!!)
}
} }