WIP: Port some 1.21.5 things
This commit is contained in:
@@ -3,6 +3,7 @@ package moe.nea.firmament.features.chat
|
||||
import io.ktor.client.request.get
|
||||
import io.ktor.client.statement.bodyAsChannel
|
||||
import io.ktor.utils.io.jvm.javaio.toInputStream
|
||||
import java.net.URI
|
||||
import java.net.URL
|
||||
import java.util.Collections
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
@@ -78,7 +79,7 @@ object ChatLinks : FirmamentFeature {
|
||||
val texId = Firmament.identifier("dynamic_image_preview${nextTexId.getAndIncrement()}")
|
||||
MC.textureManager.registerTexture(
|
||||
texId,
|
||||
NativeImageBackedTexture(image)
|
||||
NativeImageBackedTexture({ texId.path }, image)
|
||||
)
|
||||
Image(texId, image.width, image.height)
|
||||
} else
|
||||
@@ -102,8 +103,8 @@ object ChatLinks : FirmamentFeature {
|
||||
if (it.screen !is ChatScreen) return
|
||||
val hoveredComponent =
|
||||
MC.inGameHud.chatHud.getTextStyleAt(it.mouseX.toDouble(), it.mouseY.toDouble()) ?: return
|
||||
val hoverEvent = hoveredComponent.hoverEvent ?: return
|
||||
val value = hoverEvent.getValue(HoverEvent.Action.SHOW_TEXT) ?: return
|
||||
val hoverEvent = hoveredComponent.hoverEvent as? HoverEvent.ShowText ?: return
|
||||
val value = hoverEvent.value
|
||||
val url = urlRegex.matchEntire(value.unformattedString)?.groupValues?.get(0) ?: return
|
||||
if (!isImageUrl(url)) return
|
||||
val imageFuture = imageCache[url] ?: return
|
||||
@@ -149,8 +150,8 @@ object ChatLinks : FirmamentFeature {
|
||||
Text.literal(url).setStyle(
|
||||
Style.EMPTY.withUnderline(true).withColor(
|
||||
Formatting.AQUA
|
||||
).withHoverEvent(HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.literal(url)))
|
||||
.withClickEvent(ClickEvent(ClickEvent.Action.OPEN_URL, url))
|
||||
).withHoverEvent(HoverEvent.ShowText(Text.literal(url)))
|
||||
.withClickEvent(ClickEvent.OpenUrl(URI(url)))
|
||||
)
|
||||
)
|
||||
if (isImageUrl(url))
|
||||
|
||||
@@ -43,6 +43,7 @@ import moe.nea.firmament.util.mc.IntrospectableItemModelManager
|
||||
import moe.nea.firmament.util.mc.SNbtFormatter
|
||||
import moe.nea.firmament.util.mc.SNbtFormatter.Companion.toPrettyString
|
||||
import moe.nea.firmament.util.mc.displayNameAccordingToNbt
|
||||
import moe.nea.firmament.util.mc.iterableArmorItems
|
||||
import moe.nea.firmament.util.mc.loreAccordingToNbt
|
||||
import moe.nea.firmament.util.skyBlockId
|
||||
|
||||
@@ -108,7 +109,7 @@ object PowerUserTools : FirmamentFeature {
|
||||
MC.sendChat(Text.stringifiedTranslatable("firmament.poweruser.entity.position", target.pos))
|
||||
if (target is LivingEntity) {
|
||||
MC.sendChat(Text.translatable("firmament.poweruser.entity.armor"))
|
||||
for (armorItem in target.armorItems) {
|
||||
for ((slot, armorItem) in target.iterableArmorItems) {
|
||||
MC.sendChat(Text.translatable("firmament.poweruser.entity.armor.item", debugFormat(armorItem)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,7 +222,7 @@ object MinesweeperHelper {
|
||||
fun onChat(event: ProcessChatEvent) {
|
||||
if (CarnivalFeatures.TConfig.displayTutorials && event.unformattedString == startGameQuestion) {
|
||||
MC.sendChat(Text.translatable("firmament.carnival.tutorial.minesweeper").styled {
|
||||
it.withClickEvent(ClickEvent(ClickEvent.Action.RUN_COMMAND, "/firm minesweepertutorial"))
|
||||
it.withClickEvent(ClickEvent.RunCommand("/firm minesweepertutorial"))
|
||||
})
|
||||
}
|
||||
if (!CarnivalFeatures.TConfig.enableBombSolver) {
|
||||
@@ -259,7 +259,7 @@ object MinesweeperHelper {
|
||||
val boardPosition = BoardPosition.fromBlockPos(event.blockPos)
|
||||
log.log { "Breaking block at ${event.blockPos} ($boardPosition)" }
|
||||
gs.lastClickedPosition = boardPosition
|
||||
gs.lastDowsingMode = DowsingMode.fromItem(event.player.inventory.mainHandStack)
|
||||
gs.lastDowsingMode = DowsingMode.fromItem(event.player.mainHandStack)
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package moe.nea.firmament.features.inventory
|
||||
|
||||
import java.net.URI
|
||||
import net.fabricmc.loader.api.FabricLoader
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
@@ -38,7 +39,7 @@ object REIDependencyWarner {
|
||||
.white()
|
||||
.append(Text.literal("[").aqua())
|
||||
.append(Text.translatable("firmament.download", modName)
|
||||
.styled { it.withClickEvent(ClickEvent(ClickEvent.Action.OPEN_URL, modrinthLink(slug))) }
|
||||
.styled { it.withClickEvent(ClickEvent.OpenUrl(URI (modrinthLink(slug)))) }
|
||||
.yellow()
|
||||
.also {
|
||||
if (alreadyDownloaded)
|
||||
|
||||
@@ -4,6 +4,7 @@ package moe.nea.firmament.features.inventory
|
||||
|
||||
import java.util.UUID
|
||||
import org.lwjgl.glfw.GLFW
|
||||
import util.render.CustomRenderLayers
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.UseSerializers
|
||||
@@ -17,6 +18,9 @@ import kotlinx.serialization.json.JsonPrimitive
|
||||
import kotlinx.serialization.json.int
|
||||
import kotlinx.serialization.serializer
|
||||
import net.minecraft.client.gui.screen.ingame.HandledScreen
|
||||
import net.minecraft.client.render.RenderLayer
|
||||
import net.minecraft.client.render.RenderLayers
|
||||
import net.minecraft.client.render.TexturedRenderLayers
|
||||
import net.minecraft.entity.player.PlayerInventory
|
||||
import net.minecraft.screen.GenericContainerScreenHandler
|
||||
import net.minecraft.screen.slot.Slot
|
||||
@@ -45,7 +49,6 @@ import moe.nea.firmament.util.mc.ScreenUtil.getSlotByIndex
|
||||
import moe.nea.firmament.util.mc.SlotUtils.swapWithHotBar
|
||||
import moe.nea.firmament.util.mc.displayNameAccordingToNbt
|
||||
import moe.nea.firmament.util.mc.loreAccordingToNbt
|
||||
import moe.nea.firmament.util.render.GuiRenderLayers
|
||||
import moe.nea.firmament.util.render.drawLine
|
||||
import moe.nea.firmament.util.skyblock.DungeonUtil
|
||||
import moe.nea.firmament.util.skyblockUUID
|
||||
@@ -445,7 +448,7 @@ object SlotLocking : FirmamentFeature {
|
||||
val isUUIDLocked = (it.slot.stack?.skyblockUUID) in (lockedUUIDs ?: setOf())
|
||||
if (isSlotLocked || isUUIDLocked) {
|
||||
it.context.drawGuiTexture(
|
||||
GuiRenderLayers.GUI_TEXTURED_NO_DEPTH,
|
||||
RenderLayer::getGuiTexturedOverlay,
|
||||
when {
|
||||
isSlotLocked ->
|
||||
(Identifier.of("firmament:slot_locked"))
|
||||
|
||||
@@ -218,7 +218,7 @@ class StorageOverlayScreen : Screen(Text.literal("")) {
|
||||
}
|
||||
|
||||
fun drawPlayerInventory(context: DrawContext, mouseX: Int, mouseY: Int, delta: Float) {
|
||||
val items = MC.player?.inventory?.main ?: return
|
||||
val items = MC.player?.inventory?.mainStacks ?: return
|
||||
items.withIndex().forEach { (index, item) ->
|
||||
val (x, y) = getPlayerInventorySlotPosition(index)
|
||||
context.drawItem(item, x, y, 0)
|
||||
|
||||
@@ -11,6 +11,7 @@ import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
|
||||
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.nbt.NbtIo
|
||||
@@ -42,15 +43,15 @@ data class VirtualInventory(
|
||||
override fun deserialize(decoder: Decoder): VirtualInventory {
|
||||
val s = decoder.decodeString()
|
||||
val n = NbtIo.readCompressed(ByteArrayInputStream(s.decodeBase64Bytes()), NbtSizeTracker.of(100_000_000))
|
||||
val items = n.getList(INVENTORY, NbtCompound.COMPOUND_TYPE.toInt())
|
||||
val items = n.getList(INVENTORY).getOrNull()
|
||||
val ops = getOps()
|
||||
return VirtualInventory(items.map {
|
||||
return VirtualInventory(items?.map {
|
||||
it as NbtCompound
|
||||
if (it.isEmpty) ItemStack.EMPTY
|
||||
else ErrorUtil.catch("Could not deserialize item") {
|
||||
ItemStack.CODEC.parse(ops, it).orThrow
|
||||
}.or { ItemStack.EMPTY }
|
||||
})
|
||||
} ?: listOf())
|
||||
}
|
||||
|
||||
fun getOps() = TolerantRegistriesOps(NbtOps.INSTANCE, MC.currentOrDefaultRegistries)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package moe.nea.firmament.features.mining
|
||||
|
||||
import java.util.regex.Pattern
|
||||
import kotlin.jvm.optionals.getOrNull
|
||||
import kotlin.time.Duration
|
||||
import kotlin.time.Duration.Companion.seconds
|
||||
import net.minecraft.client.MinecraftClient
|
||||
@@ -144,8 +145,7 @@ object PickaxeAbility : FirmamentFeature {
|
||||
}
|
||||
} ?: return
|
||||
val extra = it.item.extraAttributes
|
||||
if (!extra.contains("drill_fuel")) return
|
||||
val fuel = extra.getInt("drill_fuel")
|
||||
val fuel = extra.getInt("drill_fuel").getOrNull() ?: return
|
||||
val percentage = fuel / maxFuel.toFloat()
|
||||
it.barOverride = DurabilityBarEvent.DurabilityBar(
|
||||
lerp(
|
||||
|
||||
Reference in New Issue
Block a user