aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/firmament/features/debug
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-05-07 21:11:09 +0200
committerLinnea Gräf <nea@nea.moe>2024-05-07 21:11:09 +0200
commit93e6e0ab16df0808ee7720202a32967eddcf5c10 (patch)
tree0939d44ec0c848f8712df8b03f30af1d34eabfa0 /src/main/kotlin/moe/nea/firmament/features/debug
parent8f3cc34740fcfe1572d23c8f1c1db1a309217b84 (diff)
downloadfirmament-93e6e0ab16df0808ee7720202a32967eddcf5c10.tar.gz
firmament-93e6e0ab16df0808ee7720202a32967eddcf5c10.tar.bz2
firmament-93e6e0ab16df0808ee7720202a32967eddcf5c10.zip
Fix up most of the remaining event handlers
[no changelog]
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/features/debug')
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/debug/DeveloperFeatures.kt4
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/debug/MinorTrolling.kt18
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/debug/PowerUserTools.kt175
3 files changed, 100 insertions, 97 deletions
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 6bbbdf0..1d7ce49 100644
--- a/src/main/kotlin/moe/nea/firmament/features/debug/DeveloperFeatures.kt
+++ b/src/main/kotlin/moe/nea/firmament/features/debug/DeveloperFeatures.kt
@@ -55,9 +55,5 @@ object DeveloperFeatures : FirmamentFeature {
}
return reloadFuture.thenCompose { client.reloadResources() }
}
-
-
- override fun onLoad() {
- }
}
diff --git a/src/main/kotlin/moe/nea/firmament/features/debug/MinorTrolling.kt b/src/main/kotlin/moe/nea/firmament/features/debug/MinorTrolling.kt
index 95c77ab..57fd8e2 100644
--- a/src/main/kotlin/moe/nea/firmament/features/debug/MinorTrolling.kt
+++ b/src/main/kotlin/moe/nea/firmament/features/debug/MinorTrolling.kt
@@ -6,9 +6,10 @@
package moe.nea.firmament.features.debug
+import net.minecraft.text.Text
+import moe.nea.firmament.annotations.Subscribe
import moe.nea.firmament.events.ModifyChatEvent
import moe.nea.firmament.features.FirmamentFeature
-import net.minecraft.text.Text
// In memorian Dulkir
@@ -19,13 +20,12 @@ object MinorTrolling : FirmamentFeature {
val trollers = listOf("nea89o", "lrg89")
val t = "From(?: \\[[^\\]]+])? ([^:]+): (.*)".toRegex()
- override fun onLoad() {
- ModifyChatEvent.subscribe {
- val m = t.matchEntire(it.unformattedString) ?: return@subscribe
- val (_, name, text) = m.groupValues
- if (name !in trollers) return@subscribe
- if (!text.startsWith("c:")) return@subscribe
- it.replaceWith = Text.literal(text.substring(2).replace("&", "§"))
- }
+ @Subscribe
+ fun onTroll(it: ModifyChatEvent) {
+ val m = t.matchEntire(it.unformattedString) ?: return
+ val (_, name, text) = m.groupValues
+ if (name !in trollers) return
+ if (!text.startsWith("c:")) return
+ it.replaceWith = Text.literal(text.substring(2).replace("&", "§"))
}
}
diff --git a/src/main/kotlin/moe/nea/firmament/features/debug/PowerUserTools.kt b/src/main/kotlin/moe/nea/firmament/features/debug/PowerUserTools.kt
index 99ef0d5..d530487 100644
--- a/src/main/kotlin/moe/nea/firmament/features/debug/PowerUserTools.kt
+++ b/src/main/kotlin/moe/nea/firmament/features/debug/PowerUserTools.kt
@@ -15,6 +15,7 @@ import net.minecraft.item.Items
import net.minecraft.text.Text
import net.minecraft.util.hit.BlockHitResult
import net.minecraft.util.hit.HitResult
+import moe.nea.firmament.annotations.Subscribe
import moe.nea.firmament.events.CustomItemModelEvent
import moe.nea.firmament.events.HandledScreenKeyPressedEvent
import moe.nea.firmament.events.ItemTooltipEvent
@@ -54,42 +55,6 @@ object PowerUserTools : FirmamentFeature {
var lastCopiedStackViewTime = false
override fun onLoad() {
- ItemTooltipEvent.subscribe {
- if (TConfig.showItemIds) {
- val id = it.stack.skyBlockId ?: return@subscribe
- it.lines.add(Text.stringifiedTranslatable("firmament.tooltip.skyblockid", id.neuItem))
- }
- val (item, text) = lastCopiedStack ?: return@subscribe
- if (!ItemStack.areEqual(item, it.stack)) {
- lastCopiedStack = null
- return@subscribe
- }
- lastCopiedStackViewTime = true
- it.lines.add(text)
- }
- WorldKeyboardEvent.subscribe {
- if (it.matches(TConfig.copySkullTexture)) {
- val p = MC.camera ?: return@subscribe
- val blockHit = p.raycast(20.0, 0.0f, false) ?: return@subscribe
- if (blockHit.type != HitResult.Type.BLOCK || blockHit !is BlockHitResult) {
- MC.sendChat(Text.translatable("firmament.tooltip.copied.skull.fail"))
- return@subscribe
- }
- val blockAt = p.world.getBlockState(blockHit.blockPos)?.block
- val entity = p.world.getBlockEntity(blockHit.blockPos)
- if (blockAt !is SkullBlock || entity !is SkullBlockEntity || entity.owner == null) {
- MC.sendChat(Text.translatable("firmament.tooltip.copied.skull.fail"))
- return@subscribe
- }
- val id = CustomSkyBlockTextures.getSkullTexture(entity.owner!!)
- if (id == null) {
- MC.sendChat(Text.translatable("firmament.tooltip.copied.skull.fail"))
- } else {
- ClipboardUtils.setTextContent(id.toString())
- MC.sendChat(Text.stringifiedTranslatable("firmament.tooltip.copied.skull", id.toString()))
- }
- }
- }
TickEvent.subscribe {
if (!lastCopiedStackViewTime)
lastCopiedStack = null
@@ -98,56 +63,98 @@ object PowerUserTools : FirmamentFeature {
ScreenChangeEvent.subscribe {
lastCopiedStack = null
}
- HandledScreenKeyPressedEvent.subscribe {
- if (it.screen !is AccessorHandledScreen) return@subscribe
- val item = it.screen.focusedItemStack ?: 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.stringifiedTranslatable("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.stringifiedTranslatable("firmament.tooltip.copied.modelid", model.toString()))
- } else if (it.matches(TConfig.copyNbtData)) {
- // TODO: copy full nbt
- val nbt = item.get(DataComponentTypes.CUSTOM_DATA)?.nbt?.toString() ?: "<empty>"
- ClipboardUtils.setTextContent(nbt)
- lastCopiedStack = Pair(item, Text.translatable("firmament.tooltip.copied.nbt"))
- } else if (it.matches(TConfig.copySkullTexture)) {
- if (item.item != Items.PLAYER_HEAD) {
- lastCopiedStack = Pair(item, Text.translatable("firmament.tooltip.copied.skull-id.fail.no-skull"))
- return@subscribe
- }
- val profile = item.get(DataComponentTypes.PROFILE)
- if (profile == null) {
- lastCopiedStack = Pair(item, Text.translatable("firmament.tooltip.copied.skull-id.fail.no-profile"))
- return@subscribe
- }
- val skullTexture = CustomSkyBlockTextures.getSkullTexture(profile)
- if (skullTexture == null) {
- lastCopiedStack = Pair(item, Text.translatable("firmament.tooltip.copied.skull-id.fail.no-texture"))
- return@subscribe
- }
- ClipboardUtils.setTextContent(skullTexture.toString())
- lastCopiedStack =
- Pair(
- item,
- Text.stringifiedTranslatable("firmament.tooltip.copied.skull-id", skullTexture.toString())
- )
- println("Copied skull id: $skullTexture")
+ }
+
+ @Subscribe
+ fun copyInventoryInfo(it: HandledScreenKeyPressedEvent) {
+ if (it.screen !is AccessorHandledScreen) return
+ val item = it.screen.focusedItemStack ?: return
+ if (it.matches(TConfig.copyItemId)) {
+ val sbId = item.skyBlockId
+ if (sbId == null) {
+ lastCopiedStack = Pair(item, Text.translatable("firmament.tooltip.copied.skyblockid.fail"))
+ return
+ }
+ ClipboardUtils.setTextContent(sbId.neuItem)
+ lastCopiedStack =
+ Pair(item, Text.stringifiedTranslatable("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
+ }
+ ClipboardUtils.setTextContent(model.toString())
+ lastCopiedStack =
+ Pair(item, Text.stringifiedTranslatable("firmament.tooltip.copied.modelid", model.toString()))
+ } else if (it.matches(TConfig.copyNbtData)) {
+ // TODO: copy full nbt
+ val nbt = item.get(DataComponentTypes.CUSTOM_DATA)?.nbt?.toString() ?: "<empty>"
+ ClipboardUtils.setTextContent(nbt)
+ lastCopiedStack = Pair(item, Text.translatable("firmament.tooltip.copied.nbt"))
+ } else if (it.matches(TConfig.copySkullTexture)) {
+ if (item.item != Items.PLAYER_HEAD) {
+ lastCopiedStack = Pair(item, Text.translatable("firmament.tooltip.copied.skull-id.fail.no-skull"))
+ return
+ }
+ val profile = item.get(DataComponentTypes.PROFILE)
+ if (profile == null) {
+ lastCopiedStack = Pair(item, Text.translatable("firmament.tooltip.copied.skull-id.fail.no-profile"))
+ return
+ }
+ val skullTexture = CustomSkyBlockTextures.getSkullTexture(profile)
+ if (skullTexture == null) {
+ lastCopiedStack = Pair(item, Text.translatable("firmament.tooltip.copied.skull-id.fail.no-texture"))
+ return
}
+ ClipboardUtils.setTextContent(skullTexture.toString())
+ lastCopiedStack =
+ Pair(
+ item,
+ Text.stringifiedTranslatable("firmament.tooltip.copied.skull-id", skullTexture.toString())
+ )
+ println("Copied skull id: $skullTexture")
+ }
+ }
+
+ @Subscribe
+ fun onCopyWorldInfo(it: WorldKeyboardEvent) {
+ if (it.matches(TConfig.copySkullTexture)) {
+ val p = MC.camera ?: return
+ val blockHit = p.raycast(20.0, 0.0f, false) ?: return
+ if (blockHit.type != HitResult.Type.BLOCK || blockHit !is BlockHitResult) {
+ MC.sendChat(Text.translatable("firmament.tooltip.copied.skull.fail"))
+ return
+ }
+ val blockAt = p.world.getBlockState(blockHit.blockPos)?.block
+ val entity = p.world.getBlockEntity(blockHit.blockPos)
+ if (blockAt !is SkullBlock || entity !is SkullBlockEntity || entity.owner == null) {
+ MC.sendChat(Text.translatable("firmament.tooltip.copied.skull.fail"))
+ return
+ }
+ val id = CustomSkyBlockTextures.getSkullTexture(entity.owner!!)
+ if (id == null) {
+ MC.sendChat(Text.translatable("firmament.tooltip.copied.skull.fail"))
+ } else {
+ ClipboardUtils.setTextContent(id.toString())
+ MC.sendChat(Text.stringifiedTranslatable("firmament.tooltip.copied.skull", id.toString()))
+ }
+ }
+ }
+
+ @Subscribe
+ fun addItemId(it: ItemTooltipEvent) {
+ if (TConfig.showItemIds) {
+ val id = it.stack.skyBlockId ?: return
+ it.lines.add(Text.stringifiedTranslatable("firmament.tooltip.skyblockid", id.neuItem))
+ }
+ val (item, text) = lastCopiedStack ?: return
+ if (!ItemStack.areEqual(item, it.stack)) {
+ lastCopiedStack = null
+ return
}
+ lastCopiedStackViewTime = true
+ it.lines.add(text)
}