diff options
Diffstat (limited to 'src/main/kotlin/moe')
7 files changed, 128 insertions, 3 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt b/src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt index 781237e..ba665e4 100644 --- a/src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt +++ b/src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt @@ -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) diff --git a/src/main/kotlin/moe/nea/firmament/features/debug/DeveloperFeatures.kt b/src/main/kotlin/moe/nea/firmament/features/debug/DeveloperFeatures.kt index 20d1358..e045fa8 100644 --- a/src/main/kotlin/moe/nea/firmament/features/debug/DeveloperFeatures.kt +++ b/src/main/kotlin/moe/nea/firmament/features/debug/DeveloperFeatures.kt @@ -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( diff --git a/src/main/kotlin/moe/nea/firmament/features/debug/PowerUserTools.kt b/src/main/kotlin/moe/nea/firmament/features/debug/PowerUserTools.kt new file mode 100644 index 0000000..398042d --- /dev/null +++ b/src/main/kotlin/moe/nea/firmament/features/debug/PowerUserTools.kt @@ -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")) + } + } + } + + +} diff --git a/src/main/kotlin/moe/nea/firmament/features/inventory/SlotLocking.kt b/src/main/kotlin/moe/nea/firmament/features/inventory/SlotLocking.kt index ec86341..5de8951 100644 --- a/src/main/kotlin/moe/nea/firmament/features/inventory/SlotLocking.kt +++ b/src/main/kotlin/moe/nea/firmament/features/inventory/SlotLocking.kt @@ -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) { diff --git a/src/main/kotlin/moe/nea/firmament/rei/SkyblockItemIdFocusedStackProvider.kt b/src/main/kotlin/moe/nea/firmament/rei/SkyblockItemIdFocusedStackProvider.kt index a26ec53..c5bca1b 100644 --- a/src/main/kotlin/moe/nea/firmament/rei/SkyblockItemIdFocusedStackProvider.kt +++ b/src/main/kotlin/moe/nea/firmament/rei/SkyblockItemIdFocusedStackProvider.kt @@ -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)) diff --git a/src/main/kotlin/moe/nea/firmament/util/ClipboardUtils.kt b/src/main/kotlin/moe/nea/firmament/util/ClipboardUtils.kt new file mode 100644 index 0000000..d761a5a --- /dev/null +++ b/src/main/kotlin/moe/nea/firmament/util/ClipboardUtils.kt @@ -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 "" + } + } +} diff --git a/src/main/kotlin/moe/nea/firmament/util/MC.kt b/src/main/kotlin/moe/nea/firmament/util/MC.kt index 602d85a..78f2eec 100644 --- a/src/main/kotlin/moe/nea/firmament/util/MC.kt +++ b/src/main/kotlin/moe/nea/firmament/util/MC.kt @@ -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 |