Add tools for copying id, texture id and nbt data

This commit is contained in:
nea
2023-09-09 03:37:29 +02:00
parent e0f784a1b2
commit 255e4f5899
9 changed files with 250 additions and 114 deletions

View File

@@ -16,5 +16,5 @@ import org.spongepowered.asm.mixin.gen.Accessor;
public interface AccessorHandledScreen {
@Accessor("focusedSlot")
@Nullable
Slot getFocusedSlot_NEU();
Slot getFocusedSlot_Firmament();
}

View File

@@ -13,6 +13,7 @@ import moe.nea.firmament.features.chat.ChatLinks
import moe.nea.firmament.features.debug.DebugView
import moe.nea.firmament.features.debug.DeveloperFeatures
import moe.nea.firmament.features.debug.MinorTrolling
import moe.nea.firmament.features.debug.PowerUserTools
import moe.nea.firmament.features.fixes.Fixes
import moe.nea.firmament.features.inventory.CraftingOverlay
import moe.nea.firmament.features.inventory.PriceData
@@ -48,6 +49,7 @@ object FeatureManager : DataHolder<FeatureManager.Config>(serializer(), "feature
loadFeature(SlotLocking)
loadFeature(StorageOverlay)
loadFeature(CraftingOverlay)
loadFeature(PowerUserTools)
loadFeature(ChatLinks)
loadFeature(SaveCursorPosition)
loadFeature(CustomSkyBlockTextures)

View File

@@ -68,7 +68,7 @@ object DeveloperFeatures : FirmamentFeature {
HandledScreenKeyPressedEvent.subscribe {
if (it.matches(IKeyBinding.ofKeyCode(GLFW.GLFW_KEY_K))) {
it.screen as AccessorHandledScreen
val focussedSlot = it.screen.focusedSlot_NEU ?: return@subscribe
val focussedSlot = it.screen.focusedSlot_Firmament ?: return@subscribe
val item = focussedSlot.stack ?: return@subscribe
val ident = item.skyBlockId?.identifier.toString()
MinecraftClient.getInstance().inGameHud.chatHud.addMessage(

View File

@@ -0,0 +1,94 @@
/*
* SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package moe.nea.firmament.features.debug
import net.minecraft.item.ItemStack
import net.minecraft.text.Text
import moe.nea.firmament.events.CustomItemModelEvent
import moe.nea.firmament.events.HandledScreenKeyPressedEvent
import moe.nea.firmament.events.ItemTooltipEvent
import moe.nea.firmament.events.ScreenOpenEvent
import moe.nea.firmament.events.TickEvent
import moe.nea.firmament.features.FirmamentFeature
import moe.nea.firmament.gui.config.ManagedConfig
import moe.nea.firmament.mixins.accessor.AccessorHandledScreen
import moe.nea.firmament.util.ClipboardUtils
import moe.nea.firmament.util.skyBlockId
object PowerUserTools : FirmamentFeature {
override val identifier: String
get() = "power-user"
object TConfig : ManagedConfig(identifier) {
val showItemIds by toggle("show-item-id") { false }
val copyItemId by keyBindingWithDefaultUnbound("copy-item-id")
val copyTexturePackId by keyBindingWithDefaultUnbound("copy-texture-pack-id")
val copyNbtData by keyBindingWithDefaultUnbound("copy-nbt-data")
}
override val config
get() = TConfig
var lastCopiedStack: Pair<ItemStack, Text>? = null
set(value) {
field = value
if (value != null)
lastCopiedStackViewTime = true
}
var lastCopiedStackViewTime = false
override fun onLoad() {
ItemTooltipEvent.subscribe {
if (TConfig.showItemIds) {
val id = it.stack.skyBlockId ?: return@subscribe
it.lines.add(Text.translatable("firmament.tooltip.skyblockid", id.neuItem))
}
val (item, text) = lastCopiedStack ?: return@subscribe
if (item != it.stack) {
lastCopiedStack = null
return@subscribe
}
lastCopiedStackViewTime = true
it.lines.add(text)
}
TickEvent.subscribe {
if (!lastCopiedStackViewTime)
lastCopiedStack = null
lastCopiedStackViewTime = false
}
ScreenOpenEvent.subscribe {
lastCopiedStack = null
}
HandledScreenKeyPressedEvent.subscribe {
if (it.screen !is AccessorHandledScreen) return@subscribe
val item = it.screen.focusedSlot_Firmament?.stack ?: return@subscribe
if (it.matches(TConfig.copyItemId)) {
val sbId = item.skyBlockId
if (sbId == null) {
lastCopiedStack = Pair(item, Text.translatable("firmament.tooltip.copied.skyblockid.fail"))
return@subscribe
}
ClipboardUtils.setTextContent(sbId.neuItem)
lastCopiedStack = Pair(item, Text.translatable("firmament.tooltip.copied.skyblockid", sbId.neuItem))
} else if (it.matches(TConfig.copyTexturePackId)) {
val model = CustomItemModelEvent.getModelIdentifier(item)
if (model == null) {
lastCopiedStack = Pair(item, Text.translatable("firmament.tooltip.copied.modelid.fail"))
return@subscribe
}
ClipboardUtils.setTextContent(model.toString())
lastCopiedStack = Pair(item, Text.translatable("firmament.tooltip.copied.modelid", model.toString()))
} else if (it.matches(TConfig.copyNbtData)) {
val nbt = item.orCreateNbt.toString()
ClipboardUtils.setTextContent(nbt)
lastCopiedStack = Pair(item, Text.translatable("firmament.tooltip.copied.nbt"))
}
}
}
}

View File

@@ -45,7 +45,7 @@ object SlotLocking : FirmamentFeature {
val inventory = MC.handledScreen ?: return@subscribe
inventory as AccessorHandledScreen
val slot = inventory.focusedSlot_NEU ?: return@subscribe
val slot = inventory.focusedSlot_Firmament ?: return@subscribe
val lockedSlots = lockedSlots ?: return@subscribe
if (slot.inventory is PlayerInventory) {
if (slot.index in lockedSlots) {

View File

@@ -19,7 +19,7 @@ object SkyblockItemIdFocusedStackProvider : FocusedStackProvider {
override fun provide(screen: Screen?, mouse: Point?): CompoundEventResult<EntryStack<*>> {
if (screen !is HandledScreen<*>) return CompoundEventResult.pass()
screen as AccessorHandledScreen
val focusedSlot = screen.focusedSlot_NEU ?: return CompoundEventResult.pass()
val focusedSlot = screen.focusedSlot_Firmament ?: return CompoundEventResult.pass()
val item = focusedSlot.stack ?: return CompoundEventResult.pass()
val skyblockId = item.skyBlockId ?: return CompoundEventResult.pass()
return CompoundEventResult.interruptTrue(SBItemEntryDefinition.getEntry(skyblockId))

View File

@@ -0,0 +1,28 @@
/*
* SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package moe.nea.firmament.util
import moe.nea.firmament.Firmament
object ClipboardUtils {
fun setTextContent(string: String) {
try {
MC.keyboard.clipboard = string.ifEmpty { " " }
} catch (e: Exception) {
Firmament.logger.error("Could not write clipboard", e)
}
}
fun getTextContents(): String {
try {
return MC.keyboard.clipboard ?: ""
} catch (e: Exception) {
Firmament.logger.error("Could not read clipboard", e)
return ""
}
}
}

View File

@@ -16,6 +16,7 @@ object MC {
player?.networkHandler?.sendCommand(command)
}
inline val keyboard get() = MinecraftClient.getInstance().keyboard
inline val textureManager get() = MinecraftClient.getInstance().textureManager
inline val inGameHud get() = MinecraftClient.getInstance().inGameHud
inline val font get() = MinecraftClient.getInstance().textRenderer

View File

@@ -108,5 +108,16 @@
"firmament.config.custom-skyblock-textures.cache-duration": "Model Cache Duration",
"firmament.config.custom-skyblock-textures.enabled": "Enable Custom Item Textures",
"firmament.config.fixes": "Fixes",
"firmament.config.fixes.player-skins": "Fix unsigned Player Skins"
"firmament.config.fixes.player-skins": "Fix unsigned Player Skins",
"firmament.config.power-user.show-item-id": "Show SkyBlock Ids",
"firmament.config.power-user.copy-item-id": "Copy SkyBlock Id",
"firmament.config.power-user.copy-texture-pack-id": "Copy Texture Pack Id",
"firmament.config.power-user.copy-nbt-data": "Copy NBT data",
"firmament.config.power-user": "Power Users",
"firmament.tooltip.skyblockid": "SkyBlock Id: %s",
"firmament.tooltip.copied.skyblockid.fail": "Failed to copy SkyBlock Id",
"firmament.tooltip.copied.skyblockid": "Copied SkyBlock Id: %s",
"firmament.tooltip.copied.modelid.fail": "Failed to copy Texture Id",
"firmament.tooltip.copied.modelid": "Copied Texture Id: %s",
"firmament.tooltip.copied.nbt": "Copied NBT data"
}