aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/features/inventory/buttons
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2025-11-17 19:55:02 +0100
committerLinnea Gräf <nea@nea.moe>2025-11-17 19:55:02 +0100
commitc93a04a001b0f66b2724d46b04b6d1ed49a08d07 (patch)
tree5869ca70acc482ef0362f27785c3d3f1cbb9ffae /src/main/kotlin/features/inventory/buttons
parentaf9893b59407c69d31ebd2ed513f0396ab4d2dc9 (diff)
downloadFirmament-c93a04a001b0f66b2724d46b04b6d1ed49a08d07.tar.gz
Firmament-c93a04a001b0f66b2724d46b04b6d1ed49a08d07.tar.bz2
Firmament-c93a04a001b0f66b2724d46b04b6d1ed49a08d07.zip
refactor: port to mojmaps
Diffstat (limited to 'src/main/kotlin/features/inventory/buttons')
-rw-r--r--src/main/kotlin/features/inventory/buttons/InventoryButton.kt42
-rw-r--r--src/main/kotlin/features/inventory/buttons/InventoryButtonEditor.kt116
-rw-r--r--src/main/kotlin/features/inventory/buttons/InventoryButtonTemplates.kt4
-rw-r--r--src/main/kotlin/features/inventory/buttons/InventoryButtons.kt30
4 files changed, 96 insertions, 96 deletions
diff --git a/src/main/kotlin/features/inventory/buttons/InventoryButton.kt b/src/main/kotlin/features/inventory/buttons/InventoryButton.kt
index e31f4a0..0cb51ca 100644
--- a/src/main/kotlin/features/inventory/buttons/InventoryButton.kt
+++ b/src/main/kotlin/features/inventory/buttons/InventoryButton.kt
@@ -5,14 +5,14 @@ import me.shedaniel.math.Dimension
import me.shedaniel.math.Point
import me.shedaniel.math.Rectangle
import kotlinx.serialization.Serializable
-import net.minecraft.client.gl.RenderPipelines
-import net.minecraft.client.gui.DrawContext
-import net.minecraft.command.CommandRegistryAccess
-import net.minecraft.command.argument.ItemStackArgumentType
-import net.minecraft.item.ItemStack
-import net.minecraft.item.Items
-import net.minecraft.resource.featuretoggle.FeatureFlags
-import net.minecraft.util.Identifier
+import net.minecraft.client.renderer.RenderPipelines
+import net.minecraft.client.gui.GuiGraphics
+import net.minecraft.commands.CommandBuildContext
+import net.minecraft.commands.arguments.item.ItemArgument
+import net.minecraft.world.item.ItemStack
+import net.minecraft.world.item.Items
+import net.minecraft.world.flag.FeatureFlags
+import net.minecraft.resources.ResourceLocation
import moe.nea.firmament.repo.ExpensiveItemCacheApi
import moe.nea.firmament.repo.ItemCache.asItemStack
import moe.nea.firmament.repo.ItemCache.isBroken
@@ -40,10 +40,10 @@ data class InventoryButton(
companion object {
val itemStackParser by lazy {
- ItemStackArgumentType.itemStack(
- CommandRegistryAccess.of(
+ ItemArgument.item(
+ CommandBuildContext.simple(
MC.defaultRegistries,
- FeatureFlags.VANILLA_FEATURES
+ FeatureFlags.VANILLA_SET
)
)
}
@@ -71,7 +71,7 @@ data class InventoryButton(
else icon
val componentItem =
runCatching {
- itemStackParser.parse(StringReader(giveSyntaxItem)).createStack(1, false)
+ itemStackParser.parse(StringReader(giveSyntaxItem)).createItemStack(1, false)
}.getOrNull()
if (componentItem != null)
itemStack = componentItem
@@ -84,23 +84,23 @@ data class InventoryButton(
}
}
- fun render(context: DrawContext) {
- context.drawGuiTexture(
+ fun render(context: GuiGraphics) {
+ context.blitSprite(
RenderPipelines.GUI_TEXTURED,
- Identifier.of("firmament:inventory_button_background"),
+ ResourceLocation.parse("firmament:inventory_button_background"),
0,
0,
myDimension.width,
myDimension.height,
)
if (isGigantic) {
- context.matrices.pushMatrix()
- context.matrices.translate(myDimension.width / 2F, myDimension.height / 2F)
- context.matrices.scale(2F)
- context.drawItem(getItem(), -8, -8)
- context.matrices.popMatrix()
+ context.pose().pushMatrix()
+ context.pose().translate(myDimension.width / 2F, myDimension.height / 2F)
+ context.pose().scale(2F)
+ context.renderItem(getItem(), -8, -8)
+ context.pose().popMatrix()
} else {
- context.drawItem(getItem(), 1, 1)
+ context.renderItem(getItem(), 1, 1)
}
}
diff --git a/src/main/kotlin/features/inventory/buttons/InventoryButtonEditor.kt b/src/main/kotlin/features/inventory/buttons/InventoryButtonEditor.kt
index d5d291c..6b6a2d6 100644
--- a/src/main/kotlin/features/inventory/buttons/InventoryButtonEditor.kt
+++ b/src/main/kotlin/features/inventory/buttons/InventoryButtonEditor.kt
@@ -8,17 +8,17 @@ import io.github.notenoughupdates.moulconfig.xml.Bind
import me.shedaniel.math.Point
import me.shedaniel.math.Rectangle
import org.lwjgl.glfw.GLFW
-import net.minecraft.client.MinecraftClient
-import net.minecraft.client.gui.Click
-import net.minecraft.client.gui.DrawContext
-import net.minecraft.client.gui.widget.ButtonWidget
-import net.minecraft.client.gui.widget.MultilineTextWidget
-import net.minecraft.client.gui.widget.TextWidget
-import net.minecraft.client.input.KeyInput
-import net.minecraft.client.util.InputUtil
-import net.minecraft.text.Text
-import net.minecraft.util.math.MathHelper
-import net.minecraft.util.math.Vec2f
+import net.minecraft.client.Minecraft
+import net.minecraft.client.input.MouseButtonEvent
+import net.minecraft.client.gui.GuiGraphics
+import net.minecraft.client.gui.components.Button
+import net.minecraft.client.gui.components.MultiLineTextWidget
+import net.minecraft.client.gui.components.StringWidget
+import net.minecraft.client.input.KeyEvent
+import com.mojang.blaze3d.platform.InputConstants
+import net.minecraft.network.chat.Component
+import net.minecraft.util.Mth
+import net.minecraft.world.phys.Vec2
import moe.nea.firmament.util.ClipboardUtils
import moe.nea.firmament.util.FragmentGuiScreen
import moe.nea.firmament.util.MC
@@ -60,69 +60,69 @@ class InventoryButtonEditor(
var buttons: MutableList<InventoryButton> =
InventoryButtons.DConfig.data.buttons.map { it.copy() }.toMutableList()
- override fun close() {
+ override fun onClose() {
InventoryButtons.DConfig.data.buttons = buttons
InventoryButtons.DConfig.markDirty()
- super.close()
+ super.onClose()
}
- override fun resize(client: MinecraftClient, width: Int, height: Int) {
+ override fun resize(client: Minecraft, width: Int, height: Int) {
lastGuiRect.move(
- MC.window.scaledWidth / 2 - lastGuiRect.width / 2,
- MC.window.scaledHeight / 2 - lastGuiRect.height / 2
+ MC.window.guiScaledWidth / 2 - lastGuiRect.width / 2,
+ MC.window.guiScaledHeight / 2 - lastGuiRect.height / 2
)
super.resize(client, width, height)
}
override fun init() {
super.init()
- addDrawableChild(
- MultilineTextWidget(
+ addRenderableWidget(
+ MultiLineTextWidget(
lastGuiRect.minX,
25,
- Text.translatable("firmament.inventory-buttons.delete"),
+ Component.translatable("firmament.inventory-buttons.delete"),
MC.font
).setCentered(true).setMaxWidth(lastGuiRect.width)
)
- addDrawableChild(
- MultilineTextWidget(
+ addRenderableWidget(
+ MultiLineTextWidget(
lastGuiRect.minX,
40,
- Text.translatable("firmament.inventory-buttons.info"),
+ Component.translatable("firmament.inventory-buttons.info"),
MC.font
).setCentered(true).setMaxWidth(lastGuiRect.width)
)
- addDrawableChild(
- ButtonWidget.builder(Text.translatable("firmament.inventory-buttons.reset")) {
+ addRenderableWidget(
+ Button.builder(Component.translatable("firmament.inventory-buttons.reset")) {
val newButtons = InventoryButtonTemplates.loadTemplate("TkVVQlVUVE9OUy9bXQ==")
if (newButtons != null)
buttons = moveButtons(newButtons.map { it.copy(command = it.command?.removePrefix("/")) })
}
- .position(lastGuiRect.minX + 10, lastGuiRect.minY + 10)
+ .pos(lastGuiRect.minX + 10, lastGuiRect.minY + 10)
.width(lastGuiRect.width - 20)
.build()
)
- addDrawableChild(
- ButtonWidget.builder(Text.translatable("firmament.inventory-buttons.load-preset")) {
+ addRenderableWidget(
+ Button.builder(Component.translatable("firmament.inventory-buttons.load-preset")) {
val t = ClipboardUtils.getTextContents()
val newButtons = InventoryButtonTemplates.loadTemplate(t)
if (newButtons != null)
buttons = moveButtons(newButtons.map { it.copy(command = it.command?.removePrefix("/")) })
}
- .position(lastGuiRect.minX + 10, lastGuiRect.minY + 35)
+ .pos(lastGuiRect.minX + 10, lastGuiRect.minY + 35)
.width(lastGuiRect.width - 20)
.build()
)
- addDrawableChild(
- ButtonWidget.builder(Text.translatable("firmament.inventory-buttons.save-preset")) {
+ addRenderableWidget(
+ Button.builder(Component.translatable("firmament.inventory-buttons.save-preset")) {
ClipboardUtils.setTextContent(InventoryButtonTemplates.saveTemplate(buttons))
}
- .position(lastGuiRect.minX + 10, lastGuiRect.minY + 60)
+ .pos(lastGuiRect.minX + 10, lastGuiRect.minY + 60)
.width(lastGuiRect.width - 20)
.build()
)
- addDrawableChild(
- ButtonWidget.builder(Text.translatable("firmament.inventory-buttons.simple-preset")) {
+ addRenderableWidget(
+ Button.builder(Component.translatable("firmament.inventory-buttons.simple-preset")) {
// Preset from NEU
// Credit: https://github.com/NotEnoughUpdates/NotEnoughUpdates/blob/9b1fcfebc646e9fb69f99006327faa3e734e5f51/src/main/resources/assets/notenoughupdates/invbuttons/presets.json#L900-L1348
val newButtons = InventoryButtonTemplates.loadTemplate(
@@ -131,12 +131,12 @@ class InventoryButtonEditor(
if (newButtons != null)
buttons = moveButtons(newButtons.map { it.copy(command = it.command?.removePrefix("/")) })
}
- .position(lastGuiRect.minX + 10, lastGuiRect.minY + 85)
+ .pos(lastGuiRect.minX + 10, lastGuiRect.minY + 85)
.width(lastGuiRect.width - 20)
.build()
)
- addDrawableChild(
- ButtonWidget.builder(Text.translatable("firmament.inventory-buttons.all-warps-preset")) {
+ addRenderableWidget(
+ Button.builder(Component.translatable("firmament.inventory-buttons.all-warps-preset")) {
// Preset from NEU
// Credit: https://github.com/NotEnoughUpdates/NotEnoughUpdates/blob/9b1fcfebc646e9fb69f99006327faa3e734e5f51/src/main/resources/assets/notenoughupdates/invbuttons/presets.json#L1817-L2276
val newButtons = InventoryButtonTemplates.loadTemplate(
@@ -145,7 +145,7 @@ class InventoryButtonEditor(
if (newButtons != null)
buttons = moveButtons(newButtons.map { it.copy(command = it.command?.removePrefix("/")) })
}
- .position(lastGuiRect.minX + 10, lastGuiRect.minY + 110)
+ .pos(lastGuiRect.minX + 10, lastGuiRect.minY + 110)
.width(lastGuiRect.width - 20)
.build()
)
@@ -195,42 +195,42 @@ class InventoryButtonEditor(
return newButtons
}
- override fun render(context: DrawContext, mouseX: Int, mouseY: Int, delta: Float) {
- context.matrices.pushMatrix()
+ override fun render(context: GuiGraphics, mouseX: Int, mouseY: Int, delta: Float) {
+ context.pose().pushMatrix()
PanelComponent.DefaultBackgroundRenderer.VANILLA
.render(
MoulConfigRenderContext(context),
lastGuiRect.minX, lastGuiRect.minY,
lastGuiRect.width, lastGuiRect.height,
)
- context.matrices.popMatrix()
+ context.pose().popMatrix()
super.render(context, mouseX, mouseY, delta)
for (button in buttons) {
val buttonPosition = button.getBounds(lastGuiRect)
- context.matrices.pushMatrix()
- context.matrices.translate(buttonPosition.minX.toFloat(), buttonPosition.minY.toFloat())
+ context.pose().pushMatrix()
+ context.pose().translate(buttonPosition.minX.toFloat(), buttonPosition.minY.toFloat())
button.render(context)
- context.matrices.popMatrix()
+ context.pose().popMatrix()
}
renderPopup(context, mouseX, mouseY, delta)
}
- override fun keyPressed(input: KeyInput): Boolean {
+ override fun keyPressed(input: KeyEvent): Boolean {
if (super.keyPressed(input)) return true
- if (input.keycode == GLFW.GLFW_KEY_ESCAPE) {
- close()
+ if (input.input() == GLFW.GLFW_KEY_ESCAPE) {
+ onClose()
return true
}
return false
}
- override fun mouseReleased(click: Click): Boolean {
+ override fun mouseReleased(click: MouseButtonEvent): Boolean {
if (super.mouseReleased(click)) return true
val clickedButton = buttons.firstOrNull { it.getBounds(lastGuiRect).contains(Point(click.x, click.y)) }
if (clickedButton != null && !justPerformedAClickAction) {
- if (InputUtil.isKeyPressed(
+ if (InputConstants.isKeyDown(
MC.window,
- InputUtil.GLFW_KEY_LEFT_CONTROL
+ InputConstants.KEY_LCONTROL
)
) Editor(clickedButton).delete()
else createPopup(
@@ -244,11 +244,11 @@ class InventoryButtonEditor(
return false
}
- override fun mouseDragged(click: Click, offsetX: Double, offsetY: Double): Boolean {
+ override fun mouseDragged(click: MouseButtonEvent, offsetX: Double, offsetY: Double): Boolean {
if (super.mouseDragged(click, offsetX, offsetY)) return true
- if (initialDragMousePosition.distanceSquared(Vec2f(click.x.toFloat(), click.y.toFloat())) >= 4 * 4) {
- initialDragMousePosition = Vec2f(-10F, -10F)
+ if (initialDragMousePosition.distanceToSqr(Vec2(click.x.toFloat(), click.y.toFloat())) >= 4 * 4) {
+ initialDragMousePosition = Vec2(-10F, -10F)
lastDraggedButton?.let { dragging ->
justPerformedAClickAction = true
val (anchorRight, anchorBottom, offsetX, offsetY) = getCoordsForMouse(click.x.toInt(), click.y.toInt())
@@ -272,7 +272,7 @@ class InventoryButtonEditor(
var lastDraggedButton: InventoryButton? = null
var justPerformedAClickAction = false
- var initialDragMousePosition = Vec2f(-10F, -10F)
+ var initialDragMousePosition = Vec2(-10F, -10F)
data class AnchoredCoords(
val anchorRight: Boolean,
@@ -286,9 +286,9 @@ class InventoryButtonEditor(
val anchorBottom = my > lastGuiRect.maxY
var offsetX = mx - if (anchorRight) lastGuiRect.maxX else lastGuiRect.minX
var offsetY = my - if (anchorBottom) lastGuiRect.maxY else lastGuiRect.minY
- if (InputUtil.isKeyPressed(MC.window, InputUtil.GLFW_KEY_LEFT_SHIFT)) {
- offsetX = MathHelper.floor(offsetX / 20F) * 20
- offsetY = MathHelper.floor(offsetY / 20F) * 20
+ if (InputConstants.isKeyDown(MC.window, InputConstants.KEY_LSHIFT)) {
+ offsetX = Mth.floor(offsetX / 20F) * 20
+ offsetY = Mth.floor(offsetY / 20F) * 20
}
val rect = InventoryButton(offsetX, offsetY, anchorRight, anchorBottom).getBounds(lastGuiRect)
if (rect.intersects(lastGuiRect)) return null
@@ -296,12 +296,12 @@ class InventoryButtonEditor(
return anchoredCoords
}
- override fun mouseClicked(click: Click, doubled: Boolean): Boolean {
+ override fun mouseClicked(click: MouseButtonEvent, doubled: Boolean): Boolean {
if (super.mouseClicked(click, doubled)) return true
val clickedButton = buttons.firstOrNull { it.getBounds(lastGuiRect).contains(click.x, click.y) }
if (clickedButton != null) {
lastDraggedButton = clickedButton
- initialDragMousePosition = Vec2f(click.y.toFloat(), click.y.toFloat())
+ initialDragMousePosition = Vec2(click.y.toFloat(), click.y.toFloat())
return true
}
val mx = click.x.toInt()
diff --git a/src/main/kotlin/features/inventory/buttons/InventoryButtonTemplates.kt b/src/main/kotlin/features/inventory/buttons/InventoryButtonTemplates.kt
index 082673e..c6ad14d 100644
--- a/src/main/kotlin/features/inventory/buttons/InventoryButtonTemplates.kt
+++ b/src/main/kotlin/features/inventory/buttons/InventoryButtonTemplates.kt
@@ -1,6 +1,6 @@
package moe.nea.firmament.features.inventory.buttons
-import net.minecraft.text.Text
+import net.minecraft.network.chat.Component
import moe.nea.firmament.Firmament
import moe.nea.firmament.util.ErrorUtil
import moe.nea.firmament.util.MC
@@ -17,7 +17,7 @@ object InventoryButtonTemplates {
ErrorUtil.catch<InventoryButton?>("Could not import button") {
Firmament.json.decodeFromString<InventoryButton>(it).also {
if (it.icon?.startsWith("extra:") == true) {
- MC.sendChat(Text.translatable("firmament.inventory-buttons.import-failed"))
+ MC.sendChat(Component.translatable("firmament.inventory-buttons.import-failed"))
}
}
}.or {
diff --git a/src/main/kotlin/features/inventory/buttons/InventoryButtons.kt b/src/main/kotlin/features/inventory/buttons/InventoryButtons.kt
index 47fdbe9..fa376bc 100644
--- a/src/main/kotlin/features/inventory/buttons/InventoryButtons.kt
+++ b/src/main/kotlin/features/inventory/buttons/InventoryButtons.kt
@@ -4,9 +4,9 @@ import me.shedaniel.math.Rectangle
import kotlinx.serialization.Serializable
import kotlinx.serialization.serializer
import kotlin.time.Duration.Companion.seconds
-import net.minecraft.client.gui.screen.ingame.HandledScreen
-import net.minecraft.client.gui.screen.ingame.InventoryScreen
-import net.minecraft.text.Text
+import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen
+import net.minecraft.client.gui.screens.inventory.InventoryScreen
+import net.minecraft.network.chat.Component
import moe.nea.firmament.annotations.Subscribe
import moe.nea.firmament.events.HandledScreenClickEvent
import moe.nea.firmament.events.HandledScreenForegroundEvent
@@ -14,7 +14,7 @@ import moe.nea.firmament.events.HandledScreenPushREIEvent
import moe.nea.firmament.util.MC
import moe.nea.firmament.util.ScreenUtil
import moe.nea.firmament.util.TimeMark
-import moe.nea.firmament.util.accessors.getRectangle
+import moe.nea.firmament.util.accessors.getProperRectangle
import moe.nea.firmament.util.data.Config
import moe.nea.firmament.util.data.DataHolder
import moe.nea.firmament.util.data.ManagedConfig
@@ -39,7 +39,7 @@ object InventoryButtons {
var buttons: MutableList<InventoryButton> = mutableListOf()
)
- fun getValidButtons(screen: HandledScreen<*>): Sequence<InventoryButton> {
+ fun getValidButtons(screen: AbstractContainerScreen<*>): Sequence<InventoryButton> {
return DConfig.data.buttons.asSequence().filter { button ->
button.isValid() && (!TConfig.onlyInv || screen is InventoryScreen)
}
@@ -48,7 +48,7 @@ object InventoryButtons {
@Subscribe
fun onRectangles(it: HandledScreenPushREIEvent) {
- val bounds = it.screen.getRectangle()
+ val bounds = it.screen.getProperRectangle()
for (button in getValidButtons(it.screen)) {
val buttonBounds = button.getBounds(bounds)
it.block(buttonBounds)
@@ -57,7 +57,7 @@ object InventoryButtons {
@Subscribe
fun onClickScreen(it: HandledScreenClickEvent) {
- val bounds = it.screen.getRectangle()
+ val bounds = it.screen.getProperRectangle()
for (button in getValidButtons(it.screen)) {
val buttonBounds = button.getBounds(bounds)
if (buttonBounds.contains(it.mouseX, it.mouseY)) {
@@ -72,22 +72,22 @@ object InventoryButtons {
@Subscribe
fun onRenderForeground(it: HandledScreenForegroundEvent) {
- val bounds = it.screen.getRectangle()
+ val bounds = it.screen.getProperRectangle()
var hoveredComponent: InventoryButton? = null
for (button in getValidButtons(it.screen)) {
val buttonBounds = button.getBounds(bounds)
- it.context.matrices.pushMatrix()
- it.context.matrices.translate(buttonBounds.minX.toFloat(), buttonBounds.minY.toFloat())
+ it.context.pose().pushMatrix()
+ it.context.pose().translate(buttonBounds.minX.toFloat(), buttonBounds.minY.toFloat())
button.render(it.context)
- it.context.matrices.popMatrix()
+ it.context.pose().popMatrix()
if (buttonBounds.contains(it.mouseX, it.mouseY) && TConfig.hoverText && hoveredComponent == null) {
hoveredComponent = button
if (lastMouseMove.passedTime() > 0.6.seconds && lastHoveredComponent === button) {
- it.context.drawTooltip(
+ it.context.setComponentTooltipForNextFrame(
MC.font,
- listOf(Text.literal(button.command).gold()),
+ listOf(Component.literal(button.command).gold()),
buttonBounds.minX - 15,
buttonBounds.maxY + 20,
)
@@ -105,8 +105,8 @@ object InventoryButtons {
ScreenUtil.setScreenLater(
InventoryButtonEditor(
lastRectangle ?: Rectangle(
- MC.window.scaledWidth / 2 - 88,
- MC.window.scaledHeight / 2 - 83,
+ MC.window.guiScaledWidth / 2 - 88,
+ MC.window.guiScaledHeight / 2 - 83,
176, 166,
)
)