aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/features/inventory
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/features/inventory')
-rw-r--r--src/main/kotlin/features/inventory/CraftingOverlay.kt26
-rw-r--r--src/main/kotlin/features/inventory/ItemRarityCosmetics.kt18
-rw-r--r--src/main/kotlin/features/inventory/JunkHighlighter.kt2
-rw-r--r--src/main/kotlin/features/inventory/PetFeatures.kt134
-rw-r--r--src/main/kotlin/features/inventory/PriceData.kt18
-rw-r--r--src/main/kotlin/features/inventory/REIDependencyWarner.kt26
-rw-r--r--src/main/kotlin/features/inventory/SaveCursorPosition.kt6
-rw-r--r--src/main/kotlin/features/inventory/SlotLocking.kt128
-rw-r--r--src/main/kotlin/features/inventory/TimerInLore.kt12
-rw-r--r--src/main/kotlin/features/inventory/WardrobeKeybinds.kt12
-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
-rw-r--r--src/main/kotlin/features/inventory/storageoverlay/StorageBackingHandle.kt20
-rw-r--r--src/main/kotlin/features/inventory/storageoverlay/StorageOverlay.kt30
-rw-r--r--src/main/kotlin/features/inventory/storageoverlay/StorageOverlayCustom.kt52
-rw-r--r--src/main/kotlin/features/inventory/storageoverlay/StorageOverlayScreen.kt142
-rw-r--r--src/main/kotlin/features/inventory/storageoverlay/StorageOverviewScreen.kt54
-rw-r--r--src/main/kotlin/features/inventory/storageoverlay/VirtualInventory.kt22
20 files changed, 447 insertions, 447 deletions
diff --git a/src/main/kotlin/features/inventory/CraftingOverlay.kt b/src/main/kotlin/features/inventory/CraftingOverlay.kt
index 30d2c6b..5241f54 100644
--- a/src/main/kotlin/features/inventory/CraftingOverlay.kt
+++ b/src/main/kotlin/features/inventory/CraftingOverlay.kt
@@ -1,9 +1,9 @@
package moe.nea.firmament.features.inventory
import io.github.moulberry.repo.data.NEUCraftingRecipe
-import net.minecraft.client.gui.screen.ingame.GenericContainerScreen
-import net.minecraft.item.ItemStack
-import net.minecraft.util.Formatting
+import net.minecraft.client.gui.screens.inventory.ContainerScreen
+import net.minecraft.world.item.ItemStack
+import net.minecraft.ChatFormatting
import moe.nea.firmament.annotations.Subscribe
import moe.nea.firmament.events.ScreenChangeEvent
import moe.nea.firmament.events.SlotRenderEvents
@@ -14,7 +14,7 @@ import moe.nea.firmament.util.skyblockId
object CraftingOverlay {
- private var screen: GenericContainerScreen? = null
+ private var screen: ContainerScreen? = null
private var recipe: NEUCraftingRecipe? = null
private var useNextScreen = false
private val craftingOverlayIndices = listOf(
@@ -24,7 +24,7 @@ object CraftingOverlay {
)
val CRAFTING_SCREEN_NAME = "Craft Item"
- fun setOverlay(screen: GenericContainerScreen?, recipe: NEUCraftingRecipe) {
+ fun setOverlay(screen: ContainerScreen?, recipe: NEUCraftingRecipe) {
this.screen = screen
if (screen == null) {
useNextScreen = true
@@ -34,7 +34,7 @@ object CraftingOverlay {
@Subscribe
fun onScreenChange(event: ScreenChangeEvent) {
- if (useNextScreen && event.new is GenericContainerScreen
+ if (useNextScreen && event.new is ContainerScreen
&& event.new.title?.string == "Craft Item"
) {
useNextScreen = false
@@ -50,11 +50,11 @@ object CraftingOverlay {
fun onSlotRender(event: SlotRenderEvents.After) {
val slot = event.slot
val recipe = this.recipe ?: return
- if (slot.inventory != screen?.screenHandler?.inventory) return
- val recipeIndex = craftingOverlayIndices.indexOf(slot.index)
+ if (slot.container != screen?.menu?.container) return
+ val recipeIndex = craftingOverlayIndices.indexOf(slot.containerSlot)
if (recipeIndex < 0) return
val expectedItem = recipe.inputs[recipeIndex]
- val actualStack = slot.stack ?: ItemStack.EMPTY!!
+ val actualStack = slot.item ?: ItemStack.EMPTY!!
val actualEntry = SBItemStack(actualStack)
if ((actualEntry.skyblockId != expectedItem.skyblockId || actualEntry.getStackSize() < expectedItem.amount)
&& expectedItem.amount.toInt() != 0
@@ -67,15 +67,15 @@ object CraftingOverlay {
0x80FF0000.toInt()
)
}
- if (!slot.hasStack()) {
+ if (!slot.hasItem()) {
val itemStack = SBItemStack(expectedItem)?.asImmutableItemStack() ?: return
- event.context.drawItem(itemStack, event.slot.x, event.slot.y)
- event.context.drawStackOverlay(
+ event.context.renderItem(itemStack, event.slot.x, event.slot.y)
+ event.context.renderItemDecorations(
MC.font,
itemStack,
event.slot.x,
event.slot.y,
- "${Formatting.RED}${expectedItem.amount.toInt()}"
+ "${ChatFormatting.RED}${expectedItem.amount.toInt()}"
)
}
}
diff --git a/src/main/kotlin/features/inventory/ItemRarityCosmetics.kt b/src/main/kotlin/features/inventory/ItemRarityCosmetics.kt
index 7a474f9..9712067 100644
--- a/src/main/kotlin/features/inventory/ItemRarityCosmetics.kt
+++ b/src/main/kotlin/features/inventory/ItemRarityCosmetics.kt
@@ -1,10 +1,10 @@
package moe.nea.firmament.features.inventory
import java.awt.Color
-import net.minecraft.client.gl.RenderPipelines
-import net.minecraft.client.gui.DrawContext
-import net.minecraft.item.ItemStack
-import net.minecraft.util.Identifier
+import net.minecraft.client.renderer.RenderPipelines
+import net.minecraft.client.gui.GuiGraphics
+import net.minecraft.world.item.ItemStack
+import net.minecraft.resources.ResourceLocation
import moe.nea.firmament.annotations.Subscribe
import moe.nea.firmament.events.HotbarItemRenderEvent
import moe.nea.firmament.events.SlotRenderEvents
@@ -23,16 +23,16 @@ object ItemRarityCosmetics {
}
private val rarityToColor = Rarity.colourMap.mapValues {
- val c = Color(it.value.colorValue!!)
+ val c = Color(it.value.color!!)
c.rgb
}
- fun drawItemStackRarity(drawContext: DrawContext, x: Int, y: Int, item: ItemStack) {
+ fun drawItemStackRarity(drawContext: GuiGraphics, x: Int, y: Int, item: ItemStack) {
val rarity = Rarity.fromItem(item) ?: return
val rgb = rarityToColor[rarity] ?: 0xFF00FF80.toInt()
- drawContext.drawGuiTexture(
+ drawContext.blitSprite(
RenderPipelines.GUI_TEXTURED,
- Identifier.of("firmament:item_rarity_background"),
+ ResourceLocation.parse("firmament:item_rarity_background"),
x, y,
16, 16,
rgb
@@ -43,7 +43,7 @@ object ItemRarityCosmetics {
@Subscribe
fun onRenderSlot(it: SlotRenderEvents.Before) {
if (!TConfig.showItemRarityBackground) return
- val stack = it.slot.stack ?: return
+ val stack = it.slot.item ?: return
drawItemStackRarity(it.context, it.slot.x, it.slot.y, stack)
}
diff --git a/src/main/kotlin/features/inventory/JunkHighlighter.kt b/src/main/kotlin/features/inventory/JunkHighlighter.kt
index 45d265e..15bdcfa 100644
--- a/src/main/kotlin/features/inventory/JunkHighlighter.kt
+++ b/src/main/kotlin/features/inventory/JunkHighlighter.kt
@@ -23,7 +23,7 @@ object JunkHighlighter {
if (!TConfig.highlightBind.isPressed() || TConfig.junkRegex.isEmpty()) return
val junkRegex = TConfig.junkRegex.toPattern()
val slot = event.slot
- junkRegex.useMatch(slot.stack.getSearchName()) {
+ junkRegex.useMatch(slot.item.getSearchName()) {
event.context.fill(slot.x, slot.y, slot.x + 16, slot.y + 16, 0xffff0000.toInt())
}
}
diff --git a/src/main/kotlin/features/inventory/PetFeatures.kt b/src/main/kotlin/features/inventory/PetFeatures.kt
index 646989c..e0bb4b1 100644
--- a/src/main/kotlin/features/inventory/PetFeatures.kt
+++ b/src/main/kotlin/features/inventory/PetFeatures.kt
@@ -2,11 +2,11 @@ package moe.nea.firmament.features.inventory
import java.util.regex.Matcher
import org.joml.Vector2i
-import net.minecraft.entity.player.PlayerInventory
-import net.minecraft.item.ItemStack
-import net.minecraft.text.Text
-import net.minecraft.util.Formatting
-import net.minecraft.util.StringIdentifiable
+import net.minecraft.world.entity.player.Inventory
+import net.minecraft.world.item.ItemStack
+import net.minecraft.network.chat.Component
+import net.minecraft.ChatFormatting
+import net.minecraft.util.StringRepresentable
import moe.nea.firmament.Firmament
import moe.nea.firmament.annotations.Subscribe
import moe.nea.firmament.events.HudRenderEvent
@@ -52,14 +52,14 @@ object PetFeatures {
val petOverlayHudStyle by choice("pet-overlay-hud-style") { PetOverlayHudStyles.PLAIN_NO_BACKGROUND }
}
- enum class PetOverlayHudStyles : StringIdentifiable {
+ enum class PetOverlayHudStyles : StringRepresentable {
PLAIN_NO_BACKGROUND,
COLOUR_NO_BACKGROUND,
PLAIN_BACKGROUND,
COLOUR_BACKGROUND,
ICON_ONLY;
- override fun asString() : String {
+ override fun getSerializedName() : String {
return name
}
}
@@ -86,7 +86,7 @@ object PetFeatures {
fun onSlotRender(event: SlotRenderEvents.Before) {
// Cache pets
petMenuTitle.useMatch(MC.screenName ?: return) {
- val stack = event.slot.stack
+ val stack = event.slot.item
if (!stack.isEmpty) cachePet(stack)
if (stack.petData?.active == true) {
if (currentPetUUID == "") currentPetUUID = stack.skyblockUUID.toString()
@@ -114,7 +114,7 @@ object PetFeatures {
fun onSlotClick(event: SlotClickEvent) {
// Check for switching/removing pet manually
petMenuTitle.useMatch(MC.screenName ?: return) {
- if (event.slot.inventory is PlayerInventory) return
+ if (event.slot.container is Inventory) return
if (event.button != 0 && event.button != 1) return
val petData = event.stack.petData ?: return
if (petData.active == true) {
@@ -175,23 +175,23 @@ object PetFeatures {
}
}
- private fun renderLinesAndBackground(it: HudRenderEvent, lines: List<Text>) {
+ private fun renderLinesAndBackground(it: HudRenderEvent, lines: List<Component>) {
// Render background for the hud
if (TConfig.petOverlayHudStyle == PetOverlayHudStyles.PLAIN_BACKGROUND ||
TConfig.petOverlayHudStyle == PetOverlayHudStyles.COLOUR_BACKGROUND) {
var maxWidth = 0
- lines.forEach { if (MC.font.getWidth(it) > maxWidth) maxWidth = MC.font.getWidth(it.unformattedString) }
- val height = if (MC.font.fontHeight * lines.size > 32) MC.font.fontHeight * lines.size else 32
+ lines.forEach { if (MC.font.width(it) > maxWidth) maxWidth = MC.font.width(it.unformattedString) }
+ val height = if (MC.font.lineHeight * lines.size > 32) MC.font.lineHeight * lines.size else 32
it.context.fill(0, -3, 40 + maxWidth, height + 2, 0x80000000.toInt())
}
// Render text for the hud
lines.forEachIndexed { index, line ->
- it.context.drawText(
+ it.context.drawString(
MC.font,
- line.copy().withColor(Formatting.GRAY),
+ line.copy().withColor(ChatFormatting.GRAY),
36,
- MC.font.fontHeight * index,
+ MC.font.lineHeight * index,
-1,
true
)
@@ -217,13 +217,13 @@ object PetFeatures {
val tabPet = PetParser.parseTabWidget(TabListAPI.getWidgetLines(TabListAPI.WidgetName.PET))
if (pet == null && tabPet == null && tempTabPet == null && tempChatPet == null) {
// No data on current pet
- it.context.matrices.pushMatrix()
- TConfig.petOverlayHud.applyTransformations(JarvisIntegration.jarvis, it.context.matrices)
- val lines = mutableListOf<Text>()
- lines.add(Text.literal("" + Formatting.WHITE + "Unknown Pet"))
- lines.add(Text.literal("Open Pets Menu To Fix"))
+ it.context.pose().pushMatrix()
+ TConfig.petOverlayHud.applyTransformations(JarvisIntegration.jarvis, it.context.pose())
+ val lines = mutableListOf<Component>()
+ lines.add(Component.literal("" + ChatFormatting.WHITE + "Unknown Pet"))
+ lines.add(Component.literal("Open Pets Menu To Fix"))
renderLinesAndBackground(it, lines)
- it.context.matrices.popMatrix()
+ it.context.pose().popMatrix()
return
}
if (pet == null) {
@@ -255,71 +255,71 @@ object PetFeatures {
// Set the text for the HUD
- val lines = mutableListOf<Text>()
+ val lines = mutableListOf<Component>()
if (TConfig.petOverlayHudStyle == PetOverlayHudStyles.COLOUR_NO_BACKGROUND ||
TConfig.petOverlayHudStyle == PetOverlayHudStyles.COLOUR_BACKGROUND) {
// Colour Style
- lines.add(Text.literal("[Lvl ${pet.level}] ").append(Text.literal(pet.name)
- .withColor((Rarity.colourMap[pet.rarity]) ?: Formatting.WHITE)))
+ lines.add(Component.literal("[Lvl ${pet.level}] ").append(Component.literal(pet.name)
+ .withColor((Rarity.colourMap[pet.rarity]) ?: ChatFormatting.WHITE)))
- lines.add(Text.literal(pet.petItem))
+ lines.add(Component.literal(pet.petItem))
if (pet.level != pet.maxLevel) {
// Exp data
lines.add(
- Text.literal(
- "" + Formatting.YELLOW + "Required L${pet.level + 1}: ${shortFormat(pet.currentExp)}" +
- Formatting.GOLD + "/" + Formatting.YELLOW +
- "${shortFormat(pet.expForNextLevel)} " + Formatting.GOLD +
+ Component.literal(
+ "" + ChatFormatting.YELLOW + "Required L${pet.level + 1}: ${shortFormat(pet.currentExp)}" +
+ ChatFormatting.GOLD + "/" + ChatFormatting.YELLOW +
+ "${shortFormat(pet.expForNextLevel)} " + ChatFormatting.GOLD +
"(${formatPercent(pet.currentExp / pet.expForNextLevel)})"
)
)
lines.add(
- Text.literal(
- "" + Formatting.YELLOW + "Required L100: ${shortFormat(pet.totalExp)}" +
- Formatting.GOLD + "/" + Formatting.YELLOW +
- "${shortFormat(pet.expForMax)} " + Formatting.GOLD +
+ Component.literal(
+ "" + ChatFormatting.YELLOW + "Required L100: ${shortFormat(pet.totalExp)}" +
+ ChatFormatting.GOLD + "/" + ChatFormatting.YELLOW +
+ "${shortFormat(pet.expForMax)} " + ChatFormatting.GOLD +
"(${formatPercent(pet.totalExp / pet.expForMax)})"
)
)
} else {
// Overflow Exp data
- lines.add(Text.literal(
- "" + Formatting.AQUA + Formatting.BOLD + "MAX LEVEL"
+ lines.add(Component.literal(
+ "" + ChatFormatting.AQUA + ChatFormatting.BOLD + "MAX LEVEL"
))
- lines.add(Text.literal(
- "" + Formatting.GOLD + "+" + Formatting.YELLOW + "${shortFormat(pet.overflowExp)} XP"
+ lines.add(Component.literal(
+ "" + ChatFormatting.GOLD + "+" + ChatFormatting.YELLOW + "${shortFormat(pet.overflowExp)} XP"
))
}
} else if (TConfig.petOverlayHudStyle == PetOverlayHudStyles.PLAIN_NO_BACKGROUND ||
TConfig.petOverlayHudStyle == PetOverlayHudStyles.PLAIN_BACKGROUND) {
// Plain Style
- lines.add(Text.literal("[Lvl ${pet.level}] ").append(Text.literal(pet.name)
- .withColor((Rarity.colourMap[pet.rarity]) ?: Formatting.WHITE)))
+ lines.add(Component.literal("[Lvl ${pet.level}] ").append(Component.literal(pet.name)
+ .withColor((Rarity.colourMap[pet.rarity]) ?: ChatFormatting.WHITE)))
- lines.add(Text.literal(if (pet.petItem != "None" && pet.petItem != "Unknown")
+ lines.add(Component.literal(if (pet.petItem != "None" && pet.petItem != "Unknown")
pet.petItem.substring(2) else pet.petItem))
if (pet.level != pet.maxLevel) {
// Exp data
lines.add(
- Text.literal(
+ Component.literal(
"Required L${pet.level + 1}: ${shortFormat(pet.currentExp)}/" +
"${shortFormat(pet.expForNextLevel)} " +
"(${formatPercent(pet.currentExp / pet.expForNextLevel)})"
)
)
lines.add(
- Text.literal(
+ Component.literal(
"Required L100: ${shortFormat(pet.totalExp)}/${shortFormat(pet.expForMax)} " +
"(${formatPercent(pet.totalExp / pet.expForMax)})"
)
)
} else {
// Overflow Exp data
- lines.add(Text.literal(
+ lines.add(Component.literal(
"MAX LEVEL"
))
- lines.add(Text.literal(
+ lines.add(Component.literal(
"+${shortFormat(pet.overflowExp)} XP"
))
}
@@ -327,19 +327,19 @@ object PetFeatures {
// Render HUD
- it.context.matrices.pushMatrix()
- TConfig.petOverlayHud.applyTransformations(JarvisIntegration.jarvis, it.context.matrices)
+ it.context.pose().pushMatrix()
+ TConfig.petOverlayHud.applyTransformations(JarvisIntegration.jarvis, it.context.pose())
renderLinesAndBackground(it, lines)
// Draw the ItemStack
- it.context.matrices.pushMatrix()
- it.context.matrices.translate(-0.5F, -0.5F)
- it.context.matrices.scale(2f, 2f)
- it.context.drawItem(pet.petItemStack.value, 0, 0)
- it.context.matrices.popMatrix()
+ it.context.pose().pushMatrix()
+ it.context.pose().translate(-0.5F, -0.5F)
+ it.context.pose().scale(2f, 2f)
+ it.context.renderItem(pet.petItemStack.value, 0, 0)
+ it.context.pose().popMatrix()
- it.context.matrices.popMatrix()
+ it.context.pose().popMatrix()
}
}
@@ -404,7 +404,7 @@ object PetParser {
}
@OptIn(ExpensiveItemCacheApi::class)
- fun parseTabWidget(lines: List<Text>): ParsedPet? {
+ fun parseTabWidget(lines: List<Component>): ParsedPet? {
found.clear()
for (line in lines.reversed()) {
if (!found.containsKey("kat")) {
@@ -524,20 +524,20 @@ object PetParser {
}
data class ParsedPet(
- val name: String,
- val rarity: Rarity,
- var level: Int,
- val maxLevel: Int,
- val expLadder: ExpLadders.ExpLadder?,
- var currentExp: Double,
- var expForNextLevel: Double,
- var totalExp: Double,
- var totalExpBeforeLevel: Double,
- val expForMax: Double,
- var overflowExp: Double,
- var petItem: String,
- var petItemStack: Lazy<ItemStack>,
- var isComplete: Boolean
+ val name: String,
+ val rarity: Rarity,
+ var level: Int,
+ val maxLevel: Int,
+ val expLadder: ExpLadders.ExpLadder?,
+ var currentExp: Double,
+ var expForNextLevel: Double,
+ var totalExp: Double,
+ var totalExpBeforeLevel: Double,
+ val expForMax: Double,
+ var overflowExp: Double,
+ var petItem: String,
+ var petItemStack: Lazy<ItemStack>,
+ var isComplete: Boolean
) {
fun update(other: ParsedPet) {
// Update the pet data to reflect another instance (of itself)
diff --git a/src/main/kotlin/features/inventory/PriceData.kt b/src/main/kotlin/features/inventory/PriceData.kt
index 5f9268e..54802db 100644
--- a/src/main/kotlin/features/inventory/PriceData.kt
+++ b/src/main/kotlin/features/inventory/PriceData.kt
@@ -1,8 +1,8 @@
package moe.nea.firmament.features.inventory
import org.lwjgl.glfw.GLFW
-import net.minecraft.text.Text
-import net.minecraft.util.StringIdentifiable
+import net.minecraft.network.chat.Component
+import net.minecraft.util.StringRepresentable
import moe.nea.firmament.annotations.Subscribe
import moe.nea.firmament.events.ItemTooltipEvent
import moe.nea.firmament.repo.HypixelStaticData
@@ -34,25 +34,25 @@ object PriceData {
}
}
- enum class AvgLowestBin : StringIdentifiable {
+ enum class AvgLowestBin : StringRepresentable {
OFF,
ONEDAYAVGLOWESTBIN,
THREEDAYAVGLOWESTBIN,
SEVENDAYAVGLOWESTBIN;
- override fun asString(): String {
+ override fun getSerializedName(): String {
return name
}
}
- fun formatPrice(label: Text, price: Double): Text {
- return Text.literal("")
+ fun formatPrice(label: Component, price: Double): Component {
+ return Component.literal("")
.yellow()
.bold()
.append(label)
.append(": ")
.append(
- Text.literal(formatCommas(price, fractionalDigits = 1))
+ Component.literal(formatCommas(price, fractionalDigits = 1))
.append(if (price != 1.0) " coins" else " coin")
.gold()
.bold()
@@ -84,7 +84,7 @@ object PriceData {
AvgLowestBin.OFF -> null
}
if (bazaarData != null) {
- it.lines.add(Text.literal(""))
+ it.lines.add(Component.literal(""))
it.lines.add(multiplierText)
it.lines.add(
formatPrice(
@@ -99,7 +99,7 @@ object PriceData {
)
)
} else if (lowestBin != null) {
- it.lines.add(Text.literal(""))
+ it.lines.add(Component.literal(""))
it.lines.add(multiplierText)
it.lines.add(
formatPrice(
diff --git a/src/main/kotlin/features/inventory/REIDependencyWarner.kt b/src/main/kotlin/features/inventory/REIDependencyWarner.kt
index 9e8a4db..e508016 100644
--- a/src/main/kotlin/features/inventory/REIDependencyWarner.kt
+++ b/src/main/kotlin/features/inventory/REIDependencyWarner.kt
@@ -6,8 +6,8 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlin.time.Duration.Companion.seconds
import net.minecraft.SharedConstants
-import net.minecraft.text.ClickEvent
-import net.minecraft.text.Text
+import net.minecraft.network.chat.ClickEvent
+import net.minecraft.network.chat.Component
import moe.nea.firmament.Firmament
import moe.nea.firmament.annotations.Subscribe
import moe.nea.firmament.commands.thenExecute
@@ -31,22 +31,22 @@ object REIDependencyWarner {
var sentWarning = false
fun modrinthLink(slug: String) =
- "https://modrinth.com/mod/$slug/versions?g=${SharedConstants.getGameVersion().name()}&l=fabric"
+ "https://modrinth.com/mod/$slug/versions?g=${SharedConstants.getCurrentVersion().name()}&l=fabric"
- fun downloadButton(modName: String, modId: String, slug: String): Text {
+ fun downloadButton(modName: String, modId: String, slug: String): Component {
val alreadyDownloaded = FabricLoader.getInstance().isModLoaded(modId)
- return Text.literal(" - ")
+ return Component.literal(" - ")
.white()
- .append(Text.literal("[").aqua())
- .append(Text.translatable("firmament.download", modName)
- .styled { it.withClickEvent(ClickEvent.OpenUrl(URI (modrinthLink(slug)))) }
+ .append(Component.literal("[").aqua())
+ .append(Component.translatable("firmament.download", modName)
+ .withStyle { it.withClickEvent(ClickEvent.OpenUrl(URI (modrinthLink(slug)))) }
.yellow()
.also {
if (alreadyDownloaded)
- it.append(Text.translatable("firmament.download.already", modName)
+ it.append(Component.translatable("firmament.download.already", modName)
.lime())
})
- .append(Text.literal("]").aqua())
+ .append(Component.literal("]").aqua())
}
@Subscribe
@@ -60,11 +60,11 @@ object REIDependencyWarner {
delay(2.seconds)
// TODO: should we offer an automatic install that actually downloads the JARs and places them into the mod folder?
MC.sendChat(
- Text.translatable("firmament.reiwarning").red().bold().append("\n")
+ Component.translatable("firmament.reiwarning").red().bold().append("\n")
.append(downloadButton("RoughlyEnoughItems", reiModId, "rei")).append("\n")
.append(downloadButton("Architectury API", "architectury", "architectury-api")).append("\n")
.append(downloadButton("Cloth Config API", "cloth-config", "cloth-config")).append("\n")
- .append(Text.translatable("firmament.reiwarning.disable")
+ .append(Component.translatable("firmament.reiwarning.disable")
.clickCommand("/firm disablereiwarning")
.grey())
)
@@ -78,7 +78,7 @@ object REIDependencyWarner {
thenExecute {
RepoManager.TConfig.warnForMissingItemListMod = false
RepoManager.TConfig.markDirty()
- MC.sendChat(Text.translatable("firmament.reiwarning.disabled").yellow())
+ MC.sendChat(Component.translatable("firmament.reiwarning.disabled").yellow())
}
}
}
diff --git a/src/main/kotlin/features/inventory/SaveCursorPosition.kt b/src/main/kotlin/features/inventory/SaveCursorPosition.kt
index c523661..c492a75 100644
--- a/src/main/kotlin/features/inventory/SaveCursorPosition.kt
+++ b/src/main/kotlin/features/inventory/SaveCursorPosition.kt
@@ -3,7 +3,7 @@ package moe.nea.firmament.features.inventory
import org.lwjgl.glfw.GLFW
import kotlin.math.absoluteValue
import kotlin.time.Duration.Companion.milliseconds
-import net.minecraft.client.util.InputUtil
+import com.mojang.blaze3d.platform.InputConstants
import moe.nea.firmament.util.MC
import moe.nea.firmament.util.TimeMark
import moe.nea.firmament.util.assertNotNullOr
@@ -43,9 +43,9 @@ object SaveCursorPosition {
(lastPosition.middle.first - middleX).absoluteValue < 1 &&
(lastPosition.middle.second - middleY).absoluteValue < 1
) {
- InputUtil.setCursorParameters(
+ InputConstants.grabOrReleaseMouse(
MC.window,
- InputUtil.GLFW_CURSOR_NORMAL,
+ InputConstants.CURSOR_NORMAL,
lastPosition.cursor.first,
lastPosition.cursor.second
)
diff --git a/src/main/kotlin/features/inventory/SlotLocking.kt b/src/main/kotlin/features/inventory/SlotLocking.kt
index 10c58cb..09afe80 100644
--- a/src/main/kotlin/features/inventory/SlotLocking.kt
+++ b/src/main/kotlin/features/inventory/SlotLocking.kt
@@ -16,17 +16,17 @@ import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.JsonPrimitive
import kotlinx.serialization.json.int
import kotlinx.serialization.serializer
-import net.minecraft.client.gl.RenderPipelines
-import net.minecraft.client.gui.screen.ingame.HandledScreen
-import net.minecraft.client.gui.screen.ingame.InventoryScreen
-import net.minecraft.entity.player.PlayerInventory
-import net.minecraft.item.ItemStack
-import net.minecraft.screen.GenericContainerScreenHandler
-import net.minecraft.screen.PlayerScreenHandler
-import net.minecraft.screen.slot.Slot
-import net.minecraft.screen.slot.SlotActionType
-import net.minecraft.util.Identifier
-import net.minecraft.util.StringIdentifiable
+import net.minecraft.client.renderer.RenderPipelines
+import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen
+import net.minecraft.client.gui.screens.inventory.InventoryScreen
+import net.minecraft.world.entity.player.Inventory
+import net.minecraft.world.item.ItemStack
+import net.minecraft.world.inventory.ChestMenu
+import net.minecraft.world.inventory.InventoryMenu
+import net.minecraft.world.inventory.Slot
+import net.minecraft.world.inventory.ClickType
+import net.minecraft.resources.ResourceLocation
+import net.minecraft.util.StringRepresentable
import moe.nea.firmament.annotations.Subscribe
import moe.nea.firmament.events.ClientInitEvent
import moe.nea.firmament.events.HandledScreenForegroundEvent
@@ -157,12 +157,12 @@ object SlotLocking {
val allowDroppingInDungeons by toggle("drop-in-dungeons") { true }
}
- enum class SlotRenderLinesMode : StringIdentifiable {
+ enum class SlotRenderLinesMode : StringRepresentable {
EVERYTHING,
ONLY_BOXES,
NOTHING;
- override fun asString(): String {
+ override fun getSerializedName(): String {
return name
}
}
@@ -175,25 +175,25 @@ object SlotLocking {
val lockedSlots
get() = currentWorldData?.lockedSlots
- fun isSalvageScreen(screen: HandledScreen<*>?): Boolean {
+ fun isSalvageScreen(screen: AbstractContainerScreen<*>?): Boolean {
if (screen == null) return false
return screen.title.unformattedString.contains("Salvage Item")
}
- fun isTradeScreen(screen: HandledScreen<*>?): Boolean {
+ fun isTradeScreen(screen: AbstractContainerScreen<*>?): Boolean {
if (screen == null) return false
- val handler = screen.screenHandler as? GenericContainerScreenHandler ?: return false
- if (handler.inventory.size() < 9) return false
- val middlePane = handler.inventory.getStack(handler.inventory.size() - 5)
+ val handler = screen.menu as? ChestMenu ?: return false
+ if (handler.container.containerSize < 9) return false
+ val middlePane = handler.container.getItem(handler.container.containerSize - 5)
if (middlePane == null) return false
return middlePane.displayNameAccordingToNbt?.unformattedString == "⇦ Your stuff"
}
- fun isNpcShop(screen: HandledScreen<*>?): Boolean {
+ fun isNpcShop(screen: AbstractContainerScreen<*>?): Boolean {
if (screen == null) return false
- val handler = screen.screenHandler as? GenericContainerScreenHandler ?: return false
- if (handler.inventory.size() < 9) return false
- val sellItem = handler.inventory.getStack(handler.inventory.size() - 5)
+ val handler = screen.menu as? ChestMenu ?: return false
+ if (handler.container.containerSize < 9) return false
+ val sellItem = handler.container.getItem(handler.container.containerSize - 5)
if (sellItem == null) return false
if (sellItem.displayNameAccordingToNbt.unformattedString == "Sell Item") return true
val lore = sellItem.loreAccordingToNbt
@@ -203,15 +203,15 @@ object SlotLocking {
@Subscribe
fun onSalvageProtect(event: IsSlotProtectedEvent) {
if (event.slot == null) return
- if (!event.slot.hasStack()) return
- if (event.slot.stack.displayNameAccordingToNbt.unformattedString != "Salvage Items") return
- val inv = event.slot.inventory
+ if (!event.slot.hasItem()) return
+ if (event.slot.item.displayNameAccordingToNbt.unformattedString != "Salvage Items") return
+ val inv = event.slot.container
var anyBlocked = false
- for (i in 0 until event.slot.index) {
- val stack = inv.getStack(i)
+ for (i in 0 until event.slot.containerSlot) {
+ val stack = inv.getItem(i)
if (IsSlotProtectedEvent.shouldBlockInteraction(
null,
- SlotActionType.THROW,
+ ClickType.THROW,
IsSlotProtectedEvent.MoveOrigin.SALVAGE,
stack
)
@@ -225,15 +225,15 @@ object SlotLocking {
@Subscribe
fun onProtectUuidItems(event: IsSlotProtectedEvent) {
- val doesNotDeleteItem = event.actionType == SlotActionType.SWAP
- || event.actionType == SlotActionType.PICKUP
- || event.actionType == SlotActionType.QUICK_MOVE
- || event.actionType == SlotActionType.QUICK_CRAFT
- || event.actionType == SlotActionType.CLONE
- || event.actionType == SlotActionType.PICKUP_ALL
+ val doesNotDeleteItem = event.actionType == ClickType.SWAP
+ || event.actionType == ClickType.PICKUP
+ || event.actionType == ClickType.QUICK_MOVE
+ || event.actionType == ClickType.QUICK_CRAFT
+ || event.actionType == ClickType.CLONE
+ || event.actionType == ClickType.PICKUP_ALL
val isSellOrTradeScreen =
isNpcShop(MC.handledScreen) || isTradeScreen(MC.handledScreen) || isSalvageScreen(MC.handledScreen)
- if ((!isSellOrTradeScreen || event.slot?.inventory !is PlayerInventory)
+ if ((!isSellOrTradeScreen || event.slot?.container !is Inventory)
&& doesNotDeleteItem
) return
val stack = event.itemStack ?: return
@@ -253,7 +253,7 @@ object SlotLocking {
@Subscribe
fun onProtectSlot(it: IsSlotProtectedEvent) {
- if (it.slot != null && it.slot.inventory is PlayerInventory && it.slot.index in (lockedSlots ?: setOf())) {
+ if (it.slot != null && it.slot.container is Inventory && it.slot.containerSlot in (lockedSlots ?: setOf())) {
it.protect()
}
}
@@ -275,14 +275,14 @@ object SlotLocking {
fun onQuickMoveBoundSlot(it: IsSlotProtectedEvent) {
val boundSlots = currentWorldData?.boundSlots ?: BoundSlots()
val isValidAction =
- it.actionType == SlotActionType.QUICK_MOVE || (it.actionType == SlotActionType.PICKUP && !TConfig.slotBindRequireShift)
+ it.actionType == ClickType.QUICK_MOVE || (it.actionType == ClickType.PICKUP && !TConfig.slotBindRequireShift)
if (!isValidAction) return
- val handler = MC.handledScreen?.screenHandler ?: return
- if (TConfig.slotBindOnlyInInv && handler !is PlayerScreenHandler)
+ val handler = MC.handledScreen?.menu ?: return
+ if (TConfig.slotBindOnlyInInv && handler !is InventoryMenu)
return
val slot = it.slot
- if (slot != null && it.slot.inventory is PlayerInventory) {
- val matchingSlots = boundSlots.findMatchingSlots(slot.index)
+ if (slot != null && it.slot.container is Inventory) {
+ val matchingSlots = boundSlots.findMatchingSlots(slot.containerSlot)
if (matchingSlots.isEmpty()) return
it.protectSilent()
val boundSlot = matchingSlots.singleOrNull() ?: return
@@ -298,7 +298,7 @@ object SlotLocking {
inventory as AccessorHandledScreen
val slot = inventory.focusedSlot_Firmament ?: return
- val stack = slot.stack ?: return
+ val stack = slot.item ?: return
if (stack.isHuntingBox()) {
MC.sendChat(
tr(
@@ -339,10 +339,10 @@ object SlotLocking {
val hotBarSlot = if (slot.isHotbar()) slot else storedSlot
val invSlot = if (slot.isHotbar()) storedSlot else slot
val boundSlots = currentWorldData?.boundSlots ?: return
- lockedSlots?.remove(hotBarSlot.index)
- lockedSlots?.remove(invSlot.index)
- boundSlots.removeDuplicateForInventory(invSlot.index)
- boundSlots.insert(hotBarSlot.index, invSlot.index)
+ lockedSlots?.remove(hotBarSlot.containerSlot)
+ lockedSlots?.remove(invSlot.containerSlot)
+ boundSlots.removeDuplicateForInventory(invSlot.containerSlot)
+ boundSlots.insert(hotBarSlot.containerSlot, invSlot.containerSlot)
DConfig.markDirty()
CommonSoundEffects.playSuccess()
return
@@ -356,7 +356,7 @@ object SlotLocking {
storedLockingSlot = null
val boundSlots = currentWorldData?.boundSlots ?: return
if (slot != null)
- boundSlots.removeAllInvolving(slot.index)
+ boundSlots.removeAllInvolving(slot.containerSlot)
}
}
@@ -393,12 +393,12 @@ object SlotLocking {
hotX + sx, hotY + sy,
color(anyHovered)
)
- event.context.drawStrokedRectangle(
+ event.context.submitOutline(
hotbarSlot.x + sx,
hotbarSlot.y + sy,
16, 16, color(hotbarSlot in highlitSlots).color
)
- event.context.drawStrokedRectangle( // TODO: 1.21.10
+ event.context.submitOutline( // TODO: 1.21.10
inventorySlot.x + sx,
inventorySlot.y + sy,
16, 16, color(inventorySlot in highlitSlots).color
@@ -411,12 +411,12 @@ object SlotLocking {
val draggingSlot = storedLockingSlot ?: return
val accScreen = event.screen as AccessorHandledScreen
val hoveredSlot = accScreen.focusedSlot_Firmament
- ?.takeIf { it.inventory is PlayerInventory }
+ ?.takeIf { it.container is Inventory }
?.takeIf { it == draggingSlot || it.isHotbar() != draggingSlot.isHotbar() }
val sx = accScreen.x_Firmament
val sy = accScreen.y_Firmament
val (borderX, borderY) = draggingSlot.lineCenter()
- event.context.drawStrokedRectangle(draggingSlot.x + sx, draggingSlot.y + sy, 16, 16, 0xFF00FF00u.toInt()) // TODO: 1.21.10
+ event.context.submitOutline(draggingSlot.x + sx, draggingSlot.y + sy, 16, 16, 0xFF00FF00u.toInt()) // TODO: 1.21.10
if (hoveredSlot == null) {
event.context.drawLine(
borderX + sx, borderY + sy,
@@ -430,7 +430,7 @@ object SlotLocking {
hovX + sx, hovY + sy,
me.shedaniel.math.Color.ofOpaque(0x00FF00)
)
- event.context.drawStrokedRectangle(
+ event.context.submitOutline(
hoveredSlot.x + sx,
hoveredSlot.y + sy,
16, 16, 0xFF00FF00u.toInt()
@@ -448,7 +448,7 @@ object SlotLocking {
fun Slot.isHotbar(): Boolean {
- return index < 9
+ return containerSlot < 9
}
@Subscribe
@@ -461,13 +461,13 @@ object SlotLocking {
fun toggleSlotLock(slot: Slot) {
val lockedSlots = lockedSlots ?: return
val boundSlots = currentWorldData?.boundSlots ?: BoundSlots()
- if (slot.inventory is PlayerInventory) {
- if (boundSlots.removeAllInvolving(slot.index)) {
+ if (slot.container is Inventory) {
+ if (boundSlots.removeAllInvolving(slot.containerSlot)) {
// intentionally do nothing
- } else if (slot.index in lockedSlots) {
- lockedSlots.remove(slot.index)
+ } else if (slot.containerSlot in lockedSlots) {
+ lockedSlots.remove(slot.containerSlot)
} else {
- lockedSlots.add(slot.index)
+ lockedSlots.add(slot.containerSlot)
}
DConfig.markDirty()
CommonSoundEffects.playSuccess()
@@ -480,7 +480,7 @@ object SlotLocking {
inventory as AccessorHandledScreen
val slot = inventory.focusedSlot_Firmament ?: return
- if (slot.inventory !is PlayerInventory) return
+ if (slot.container !is Inventory) return
if (it.matches(TConfig.slotBind)) {
storedLockingSlot = storedLockingSlot ?: slot
return
@@ -493,17 +493,17 @@ object SlotLocking {
@Subscribe
fun onRenderSlotOverlay(it: SlotRenderEvents.After) {
- val isSlotLocked = it.slot.inventory is PlayerInventory && it.slot.index in (lockedSlots ?: setOf())
- val isUUIDLocked = (it.slot.stack?.skyblockUUID) in (lockedUUIDs ?: setOf())
+ val isSlotLocked = it.slot.container is Inventory && it.slot.containerSlot in (lockedSlots ?: setOf())
+ val isUUIDLocked = (it.slot.item?.skyblockUUID) in (lockedUUIDs ?: setOf())
if (isSlotLocked || isUUIDLocked) {
- it.context.drawGuiTexture(
+ it.context.blitSprite(
RenderPipelines.GUI_TEXTURED,
when {
isSlotLocked ->
- (Identifier.of("firmament:slot_locked"))
+ (ResourceLocation.parse("firmament:slot_locked"))
isUUIDLocked ->
- (Identifier.of("firmament:uuid_locked"))
+ (ResourceLocation.parse("firmament:uuid_locked"))
else ->
error("unreachable")
diff --git a/src/main/kotlin/features/inventory/TimerInLore.kt b/src/main/kotlin/features/inventory/TimerInLore.kt
index d8eebda..9bb78c9 100644
--- a/src/main/kotlin/features/inventory/TimerInLore.kt
+++ b/src/main/kotlin/features/inventory/TimerInLore.kt
@@ -7,8 +7,8 @@ import java.time.format.DateTimeFormatterBuilder
import java.time.format.FormatStyle
import java.time.format.TextStyle
import java.time.temporal.ChronoField
-import net.minecraft.text.Text
-import net.minecraft.util.StringIdentifiable
+import net.minecraft.network.chat.Component
+import net.minecraft.util.StringRepresentable
import moe.nea.firmament.annotations.Subscribe
import moe.nea.firmament.events.ItemTooltipEvent
import moe.nea.firmament.util.SBData
@@ -29,7 +29,7 @@ object TimerInLore {
val timerFormat by choice("format") { TimerFormat.SOCIALIST }
}
- enum class TimerFormat(val formatter: DateTimeFormatter) : StringIdentifiable {
+ enum class TimerFormat(val formatter: DateTimeFormatter) : StringRepresentable {
RFC(DateTimeFormatter.RFC_1123_DATE_TIME),
LOCAL(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM)),
SOCIALIST(
@@ -57,7 +57,7 @@ object TimerInLore {
constructor(format: String) : this(DateTimeFormatter.ofPattern(format))
- override fun asString(): String {
+ override fun getSerializedName(): String {
return name
}
}
@@ -142,9 +142,9 @@ object TimerInLore {
// TODO: install approximate time stabilization algorithm
event.lines.add(
i + 1,
- Text.literal("${countdownType.label}: ")
+ Component.literal("${countdownType.label}: ")
.grey()
- .append(Text.literal(TConfig.timerFormat.formatter.format(localTimer)).aqua())
+ .append(Component.literal(TConfig.timerFormat.formatter.format(localTimer)).aqua())
)
}
}
diff --git a/src/main/kotlin/features/inventory/WardrobeKeybinds.kt b/src/main/kotlin/features/inventory/WardrobeKeybinds.kt
index cdd646e..b3d4bfd 100644
--- a/src/main/kotlin/features/inventory/WardrobeKeybinds.kt
+++ b/src/main/kotlin/features/inventory/WardrobeKeybinds.kt
@@ -1,7 +1,7 @@
package moe.nea.firmament.features.inventory
import org.lwjgl.glfw.GLFW
-import net.minecraft.item.Items
+import net.minecraft.world.item.Items
import moe.nea.firmament.annotations.Subscribe
import moe.nea.firmament.events.HandledScreenKeyPressedEvent
import moe.nea.firmament.util.MC
@@ -41,16 +41,16 @@ object WardrobeKeybinds {
) {
event.cancel()
- val handler = event.screen.screenHandler
+ val handler = event.screen.menu
val previousSlot = handler.getSlot(45)
val nextSlot = handler.getSlot(53)
val backPressed = event.matches(TConfig.changePageKeybind) || event.matches(TConfig.previousPage)
val nextPressed = event.matches(TConfig.changePageKeybind) || event.matches(TConfig.nextPage)
- if (backPressed && previousSlot.stack.item == Items.ARROW) {
+ if (backPressed && previousSlot.item.item == Items.ARROW) {
previousSlot.clickLeftMouseButton(handler)
- } else if (nextPressed && nextSlot.stack.item == Items.ARROW) {
+ } else if (nextPressed && nextSlot.item.item == Items.ARROW) {
nextSlot.clickLeftMouseButton(handler)
}
}
@@ -63,10 +63,10 @@ object WardrobeKeybinds {
event.cancel()
- val handler = event.screen.screenHandler
+ val handler = event.screen.menu
val invSlot = handler.getSlot(slot)
- val itemStack = invSlot.stack
+ val itemStack = invSlot.item
val isSelected = itemStack.item == Items.LIME_DYE
val isSelectable = itemStack.item == Items.PINK_DYE
if (!isSelectable && !isSelected) return
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,
)
)
diff --git a/src/main/kotlin/features/inventory/storageoverlay/StorageBackingHandle.kt b/src/main/kotlin/features/inventory/storageoverlay/StorageBackingHandle.kt
index d7346c2..964f415 100644
--- a/src/main/kotlin/features/inventory/storageoverlay/StorageBackingHandle.kt
+++ b/src/main/kotlin/features/inventory/storageoverlay/StorageBackingHandle.kt
@@ -4,9 +4,9 @@ package moe.nea.firmament.features.inventory.storageoverlay
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.contract
-import net.minecraft.client.gui.screen.Screen
-import net.minecraft.client.gui.screen.ingame.GenericContainerScreen
-import net.minecraft.screen.GenericContainerScreenHandler
+import net.minecraft.client.gui.screens.Screen
+import net.minecraft.client.gui.screens.inventory.ContainerScreen
+import net.minecraft.world.inventory.ChestMenu
import moe.nea.firmament.util.ifMatches
import moe.nea.firmament.util.unformattedString
@@ -16,19 +16,19 @@ import moe.nea.firmament.util.unformattedString
sealed interface StorageBackingHandle {
sealed interface HasBackingScreen {
- val handler: GenericContainerScreenHandler
+ val handler: ChestMenu
}
/**
* The main storage overview is open. Clicking on a slot will open that page. This page is accessible via `/storage`
*/
- data class Overview(override val handler: GenericContainerScreenHandler) : StorageBackingHandle, HasBackingScreen
+ data class Overview(override val handler: ChestMenu) : StorageBackingHandle, HasBackingScreen
/**
* An individual storage page is open. This may be a backpack or an enderchest page. This page is accessible via
* the [Overview] or via `/ec <index + 1>` for enderchest pages.
*/
- data class Page(override val handler: GenericContainerScreenHandler, val storagePageSlot: StoragePageSlot) :
+ data class Page(override val handler: ChestMenu, val storagePageSlot: StoragePageSlot) :
StorageBackingHandle, HasBackingScreen
companion object {
@@ -46,13 +46,13 @@ sealed interface StorageBackingHandle {
returnsNotNull() implies (screen != null)
}
if (screen == null) return null
- if (screen !is GenericContainerScreen) return null
+ if (screen !is ContainerScreen) return null
val title = screen.title.unformattedString
- if (title == "Storage") return Overview(screen.screenHandler)
+ if (title == "Storage") return Overview(screen.menu)
return title.ifMatches(enderChestName) {
- Page(screen.screenHandler, StoragePageSlot.ofEnderChestPage(it.groupValues[1].toInt()))
+ Page(screen.menu, StoragePageSlot.ofEnderChestPage(it.groupValues[1].toInt()))
} ?: title.ifMatches(backPackName) {
- Page(screen.screenHandler, StoragePageSlot.ofBackPackPage(it.groupValues[1].toInt()))
+ Page(screen.menu, StoragePageSlot.ofBackPackPage(it.groupValues[1].toInt()))
}
}
}
diff --git a/src/main/kotlin/features/inventory/storageoverlay/StorageOverlay.kt b/src/main/kotlin/features/inventory/storageoverlay/StorageOverlay.kt
index 7dbb02a..7f96637 100644
--- a/src/main/kotlin/features/inventory/storageoverlay/StorageOverlay.kt
+++ b/src/main/kotlin/features/inventory/storageoverlay/StorageOverlay.kt
@@ -3,12 +3,12 @@ package moe.nea.firmament.features.inventory.storageoverlay
import io.github.notenoughupdates.moulconfig.ChromaColour
import java.util.SortedMap
import kotlinx.serialization.serializer
-import net.minecraft.client.gui.screen.ingame.GenericContainerScreen
-import net.minecraft.client.gui.screen.ingame.HandledScreen
-import net.minecraft.entity.player.PlayerInventory
-import net.minecraft.item.Items
-import net.minecraft.network.packet.c2s.play.CloseHandledScreenC2SPacket
-import net.minecraft.text.Text
+import net.minecraft.client.gui.screens.inventory.ContainerScreen
+import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen
+import net.minecraft.world.entity.player.Inventory
+import net.minecraft.world.item.Items
+import net.minecraft.network.protocol.game.ServerboundContainerClosePacket
+import net.minecraft.network.chat.Component
import moe.nea.firmament.annotations.Subscribe
import moe.nea.firmament.events.ChestInventoryUpdateEvent
import moe.nea.firmament.events.ScreenChangeEvent
@@ -71,7 +71,7 @@ object StorageOverlay {
(MC.screen as? StorageOverlayScreen)
?: (MC.handledScreen?.customGui as? StorageOverlayCustom)?.overview
?: return
- val stack = event.slot.stack ?: return
+ val stack = event.slot.item ?: return
val search = storageOverlayScreen.searchText.get().takeIf { it.isNotBlank() } ?: return
if (storageOverlayScreen.matchesSearch(stack, search)) {
event.context.fill(
@@ -100,7 +100,7 @@ object StorageOverlay {
@Subscribe
fun onClick(event: SlotClickEvent) {
- if (lastStorageOverlay != null && event.slot.inventory !is PlayerInventory && event.slot.index < 9
+ if (lastStorageOverlay != null && event.slot.container !is Inventory && event.slot.containerSlot < 9
&& event.stack.item != Items.BLACK_STAINED_GLASS_PANE
) {
skipNextStorageOverlayBackflip = true
@@ -111,18 +111,18 @@ object StorageOverlay {
fun onScreenChange(it: ScreenChangeEvent) {
if (it.old == null && it.new == null) return
val storageOverlayScreen = it.old as? StorageOverlayScreen
- ?: ((it.old as? HandledScreen<*>)?.customGui as? StorageOverlayCustom)?.overview
+ ?: ((it.old as? AbstractContainerScreen<*>)?.customGui as? StorageOverlayCustom)?.overview
var storageOverviewScreen = it.old as? StorageOverviewScreen
- val screen = it.new as? GenericContainerScreen
+ val screen = it.new as? ContainerScreen
rememberContent(currentHandler)
val oldHandler = currentHandler
currentHandler = StorageBackingHandle.fromScreen(screen)
if (storageOverviewScreen != null && oldHandler is StorageBackingHandle.HasBackingScreen) {
val player = MC.player
assert(player != null)
- player?.networkHandler?.sendPacket(CloseHandledScreenC2SPacket(oldHandler.handler.syncId))
- if (player?.currentScreenHandler === oldHandler.handler) {
- player.currentScreenHandler = player.playerScreenHandler
+ player?.connection?.send(ServerboundContainerClosePacket(oldHandler.handler.containerId))
+ if (player?.containerMenu === oldHandler.handler) {
+ player.containerMenu = player.inventoryMenu
}
}
storageOverviewScreen = storageOverviewScreen ?: lastStorageOverlay
@@ -164,7 +164,7 @@ object StorageOverlay {
handler: StorageBackingHandle.Overview,
data: SortedMap<StoragePageSlot, StorageData.StorageInventory>
) {
- for ((index, stack) in handler.handler.stacks.withIndex()) {
+ for ((index, stack) in handler.handler.items.withIndex()) { // TODO: replace with slot iteration
// Ignore unloaded item stacks
if (stack.isEmpty) continue
val slot = StoragePageSlot.fromOverviewSlotIndex(index) ?: continue
@@ -186,7 +186,7 @@ object StorageOverlay {
data: SortedMap<StoragePageSlot, StorageData.StorageInventory>
) {
val newStacks =
- VirtualInventory(handler.handler.stacks.take(handler.handler.rows * 9).drop(9).map { it.copy() })
+ VirtualInventory(handler.handler.items.take(handler.handler.rowCount * 9).drop(9).map { it.copy() })
data.compute(handler.storagePageSlot) { slot, existingInventory ->
(existingInventory ?: StorageData.StorageInventory(
slot.defaultName(),
diff --git a/src/main/kotlin/features/inventory/storageoverlay/StorageOverlayCustom.kt b/src/main/kotlin/features/inventory/storageoverlay/StorageOverlayCustom.kt
index a4199c9..f291dba 100644
--- a/src/main/kotlin/features/inventory/storageoverlay/StorageOverlayCustom.kt
+++ b/src/main/kotlin/features/inventory/storageoverlay/StorageOverlayCustom.kt
@@ -2,22 +2,22 @@ package moe.nea.firmament.features.inventory.storageoverlay
import me.shedaniel.math.Point
import me.shedaniel.math.Rectangle
-import net.minecraft.client.MinecraftClient
-import net.minecraft.client.gui.Click
-import net.minecraft.client.gui.DrawContext
-import net.minecraft.client.gui.screen.ingame.GenericContainerScreen
-import net.minecraft.client.input.CharInput
-import net.minecraft.client.input.KeyInput
-import net.minecraft.entity.player.PlayerInventory
-import net.minecraft.screen.slot.Slot
+import net.minecraft.client.Minecraft
+import net.minecraft.client.input.MouseButtonEvent
+import net.minecraft.client.gui.GuiGraphics
+import net.minecraft.client.gui.screens.inventory.ContainerScreen
+import net.minecraft.client.input.CharacterEvent
+import net.minecraft.client.input.KeyEvent
+import net.minecraft.world.entity.player.Inventory
+import net.minecraft.world.inventory.Slot
import moe.nea.firmament.mixins.accessor.AccessorHandledScreen
import moe.nea.firmament.util.customgui.CustomGui
import moe.nea.firmament.util.focusedItemStack
class StorageOverlayCustom(
- val handler: StorageBackingHandle,
- val screen: GenericContainerScreen,
- val overview: StorageOverlayScreen,
+ val handler: StorageBackingHandle,
+ val screen: ContainerScreen,
+ val overview: StorageOverlayScreen,
) : CustomGui() {
override fun onVoluntaryExit(): Boolean {
overview.isExiting = true
@@ -29,18 +29,18 @@ class StorageOverlayCustom(
return overview.getBounds()
}
- override fun afterSlotRender(context: DrawContext, slot: Slot) {
- if (slot.inventory !is PlayerInventory)
+ override fun afterSlotRender(context: GuiGraphics, slot: Slot) {
+ if (slot.container !is Inventory)
context.disableScissor()
}
- override fun beforeSlotRender(context: DrawContext, slot: Slot) {
- if (slot.inventory !is PlayerInventory)
+ override fun beforeSlotRender(context: GuiGraphics, slot: Slot) {
+ if (slot.container !is Inventory)
overview.createScissors(context)
}
override fun onInit() {
- overview.init(MinecraftClient.getInstance(), screen.width, screen.height)
+ overview.init(Minecraft.getInstance(), screen.width, screen.height)
overview.init()
screen as AccessorHandledScreen
screen.x_Firmament = overview.measurements.x
@@ -52,7 +52,7 @@ class StorageOverlayCustom(
override fun isPointOverSlot(slot: Slot, xOffset: Int, yOffset: Int, pointX: Double, pointY: Double): Boolean {
if (!super.isPointOverSlot(slot, xOffset, yOffset, pointX, pointY))
return false
- if (slot.inventory !is PlayerInventory) {
+ if (slot.container !is Inventory) {
if (!overview.getScrollPanelInner().contains(pointX, pointY))
return false
}
@@ -63,31 +63,31 @@ class StorageOverlayCustom(
return false
}
- override fun mouseReleased(click: Click): Boolean {
+ override fun mouseReleased(click: MouseButtonEvent): Boolean {
return overview.mouseReleased(click)
}
- override fun mouseDragged(click: Click, offsetX: Double, offsetY: Double): Boolean {
+ override fun mouseDragged(click: MouseButtonEvent, offsetX: Double, offsetY: Double): Boolean {
return overview.mouseDragged(click, offsetX, offsetY)
}
- override fun keyReleased(input: KeyInput): Boolean {
+ override fun keyReleased(input: KeyEvent): Boolean {
return overview.keyReleased(input)
}
- override fun keyPressed(input: KeyInput): Boolean {
+ override fun keyPressed(input: KeyEvent): Boolean {
return overview.keyPressed(input)
}
- override fun charTyped(input: CharInput): Boolean {
+ override fun charTyped(input: CharacterEvent): Boolean {
return overview.charTyped(input)
}
- override fun mouseClick(click: Click, doubled: Boolean): Boolean {
+ override fun mouseClick(click: MouseButtonEvent, doubled: Boolean): Boolean {
return overview.mouseClicked(click, doubled, (handler as? StorageBackingHandle.Page)?.storagePageSlot)
}
- override fun render(drawContext: DrawContext, delta: Float, mouseX: Int, mouseY: Int) {
+ override fun render(drawContext: GuiGraphics, delta: Float, mouseX: Int, mouseY: Int) {
overview.drawBackgrounds(drawContext)
overview.drawPages(
drawContext,
@@ -95,7 +95,7 @@ class StorageOverlayCustom(
mouseY,
delta,
(handler as? StorageBackingHandle.Page)?.storagePageSlot,
- screen.screenHandler.slots.take(screen.screenHandler.rows * 9).drop(9),
+ screen.menu.slots.take(screen.menu.rowCount * 9).drop(9),
Point((screen as AccessorHandledScreen).x_Firmament, screen.y_Firmament)
)
overview.drawScrollBar(drawContext)
@@ -103,7 +103,7 @@ class StorageOverlayCustom(
}
override fun moveSlot(slot: Slot) {
- val index = slot.index
+ val index = slot.containerSlot
if (index in 0..<36) {
val (x, y) = overview.getPlayerInventorySlotPosition(index)
slot.x = x - (screen as AccessorHandledScreen).x_Firmament
diff --git a/src/main/kotlin/features/inventory/storageoverlay/StorageOverlayScreen.kt b/src/main/kotlin/features/inventory/storageoverlay/StorageOverlayScreen.kt
index d2fff9c..3e0bb4b 100644
--- a/src/main/kotlin/features/inventory/storageoverlay/StorageOverlayScreen.kt
+++ b/src/main/kotlin/features/inventory/storageoverlay/StorageOverlayScreen.kt
@@ -13,17 +13,17 @@ import io.github.notenoughupdates.moulconfig.observer.Property
import java.util.TreeSet
import me.shedaniel.math.Point
import me.shedaniel.math.Rectangle
-import net.minecraft.client.gui.Click
-import net.minecraft.client.gui.DrawContext
-import net.minecraft.client.gui.screen.Screen
-import net.minecraft.client.gui.screen.ingame.HandledScreen
-import net.minecraft.client.input.CharInput
-import net.minecraft.client.input.KeyInput
-import net.minecraft.item.ItemStack
-import net.minecraft.screen.slot.Slot
-import net.minecraft.text.Text
-import net.minecraft.util.Formatting
-import net.minecraft.util.Identifier
+import net.minecraft.client.input.MouseButtonEvent
+import net.minecraft.client.gui.GuiGraphics
+import net.minecraft.client.gui.screens.Screen
+import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen
+import net.minecraft.client.input.CharacterEvent
+import net.minecraft.client.input.KeyEvent
+import net.minecraft.world.item.ItemStack
+import net.minecraft.world.inventory.Slot
+import net.minecraft.network.chat.Component
+import net.minecraft.ChatFormatting
+import net.minecraft.resources.ResourceLocation
import moe.nea.firmament.events.SlotRenderEvents
import moe.nea.firmament.gui.EmptyComponent
import moe.nea.firmament.gui.FirmButtonComponent
@@ -43,7 +43,7 @@ import moe.nea.firmament.util.render.enableScissorWithoutTranslation
import moe.nea.firmament.util.tr
import moe.nea.firmament.util.unformattedString
-class StorageOverlayScreen : Screen(Text.literal("")) {
+class StorageOverlayScreen : Screen(Component.literal("")) {
companion object {
val PLAYER_WIDTH = 184
@@ -122,20 +122,20 @@ class StorageOverlayScreen : Screen(Text.literal("")) {
fun getMaxScroll() = lastRenderedInnerHeight.toFloat() - getScrollPanelInner().height
- val playerInventorySprite = Identifier.of("firmament:storageoverlay/player_inventory")
- val upperBackgroundSprite = Identifier.of("firmament:storageoverlay/upper_background")
- val slotRowSprite = Identifier.of("firmament:storageoverlay/storage_row")
- val scrollbarBackground = Identifier.of("firmament:storageoverlay/scroll_bar_background")
- val scrollbarKnob = Identifier.of("firmament:storageoverlay/scroll_bar_knob")
- val controllerBackground = Identifier.of("firmament:storageoverlay/storage_controls")
+ val playerInventorySprite = ResourceLocation.parse("firmament:storageoverlay/player_inventory")
+ val upperBackgroundSprite = ResourceLocation.parse("firmament:storageoverlay/upper_background")
+ val slotRowSprite = ResourceLocation.parse("firmament:storageoverlay/storage_row")
+ val scrollbarBackground = ResourceLocation.parse("firmament:storageoverlay/scroll_bar_background")
+ val scrollbarKnob = ResourceLocation.parse("firmament:storageoverlay/scroll_bar_knob")
+ val controllerBackground = ResourceLocation.parse("firmament:storageoverlay/storage_controls")
- override fun close() {
+ override fun onClose() {
isExiting = true
resetScroll()
- super.close()
+ super.onClose()
}
- override fun render(context: DrawContext, mouseX: Int, mouseY: Int, delta: Float) {
+ override fun render(context: GuiGraphics, mouseX: Int, mouseY: Int, delta: Float) {
super.render(context, mouseX, mouseY, delta)
drawBackgrounds(context)
drawPages(context, mouseX, mouseY, delta, null, null, Point())
@@ -148,7 +148,7 @@ class StorageOverlayScreen : Screen(Text.literal("")) {
return scroll / getMaxScroll()
}
- fun drawScrollBar(context: DrawContext) {
+ fun drawScrollBar(context: GuiGraphics) {
val sbRect = getScrollBarRect()
context.drawGuiTexture(
scrollbarBackground,
@@ -164,8 +164,8 @@ class StorageOverlayScreen : Screen(Text.literal("")) {
fun editPages() {
isExiting = true
- MC.instance.send {
- val hs = MC.screen as? HandledScreen<*>
+ MC.instance.schedule {
+ val hs = MC.screen as? AbstractContainerScreen<*>
if (StorageBackingHandle.fromScreen(hs) is StorageBackingHandle.Overview) {
hs.customGui = null
hs.init(MC.instance, width, height)
@@ -204,7 +204,7 @@ class StorageOverlayScreen : Screen(Text.literal("")) {
guiContext.adopt(controlComponent)
}
- fun drawControls(context: DrawContext, mouseX: Int, mouseY: Int) {
+ fun drawControls(context: GuiGraphics, mouseX: Int, mouseY: Int) {
context.drawGuiTexture(
controllerBackground,
measurements.controlX,
@@ -219,7 +219,7 @@ class StorageOverlayScreen : Screen(Text.literal("")) {
)
}
- fun drawBackgrounds(context: DrawContext) {
+ fun drawBackgrounds(context: GuiGraphics) {
context.drawGuiTexture(
upperBackgroundSprite,
measurements.x,
@@ -246,12 +246,12 @@ class StorageOverlayScreen : Screen(Text.literal("")) {
)
}
- fun drawPlayerInventory(context: DrawContext, mouseX: Int, mouseY: Int, delta: Float) {
- val items = MC.player?.inventory?.mainStacks ?: return
+ fun drawPlayerInventory(context: GuiGraphics, mouseX: Int, mouseY: Int, delta: Float) {
+ val items = MC.player?.inventory?.nonEquipmentItems ?: return
items.withIndex().forEach { (index, item) ->
val (x, y) = getPlayerInventorySlotPosition(index)
- context.drawItem(item, x, y, 0)
- context.drawStackOverlay(textRenderer, item, x, y)
+ context.renderItem(item, x, y, 0)
+ context.renderItemDecorations(font, item, x, y)
}
}
@@ -273,7 +273,7 @@ class StorageOverlayScreen : Screen(Text.literal("")) {
)
}
- fun createScissors(context: DrawContext) {
+ fun createScissors(context: GuiGraphics) {
val rect = getScrollPanelInner()
context.enableScissorWithoutTranslation(
rect.minX.toFloat(), rect.minY.toFloat(),
@@ -282,10 +282,10 @@ class StorageOverlayScreen : Screen(Text.literal("")) {
}
fun drawPages(
- context: DrawContext, mouseX: Int, mouseY: Int, delta: Float,
- excluding: StoragePageSlot?,
- slots: List<Slot>?,
- slotOffset: Point
+ context: GuiGraphics, mouseX: Int, mouseY: Int, delta: Float,
+ excluding: StoragePageSlot?,
+ slots: List<Slot>?,
+ slotOffset: Point
) {
createScissors(context)
val data = StorageOverlay.Data.data ?: StorageData()
@@ -310,11 +310,11 @@ class StorageOverlayScreen : Screen(Text.literal("")) {
get() = guiContext.focusedElement == knobStub
set(value) = knobStub.setFocus(value)
- override fun mouseClicked(click: Click, doubled: Boolean): Boolean {
+ override fun mouseClicked(click: MouseButtonEvent, doubled: Boolean): Boolean {
return mouseClicked(click, doubled, null)
}
- override fun mouseReleased(click: Click): Boolean {
+ override fun mouseReleased(click: MouseButtonEvent): Boolean {
if (knobGrabbed) {
knobGrabbed = false
return true
@@ -330,7 +330,7 @@ class StorageOverlayScreen : Screen(Text.literal("")) {
return super.mouseReleased(click)
}
- override fun mouseDragged(click: Click, offsetX: Double, offsetY: Double): Boolean {
+ override fun mouseDragged(click: MouseButtonEvent, offsetX: Double, offsetY: Double): Boolean {
if (knobGrabbed) {
val sbRect = getScrollBarRect()
val percentage = (click.x - sbRect.getY()) / sbRect.getHeight()
@@ -341,7 +341,7 @@ class StorageOverlayScreen : Screen(Text.literal("")) {
return super.mouseDragged(click, offsetX, offsetY)
}
- fun mouseClicked(click: Click, doubled: Boolean, activePage: StoragePageSlot?): Boolean {
+ fun mouseClicked(click: MouseButtonEvent, doubled: Boolean, activePage: StoragePageSlot?): Boolean {
guiContext.setFocusedElement(null) // Blur all elements. They will be refocused by clickMCComponentInPlace if in doubt, and we don't have any double click components.
val mouseX = click.x
val mouseY = click.y
@@ -374,12 +374,12 @@ class StorageOverlayScreen : Screen(Text.literal("")) {
return false
}
- override fun charTyped(input: CharInput): Boolean {
+ override fun charTyped(input: CharacterEvent): Boolean {
if (typeMCComponentInPlace(
controlComponent,
measurements.controlX, measurements.controlY,
CONTROL_WIDTH, CONTROL_HEIGHT,
- KeyboardEvent.CharTyped(input.asString().first()) // TODO: i dont like this .first()
+ KeyboardEvent.CharTyped(input.codepointAsString().first()) // TODO: i dont like this .first()
)
) {
return true
@@ -387,12 +387,12 @@ class StorageOverlayScreen : Screen(Text.literal("")) {
return super.charTyped(input)
}
- override fun keyReleased(input: KeyInput): Boolean {
+ override fun keyReleased(input: KeyEvent): Boolean {
if (typeMCComponentInPlace(
controlComponent,
measurements.controlX, measurements.controlY,
CONTROL_WIDTH, CONTROL_HEIGHT,
- KeyboardEvent.KeyPressed(input.keycode, input.scancode, false)
+ KeyboardEvent.KeyPressed(input.input(), input.scancode, false)
)
) {
return true
@@ -404,12 +404,12 @@ class StorageOverlayScreen : Screen(Text.literal("")) {
return this === MC.screen // Fixes this UI closing the handled screen on Escape press.
}
- override fun keyPressed(input: KeyInput): Boolean {
+ override fun keyPressed(input: KeyEvent): Boolean {
if (typeMCComponentInPlace(
controlComponent,
measurements.controlX, measurements.controlY,
CONTROL_WIDTH, CONTROL_HEIGHT,
- KeyboardEvent.KeyPressed(input.keycode, input.scancode, true)
+ KeyboardEvent.KeyPressed(input.input(), input.scancode, true)
)
) {
return true
@@ -463,7 +463,7 @@ class StorageOverlayScreen : Screen(Text.literal("")) {
val filter = getFilteredPages()
for ((page, inventory) in data.storageInventories.entries) {
if (page !in filter) continue
- val currentHeight = inventory.inventory?.let { it.rows * SLOT_SIZE + 6 + textRenderer.fontHeight }
+ val currentHeight = inventory.inventory?.let { it.rows * SLOT_SIZE + 6 + font.lineHeight }
?: 18
maxHeight = maxOf(maxHeight, currentHeight)
val rect = Rectangle(
@@ -484,22 +484,22 @@ class StorageOverlayScreen : Screen(Text.literal("")) {
}
fun drawPage(
- context: DrawContext,
- x: Int,
- y: Int,
- page: StoragePageSlot,
- inventory: StorageData.StorageInventory,
- slots: List<Slot>?,
- slotOffset: Point,
- mouseX: Int,
- mouseY: Int,
+ context: GuiGraphics,
+ x: Int,
+ y: Int,
+ page: StoragePageSlot,
+ inventory: StorageData.StorageInventory,
+ slots: List<Slot>?,
+ slotOffset: Point,
+ mouseX: Int,
+ mouseY: Int,
): Int {
val inv = inventory.inventory
if (inv == null) {
context.drawGuiTexture(upperBackgroundSprite, x, y, PAGE_WIDTH, 18)
- context.drawText(
- textRenderer,
- Text.literal("TODO: open this page"),
+ context.drawString(
+ font,
+ Component.literal("TODO: open this page"),
x + 4,
y + 4,
-1,
@@ -509,34 +509,34 @@ class StorageOverlayScreen : Screen(Text.literal("")) {
}
assertTrueOr(slots == null || slots.size == inv.stacks.size) { return 0 }
val name = inventory.title
- val pageHeight = inv.rows * SLOT_SIZE + 8 + textRenderer.fontHeight
+ val pageHeight = inv.rows * SLOT_SIZE + 8 + font.lineHeight
if (slots != null && StorageOverlay.TConfig.outlineActiveStoragePage)
- context.drawStrokedRectangle(
+ context.submitOutline(
x,
- y + 3 + textRenderer.fontHeight,
+ y + 3 + font.lineHeight,
PAGE_WIDTH,
inv.rows * SLOT_SIZE + 4,
StorageOverlay.TConfig.outlineActiveStoragePageColour.getEffectiveColourRGB()
)
- context.drawText(
- textRenderer, Text.literal(name), x + 6, y + 3,
+ context.drawString(
+ font, Component.literal(name), x + 6, y + 3,
if (slots == null) 0xFFFFFFFF.toInt() else 0xFFFFFF00.toInt(), true
)
context.drawGuiTexture(
slotRowSprite,
x + 2,
- y + 5 + textRenderer.fontHeight,
+ y + 5 + font.lineHeight,
PAGE_SLOTS_WIDTH,
inv.rows * SLOT_SIZE
)
inv.stacks.forEachIndexed { index, stack ->
val slotX = (index % 9) * SLOT_SIZE + x + 3
- val slotY = (index / 9) * SLOT_SIZE + y + 5 + textRenderer.fontHeight + 1
+ val slotY = (index / 9) * SLOT_SIZE + y + 5 + font.lineHeight + 1
if (slots == null) {
val fakeSlot = FakeSlot(stack, slotX, slotY)
SlotRenderEvents.Before.publish(SlotRenderEvents.Before(context, fakeSlot))
- context.drawItem(stack, slotX, slotY)
- context.drawStackOverlay(textRenderer, stack, slotX, slotY)
+ context.renderItem(stack, slotX, slotY)
+ context.renderItemDecorations(font, stack, slotX, slotY)
SlotRenderEvents.After.publish(SlotRenderEvents.After(context, fakeSlot))
val rect = getScrollPanelInner()
if (StorageOverlay.TConfig.showInactivePageTooltips && !stack.isEmpty &&
@@ -544,11 +544,11 @@ class StorageOverlayScreen : Screen(Text.literal("")) {
mouseX <= slotX + 16 && mouseY <= slotY + 16 &&
mouseY >= rect.minY && mouseY <= rect.maxY) {
try {
- context.drawItemTooltip(textRenderer, stack, mouseX, mouseY)
+ context.setTooltipForNextFrame(font, stack, mouseX, mouseY)
} catch (e: IllegalStateException) {
- context.drawTooltip(textRenderer, listOf(Text.of(Formatting.RED.toString() +
- "Error Getting Tooltip!"), Text.of(Formatting.YELLOW.toString() +
- "Open page to fix" + Formatting.RESET)), mouseX, mouseY)
+ context.setComponentTooltipForNextFrame(font, listOf(Component.nullToEmpty(ChatFormatting.RED.toString() +
+ "Error Getting Tooltip!"), Component.nullToEmpty(ChatFormatting.YELLOW.toString() +
+ "Open page to fix" + ChatFormatting.RESET)), mouseX, mouseY)
}
}
} else {
diff --git a/src/main/kotlin/features/inventory/storageoverlay/StorageOverviewScreen.kt b/src/main/kotlin/features/inventory/storageoverlay/StorageOverviewScreen.kt
index a55b5ac..3c40fc6 100644
--- a/src/main/kotlin/features/inventory/storageoverlay/StorageOverviewScreen.kt
+++ b/src/main/kotlin/features/inventory/storageoverlay/StorageOverviewScreen.kt
@@ -4,19 +4,19 @@ package moe.nea.firmament.features.inventory.storageoverlay
import org.lwjgl.glfw.GLFW
import kotlin.math.max
-import net.minecraft.block.Blocks
-import net.minecraft.client.gui.Click
-import net.minecraft.client.gui.DrawContext
-import net.minecraft.client.gui.screen.Screen
-import net.minecraft.client.input.KeyInput
-import net.minecraft.item.Item
-import net.minecraft.item.Items
-import net.minecraft.text.Text
-import net.minecraft.util.DyeColor
+import net.minecraft.world.level.block.Blocks
+import net.minecraft.client.input.MouseButtonEvent
+import net.minecraft.client.gui.GuiGraphics
+import net.minecraft.client.gui.screens.Screen
+import net.minecraft.client.input.KeyEvent
+import net.minecraft.world.item.Item
+import net.minecraft.world.item.Items
+import net.minecraft.network.chat.Component
+import net.minecraft.world.item.DyeColor
import moe.nea.firmament.util.MC
import moe.nea.firmament.util.toShedaniel
-class StorageOverviewScreen() : Screen(Text.empty()) {
+class StorageOverviewScreen() : Screen(Component.empty()) {
companion object {
val emptyStorageSlotItems = listOf<Item>(
Blocks.RED_STAINED_GLASS_PANE.asItem(),
@@ -37,19 +37,19 @@ class StorageOverviewScreen() : Screen(Text.empty()) {
scroll = scroll.coerceAtMost(getMaxScroll()).coerceAtLeast(0)
}
- override fun close() {
+ override fun onClose() {
if (!StorageOverlay.TConfig.retainScroll) scroll = 0
- super.close()
+ super.onClose()
}
- override fun render(context: DrawContext, mouseX: Int, mouseY: Int, delta: Float) {
+ override fun render(context: GuiGraphics, mouseX: Int, mouseY: Int, delta: Float) {
super.render(context, mouseX, mouseY, delta)
context.fill(0, 0, width, height, 0x90000000.toInt())
layoutedForEach { (key, value), offsetX, offsetY ->
- context.matrices.pushMatrix()
- context.matrices.translate(offsetX.toFloat(), offsetY.toFloat())
+ context.pose().pushMatrix()
+ context.pose().translate(offsetX.toFloat(), offsetY.toFloat())
renderStoragePage(context, value, mouseX - offsetX, mouseY - offsetY)
- context.matrices.popMatrix()
+ context.pose().popMatrix()
}
}
@@ -74,12 +74,12 @@ class StorageOverviewScreen() : Screen(Text.empty()) {
lastRenderedHeight = totalHeight + currentMaxHeight
}
- override fun mouseClicked(click: Click, doubled: Boolean): Boolean {
+ override fun mouseClicked(click: MouseButtonEvent, doubled: Boolean): Boolean {
layoutedForEach { (k, p), x, y ->
val rx = click.x - x
val ry = click.y - y
if (rx in (0.0..pageWidth.toDouble()) && ry in (0.0..getStorePageHeight(p).toDouble())) {
- close()
+ onClose()
StorageOverlay.lastStorageOverlay = this
k.navigateTo()
return true
@@ -89,7 +89,7 @@ class StorageOverviewScreen() : Screen(Text.empty()) {
}
fun getStorePageHeight(page: StorageData.StorageInventory): Int {
- return page.inventory?.rows?.let { it * 19 + MC.font.fontHeight + 2 } ?: 60
+ return page.inventory?.rows?.let { it * 19 + MC.font.lineHeight + 2 } ?: 60
}
override fun mouseScrolled(
@@ -106,31 +106,31 @@ class StorageOverviewScreen() : Screen(Text.empty()) {
private fun getMaxScroll() = lastRenderedHeight - height + 2 * StorageOverlay.TConfig.margin
- private fun renderStoragePage(context: DrawContext, page: StorageData.StorageInventory, mouseX: Int, mouseY: Int) {
- context.drawText(MC.font, page.title, 2, 2, -1, true)
+ private fun renderStoragePage(context: GuiGraphics, page: StorageData.StorageInventory, mouseX: Int, mouseY: Int) {
+ context.drawString(MC.font, page.title, 2, 2, -1, true)
val inventory = page.inventory
if (inventory == null) {
// TODO: Missing texture
context.fill(0, 0, pageWidth, 60, DyeColor.RED.toShedaniel().darker(4.0).color)
- context.drawCenteredTextWithShadow(MC.font, Text.literal("Not loaded yet"), pageWidth / 2, 30, -1)
+ context.drawCenteredString(MC.font, Component.literal("Not loaded yet"), pageWidth / 2, 30, -1)
return
}
for ((index, stack) in inventory.stacks.withIndex()) {
val x = (index % 9) * 19
- val y = (index / 9) * 19 + MC.font.fontHeight + 2
+ val y = (index / 9) * 19 + MC.font.lineHeight + 2
if (((mouseX - x) in 0 until 18) && ((mouseY - y) in 0 until 18)) {
context.fill(x, y, x + 18, y + 18, 0x80808080.toInt())
} else {
context.fill(x, y, x + 18, y + 18, 0x40808080.toInt())
}
- context.drawItem(stack, x + 1, y + 1)
- context.drawStackOverlay(MC.font, stack, x + 1, y + 1)
+ context.renderItem(stack, x + 1, y + 1)
+ context.renderItemDecorations(MC.font, stack, x + 1, y + 1)
}
}
- override fun keyPressed(input: KeyInput): Boolean {
- if (input.keycode == GLFW.GLFW_KEY_ESCAPE)
+ override fun keyPressed(input: KeyEvent): Boolean {
+ if (input.input() == GLFW.GLFW_KEY_ESCAPE)
isClosing = true
return super.keyPressed(input)
}
diff --git a/src/main/kotlin/features/inventory/storageoverlay/VirtualInventory.kt b/src/main/kotlin/features/inventory/storageoverlay/VirtualInventory.kt
index fddc189..69d686f 100644
--- a/src/main/kotlin/features/inventory/storageoverlay/VirtualInventory.kt
+++ b/src/main/kotlin/features/inventory/storageoverlay/VirtualInventory.kt
@@ -13,12 +13,12 @@ import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import kotlin.jvm.optionals.getOrNull
-import net.minecraft.item.ItemStack
-import net.minecraft.nbt.NbtCompound
+import net.minecraft.world.item.ItemStack
+import net.minecraft.nbt.CompoundTag
import net.minecraft.nbt.NbtIo
-import net.minecraft.nbt.NbtList
+import net.minecraft.nbt.ListTag
import net.minecraft.nbt.NbtOps
-import net.minecraft.nbt.NbtSizeTracker
+import net.minecraft.nbt.NbtAccounter
import moe.nea.firmament.Firmament
import moe.nea.firmament.features.inventory.storageoverlay.VirtualInventory.Serializer.writeToByteArray
import moe.nea.firmament.util.Base64Util
@@ -44,21 +44,21 @@ data class VirtualInventory(
object Serializer : KSerializer<VirtualInventory> {
fun writeToByteArray(value: VirtualInventory): ByteArray {
- val list = NbtList()
+ val list = ListTag()
val ops = getOps()
value.stacks.forEach {
- if (it.isEmpty) list.add(NbtCompound())
+ if (it.isEmpty) list.add(CompoundTag())
else list.add(ErrorUtil.catch("Could not serialize item") {
ItemStack.CODEC.encode(
it,
ops,
- NbtCompound()
+ CompoundTag()
).orThrow
}
- .or { NbtCompound() })
+ .or { CompoundTag() })
}
val baos = ByteArrayOutputStream()
- NbtIo.writeCompressed(NbtCompound().also { it.put(INVENTORY, list) }, baos)
+ NbtIo.writeCompressed(CompoundTag().also { it.put(INVENTORY, list) }, baos)
return baos.toByteArray()
}
@@ -68,11 +68,11 @@ data class VirtualInventory(
override fun deserialize(decoder: Decoder): VirtualInventory {
val s = decoder.decodeString()
- val n = NbtIo.readCompressed(ByteArrayInputStream(Base64Util.decodeBytes(s)), NbtSizeTracker.of(100_000_000))
+ val n = NbtIo.readCompressed(ByteArrayInputStream(Base64Util.decodeBytes(s)), NbtAccounter.create(100_000_000))
val items = n.getList(INVENTORY).getOrNull()
val ops = getOps()
return VirtualInventory(items?.map {
- it as NbtCompound
+ it as CompoundTag
if (it.isEmpty) ItemStack.EMPTY
else ErrorUtil.catch("Could not deserialize item") {
ItemStack.CODEC.parse(ops, it).orThrow