From 82eb50282512650894f4bc12b2c276a1e1f2d2e7 Mon Sep 17 00:00:00 2001 From: ImToggle <98242902+ImToggle@users.noreply.github.com> Date: Sun, 13 Jul 2025 00:06:54 +0800 Subject: [PATCH 01/30] reboot --- .github/workflows/build.yml | 10 +- .github/workflows/mod_project_integration.yml | 17 - .gitignore | 379 ++++++++++++++- build.gradle.kts | 42 +- docs/chattabs.md | 256 ----------- docs/docs.md | 3 - gradle.properties | 18 +- gradlew | 2 +- root.gradle.kts | 18 - settings.gradle.kts | 21 - .../patcher/config/OldPatcherConfig.java | 7 - .../sk1er/patcher/config/PatcherConfig.java | 8 - .../com/llamalad7/betterchat/BetterChat.java | 7 - .../llamalad7/betterchat/ChatSettings.java | 7 - .../org/polyfrost/chatting/hook/ChatHook.java | 8 - .../polyfrost/chatting/hook/ChatLineHook.java | 19 - .../polyfrost/chatting/hook/GuiChatHook.java | 5 - .../chatting/hook/GuiNewChatHook.java | 15 - .../chatting/mixin/ChatHudAccessor.java | 60 +++ .../chatting/mixin/ChatHudMixin.java | 18 + .../chatting/mixin/ChatLineMixin.java | 146 ------ .../mixin/ChatStyle_UnderlineLinks_Mixin.java | 31 -- .../mixin/ClientCommandHandlerMixin.java | 33 -- .../chatting/mixin/EntityPlayerSPMixin.java | 41 -- .../chatting/mixin/EntityRendererMixin.java | 19 - ...meSettings_ChatScaleChangeEvent_Mixin.java | 22 - .../chatting/mixin/GuiChatMixin.java | 232 ---------- .../mixin/GuiContainerCreativeMixin.java | 20 - .../chatting/mixin/GuiIngameForgeMixin.java | 30 -- .../GuiIngameForge_DrawChatAccessor.java | 11 - .../chatting/mixin/GuiNewChatAccessor.java | 20 - .../chatting/mixin/GuiNewChatMixin.java | 431 ------------------ .../mixin/GuiNewChatMixin_ChatHeight.java | 26 -- .../mixin/GuiNewChatMixin_ChatPeek.java | 18 - .../mixin/GuiNewChatMixin_ChatSearching.java | 33 -- .../mixin/GuiNewChatMixin_ChatTabs.java | 56 --- .../mixin/GuiNewChatMixin_Movable.java | 87 ---- .../mixin/GuiNewChatMixin_Scrolling.java | 60 --- .../mixin/GuiNewChatMixin_SmoothMessages.java | 105 ----- .../mixin/GuiNewChatMixin_TextRendering.java | 29 -- .../chatting/mixin/GuiTextFieldMixin.java | 18 - .../chatting/mixin/GuiUtilsMixin.java | 35 -- .../chatting/mixin/InventoryPlayerMixin.java | 19 - .../mixin/compat/ChatPeekMixin_SkyHanni.java | 31 -- .../compat/ChatTabsMixin_SkytilsCopyChat.java | 45 -- .../EssentialKeybindingRegistryMixin.java | 31 -- .../org/polyfrost/chatting/ChatWindow.kt | 127 ++++++ .../kotlin/org/polyfrost/chatting/Chatting.kt | 268 +---------- .../org/polyfrost/chatting/ModCommand.kt | 15 + .../ChattingConfig.kt => ModConfig.kt} | 224 ++------- .../org/polyfrost/chatting/ModConstants.kt | 10 + .../org/polyfrost/chatting/chat/ChatHooks.kt | 35 -- .../polyfrost/chatting/chat/ChatInputBox.kt | 51 --- .../polyfrost/chatting/chat/ChatRegexes.kt | 11 - .../chatting/chat/ChatScrollingHook.kt | 5 - .../chatting/chat/ChatSearchingManager.kt | 69 --- .../polyfrost/chatting/chat/ChatShortcuts.kt | 79 ---- .../org/polyfrost/chatting/chat/ChatTab.kt | 114 ----- .../org/polyfrost/chatting/chat/ChatTabs.kt | 354 -------------- .../polyfrost/chatting/chat/ChatTabsJson.kt | 15 - .../org/polyfrost/chatting/chat/ChatWindow.kt | 217 --------- .../chatting/gui/components/CleanButton.kt | 110 ----- .../chatting/gui/components/ClearButton.kt | 58 --- .../chatting/gui/components/RenderType.kt | 7 - .../gui/components/ScreenshotButton.kt | 47 -- .../chatting/gui/components/SearchButton.kt | 80 ---- .../chatting/gui/components/TabButton.kt | 48 -- .../chatting/utils/ModCompatHooks.kt | 129 ------ .../polyfrost/chatting/utils/RenderUtils.kt | 115 ----- src/main/resources/assets/chatting/copy.png | Bin 121 -> 0 bytes src/main/resources/assets/chatting/delete.png | Bin 158 -> 0 bytes src/main/resources/assets/chatting/reply.png | Bin 120 -> 0 bytes .../resources/assets/chatting/screenshot.png | Bin 125 -> 0 bytes src/main/resources/assets/chatting/search.png | Bin 158 -> 0 bytes src/main/resources/chatting_dark.svg | 5 - src/main/resources/fabric.mod.json | 26 ++ src/main/resources/mcmod.info | 18 - src/main/resources/mixins.chatting.json | 39 +- versions/mainProject | 1 - 79 files changed, 725 insertions(+), 4101 deletions(-) delete mode 100644 .github/workflows/mod_project_integration.yml delete mode 100644 docs/chattabs.md delete mode 100644 docs/docs.md delete mode 100644 root.gradle.kts delete mode 100644 src/ducks/java/club/sk1er/patcher/config/OldPatcherConfig.java delete mode 100644 src/ducks/java/club/sk1er/patcher/config/PatcherConfig.java delete mode 100644 src/ducks/java/com/llamalad7/betterchat/BetterChat.java delete mode 100644 src/ducks/java/com/llamalad7/betterchat/ChatSettings.java delete mode 100644 src/main/java/org/polyfrost/chatting/hook/ChatHook.java delete mode 100644 src/main/java/org/polyfrost/chatting/hook/ChatLineHook.java delete mode 100644 src/main/java/org/polyfrost/chatting/hook/GuiChatHook.java delete mode 100644 src/main/java/org/polyfrost/chatting/hook/GuiNewChatHook.java create mode 100644 src/main/java/org/polyfrost/chatting/mixin/ChatHudAccessor.java create mode 100644 src/main/java/org/polyfrost/chatting/mixin/ChatHudMixin.java delete mode 100644 src/main/java/org/polyfrost/chatting/mixin/ChatLineMixin.java delete mode 100644 src/main/java/org/polyfrost/chatting/mixin/ChatStyle_UnderlineLinks_Mixin.java delete mode 100644 src/main/java/org/polyfrost/chatting/mixin/ClientCommandHandlerMixin.java delete mode 100644 src/main/java/org/polyfrost/chatting/mixin/EntityPlayerSPMixin.java delete mode 100644 src/main/java/org/polyfrost/chatting/mixin/EntityRendererMixin.java delete mode 100644 src/main/java/org/polyfrost/chatting/mixin/GameSettings_ChatScaleChangeEvent_Mixin.java delete mode 100644 src/main/java/org/polyfrost/chatting/mixin/GuiChatMixin.java delete mode 100644 src/main/java/org/polyfrost/chatting/mixin/GuiContainerCreativeMixin.java delete mode 100644 src/main/java/org/polyfrost/chatting/mixin/GuiIngameForgeMixin.java delete mode 100644 src/main/java/org/polyfrost/chatting/mixin/GuiIngameForge_DrawChatAccessor.java delete mode 100644 src/main/java/org/polyfrost/chatting/mixin/GuiNewChatAccessor.java delete mode 100644 src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin.java delete mode 100644 src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin_ChatHeight.java delete mode 100644 src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin_ChatPeek.java delete mode 100644 src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin_ChatSearching.java delete mode 100644 src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin_ChatTabs.java delete mode 100644 src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin_Movable.java delete mode 100644 src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin_Scrolling.java delete mode 100644 src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin_SmoothMessages.java delete mode 100644 src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin_TextRendering.java delete mode 100644 src/main/java/org/polyfrost/chatting/mixin/GuiTextFieldMixin.java delete mode 100644 src/main/java/org/polyfrost/chatting/mixin/GuiUtilsMixin.java delete mode 100644 src/main/java/org/polyfrost/chatting/mixin/InventoryPlayerMixin.java delete mode 100644 src/main/java/org/polyfrost/chatting/mixin/compat/ChatPeekMixin_SkyHanni.java delete mode 100644 src/main/java/org/polyfrost/chatting/mixin/compat/ChatTabsMixin_SkytilsCopyChat.java delete mode 100644 src/main/java/org/polyfrost/chatting/mixin/compat/EssentialKeybindingRegistryMixin.java create mode 100644 src/main/kotlin/org/polyfrost/chatting/ChatWindow.kt create mode 100644 src/main/kotlin/org/polyfrost/chatting/ModCommand.kt rename src/main/kotlin/org/polyfrost/chatting/{config/ChattingConfig.kt => ModConfig.kt} (56%) create mode 100644 src/main/kotlin/org/polyfrost/chatting/ModConstants.kt delete mode 100644 src/main/kotlin/org/polyfrost/chatting/chat/ChatHooks.kt delete mode 100644 src/main/kotlin/org/polyfrost/chatting/chat/ChatInputBox.kt delete mode 100644 src/main/kotlin/org/polyfrost/chatting/chat/ChatRegexes.kt delete mode 100644 src/main/kotlin/org/polyfrost/chatting/chat/ChatScrollingHook.kt delete mode 100644 src/main/kotlin/org/polyfrost/chatting/chat/ChatSearchingManager.kt delete mode 100644 src/main/kotlin/org/polyfrost/chatting/chat/ChatShortcuts.kt delete mode 100644 src/main/kotlin/org/polyfrost/chatting/chat/ChatTab.kt delete mode 100644 src/main/kotlin/org/polyfrost/chatting/chat/ChatTabs.kt delete mode 100644 src/main/kotlin/org/polyfrost/chatting/chat/ChatTabsJson.kt delete mode 100644 src/main/kotlin/org/polyfrost/chatting/chat/ChatWindow.kt delete mode 100644 src/main/kotlin/org/polyfrost/chatting/gui/components/CleanButton.kt delete mode 100644 src/main/kotlin/org/polyfrost/chatting/gui/components/ClearButton.kt delete mode 100644 src/main/kotlin/org/polyfrost/chatting/gui/components/RenderType.kt delete mode 100644 src/main/kotlin/org/polyfrost/chatting/gui/components/ScreenshotButton.kt delete mode 100644 src/main/kotlin/org/polyfrost/chatting/gui/components/SearchButton.kt delete mode 100644 src/main/kotlin/org/polyfrost/chatting/gui/components/TabButton.kt delete mode 100644 src/main/kotlin/org/polyfrost/chatting/utils/ModCompatHooks.kt delete mode 100644 src/main/kotlin/org/polyfrost/chatting/utils/RenderUtils.kt delete mode 100644 src/main/resources/assets/chatting/copy.png delete mode 100644 src/main/resources/assets/chatting/delete.png delete mode 100644 src/main/resources/assets/chatting/reply.png delete mode 100644 src/main/resources/assets/chatting/screenshot.png delete mode 100644 src/main/resources/assets/chatting/search.png delete mode 100644 src/main/resources/chatting_dark.svg create mode 100644 src/main/resources/fabric.mod.json delete mode 100644 src/main/resources/mcmod.info delete mode 100644 versions/mainProject diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d4a420f..62008db 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,15 +23,11 @@ jobs: with: fetch-depth: 10 - - name: Set up JDK 8, 16, 17, 21 + - name: Set up JDK 17 uses: actions/setup-java@v4 with: + java-version: 21 distribution: temurin - java-version: | - 8 - 16 - 17 - 21 - uses: actions/cache@v4 with: @@ -48,4 +44,4 @@ jobs: run: chmod +x ./gradlew - name: Build - run: ./gradlew build --no-daemon + run: ./gradlew build --no-daemon \ No newline at end of file diff --git a/.github/workflows/mod_project_integration.yml b/.github/workflows/mod_project_integration.yml deleted file mode 100644 index ddd613b..0000000 --- a/.github/workflows/mod_project_integration.yml +++ /dev/null @@ -1,17 +0,0 @@ -name: Mod-Project Integration - -on: - issues: - types: [opened] - pull_request: - types: [opened] - -jobs: - add-to-project: - name: Add issue/PR to project - runs-on: ubuntu-latest - steps: - - uses: actions/add-to-project@v1.0.2 - with: - project-url: https://github.com/orgs/Polyfrost/projects/9 - github-token: ${{ secrets.ADD_TO_PROJECT_PAT }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 74b86e0..6de7fc5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ # eclipse -eclipse bin *.launch .settings @@ -9,7 +8,6 @@ bin # idea out -classes *.ipr *.iws *.iml @@ -19,12 +17,377 @@ classes build .gradle -#Netbeans -.nb-gradle -.nb-gradle-properties - # other +eclipse run +build - Copy.gradle +.vscode +.devauth +.DS_STORE + + +# Created by https://www.toptal.com/developers/gitignore/api/java,gradle,forgegradle,kotlin,macos,intellij,intellij+all,eclipse,visualstudiocode +# Edit at https://www.toptal.com/developers/gitignore?templates=java,gradle,forgegradle,kotlin,macos,intellij,intellij+all,eclipse,visualstudiocode + +### Eclipse ### +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.settings/ +.loadpath +.recommenders + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# PyDev specific (Python IDE for Eclipse) +*.pydevproject + +# CDT-specific (C/C++ Development Tooling) +.cproject + +# CDT- autotools +.autotools + +# Java annotation processor (APT) +.factorypath + +# PDT-specific (PHP Development Tools) +.buildpath + +# sbteclipse plugin +.target + +# Tern plugin +.tern-project + +# TeXlipse plugin +.texlipse + +# STS (Spring Tool Suite) +.springBeans + +# Code Recommenders +.recommenders/ + +# Annotation Processing +.apt_generated/ +.apt_generated_test/ + +# Scala IDE specific (Scala & Java development for Eclipse) +.cache-main +.scala_dependencies +.worksheet + +# Uncomment this line if you wish to ignore the project description file. +# Typically, this file would be tracked if it contains build/dependency configurations: +#.project + +### Eclipse Patch ### +# Spring Boot Tooling +.sts4-cache/ + +### ForgeGradle ### +# Minecraft client/server files +run/ + +### Intellij ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# SonarLint plugin +.idea/sonarlint/ + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### Intellij Patch ### +# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 + +# *.iml +# modules.xml +# .idea/misc.xml +# *.ipr + +# Sonarlint plugin +# https://plugins.jetbrains.com/plugin/7973-sonarlint +.idea/**/sonarlint/ + +# SonarQube Plugin +# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin +.idea/**/sonarIssues.xml + +# Markdown Navigator plugin +# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced +.idea/**/markdown-navigator.xml +.idea/**/markdown-navigator-enh.xml +.idea/**/markdown-navigator/ + +# Cache file creation bug +# See https://youtrack.jetbrains.com/issue/JBR-2257 +.idea/$CACHE_FILE$ + +# CodeStream plugin +# https://plugins.jetbrains.com/plugin/12206-codestream +.idea/codestream.xml + +# Azure Toolkit for IntelliJ plugin +# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij +.idea/**/azureSettings.xml + +### Intellij+all ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff + +# AWS User-specific + +# Generated files + +# Sensitive or high-churn files + +# Gradle + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake + +# Mongo Explorer plugin + +# File-based project format + +# IntelliJ + +# mpeltonen/sbt-idea plugin + +# JIRA plugin + +# Cursive Clojure plugin + +# SonarLint plugin + +# Crashlytics plugin (for Android Studio and IntelliJ) + +# Editor-based Rest Client + +# Android studio 3.1+ serialized cache file + +### Intellij+all Patch ### +# Ignore everything but code style settings and run configurations +# that are supposed to be shared within teams. + +.idea/* + +!.idea/codeStyles +!.idea/runConfigurations + +### Java ### +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +replay_pid* + +### Kotlin ### +# Compiled class file + +# Log file + +# BlueJ files + +# Mobile Tools for Java (J2ME) + +# Package Files # + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml + +### macOS ### +# General .DS_Store -Thumbs.db -.vscode \ No newline at end of file +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### macOS Patch ### +# iCloud generated files +*.icloud + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +!.vscode/*.code-snippets + +# Local History for Visual Studio Code +.history/ + +# Built Visual Studio Code Extensions +*.vsix + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history +.ionide + +# Support for Project snippet scope +.vscode/*.code-snippets + +# Ignore code-workspaces +*.code-workspace + +### Gradle ### +.gradle +**/build/ +!src/**/build/ + +# Ignore Gradle GUI config +gradle-app.setting + +# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) +!gradle-wrapper.jar + +# Avoid ignore Gradle wrappper properties +!gradle-wrapper.properties + +# Cache of project +.gradletasknamecache + +# Eclipse Gradle plugin generated files +# Eclipse Core +.project +# JDT-specific (Eclipse Java Development Tools) +.classpath + +# End of https://www.toptal.com/developers/gitignore/api/java,gradle,forgegradle,kotlin,macos,intellij,intellij+all,eclipse,visualstudiocode diff --git a/build.gradle.kts b/build.gradle.kts index f4acb5e..aca15ab 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,46 +4,36 @@ import dev.deftu.gradle.utils.GameSide plugins { java - kotlin("jvm") - id("dev.deftu.gradle.multiversion") // Applies preprocessing for multiple versions of Minecraft and/or multiple mod loaders. - id("dev.deftu.gradle.tools") // Applies several configurations to things such as the Java version, project name/version, etc. - id("dev.deftu.gradle.tools.resources") // Applies resource processing so that we can replace tokens, such as our mod name/version, in our resources. - id("dev.deftu.gradle.tools.bloom") // Applies the Bloom plugin, which allows us to replace tokens in our source files, such as being able to use `@MOD_VERSION` in our source files. - id("dev.deftu.gradle.tools.shadow") // Applies the Shadow plugin, which allows us to shade our dependencies into our mod JAR. This is NOT recommended for Fabric mods, but we have an *additional* configuration for those! - id("dev.deftu.gradle.tools.ducks") // Creates a ducks source set, which allows us to use theoretical classes which may not exist at runtime (such as things which are in other mods). - id("dev.deftu.gradle.tools.minecraft.loom") // Applies the Loom plugin, which automagically configures Essential's Architectury Loom plugin for you. - id("dev.deftu.gradle.tools.minecraft.releases") // Applies the Minecraft auto-releasing plugin, which allows you to automatically release your mod to CurseForge and Modrinth. + kotlin("jvm") version("2.0.10") + val dgtVersion = "2.39.0" + id("dev.deftu.gradle.tools") version(dgtVersion) // Applies several configurations to things such as the Java version, project name/version, etc. + id("dev.deftu.gradle.tools.resources") version(dgtVersion) // Applies resource processing so that we can replace tokens, such as our mod name/version, in our resources. + id("dev.deftu.gradle.tools.bloom") version(dgtVersion) // Applies the Bloom plugin, which allows us to replace tokens in our source files, such as being able to use `@MOD_VERSION` in our source files. + id("dev.deftu.gradle.tools.shadow") version(dgtVersion) // Applies the Shadow plugin, which allows us to shade our dependencies into our mod JAR. This is NOT recommended for Fabric mods, but we have an *additional* configuration for those! + id("dev.deftu.gradle.tools.minecraft.loom") version(dgtVersion) // Applies the Loom plugin, which automagically configures Essential's Architectury Loom plugin for you. + id("dev.deftu.gradle.tools.minecraft.releases") version(dgtVersion) // Applies the Minecraft auto-releasing plugin, which allows you to automatically release your mod to CurseForge and Modrinth. } +//dependencies { +// compileOnly("dev.deftu:omnicore-1.21.5-fabric:0.34.0") +//} + toolkitLoomHelper { useOneConfig { version = "1.0.0-alpha.106" loaderVersion = "1.1.0-alpha.46" - usePolyMixin = true - polyMixinVersion = "0.8.4+build.2" - - applyLoaderTweaker = true - for (module in arrayOf("commands", "config", "config-impl", "events", "internal", "ui", "utils")) { +module } } + useDevAuth("1.2.1") + useMixinExtras("0.4.1") + // Turns off the server-side run configs, as we're building a client-sided mod. disableRunConfigs(GameSide.SERVER) // Defines the name of the Mixin refmap, which is used to map the Mixin classes to the obfuscated Minecraft classes. - if (!mcData.isNeoForge) { - useMixinRefMap(modData.id) - } - - if (mcData.isForge) { - // Configures the Mixin tweaker if we are building for Forge. - useForgeMixin(modData.id) - } + useMixinRefMap(modData.id) } - -dependencies { - implementation(shade("com.github.ben-manes.caffeine:caffeine:2.9.3")!!) -} \ No newline at end of file diff --git a/docs/chattabs.md b/docs/chattabs.md deleted file mode 100644 index ca2740d..0000000 --- a/docs/chattabs.md +++ /dev/null @@ -1,256 +0,0 @@ -# Chatting Chat Tabs - -## Syntax - -The file for Chat Tabs is in `{MINECRAFT DIRECTORY}/OneConfig/profiles/{PROFILE}/chattabs.json`. However, Chatting versions below 1.4.2-beta5 use `{MINECRAFT DIRECTORY}/W-OVERFLOW/Chatting/chattabs.json`. The default file will look -something like this: - -```json -{ - "tabs": [ - { - "enabled": true, - "name": "ALL", - "unformatted": false, - "lowercase": false, - "color": 14737632, - "hovered_color": 16777120, - "selected_color": 10526880 - }, - { - "enabled": true, - "name": "PARTY", - "unformatted": false, - "lowercase": false, - "starts": [ - "§r§9Party §8> ", - "§r§9P §8> ", - "§eThe party was transferred to §r", - "§eKicked §r" - ], - "contains": [ - "§r§ehas invited you to join their party!" - ], - "ends": [ - "§r§eto the party! They have §r§c60 §r§eseconds to accept.§r", - "§r§ehas disbanded the party!§r", - "§r§ehas disconnected, they have §r§c5 §r§eminutes to rejoin before they are removed from the party.§r", - " §r§ejoined the party.§r", - " §r§ehas left the party.§r", - " §r§ehas been removed from the party.§r", - "§r§e because they were offline.§r" - ], - "equals": [ - "§cThe party was disbanded because all invites expired and the party was empty§r" - ], - "regex": [ - "(§r)*(§9Party §8>)+(.*)", - "(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+) §r§einvited §r(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+) §r§eto the party! They have §r§c60 §r§eseconds to accept\\.§r", - "(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+) §r§ehas left the party\\.§r", - "(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+) §r§ejoined the party\\.§r", - "§eYou left the party\\.§r", - "§eYou have joined §r(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+)'s §r§eparty!§r", - "§cThe party was disbanded because all invites expired and the party was empty§r", - "§cYou cannot invite that player since they're not online\\.§r", - "§eThe party leader, §r(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+)§r§e, warped you to §r(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+)§r§e's house\\.§r", - "§eSkyBlock Party Warp §r§7\\([0-9]+ players?\\)§r", - "§a. §r(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+)§r§f §r§awarped to your server§r", - "§eYou summoned §r(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+)§r§f §r§eto your server\\.§r", - "§eThe party leader, §r(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+)§r§e, warped you to their house\\.§r", - "(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+) §r§aenabled Private Game§r", - "(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+) §r§cdisabled Private Game§r", - "§cThe party is now muted\\. §r", - "§aThe party is no longer muted\\.§r", - "§cThere are no offline players to remove\\.§r", - "(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+) §r§ehas been removed from the party\\.§r", - "§eThe party was transferred to §r(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+) §r§eby §r(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+)§r", - "(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+)§r§e has promoted §r(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+) §r§eto Party Leader§r", - "(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+)§r§e has promoted §r(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+) §r§eto Party Moderator§r", - "(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+) §r§eis now a Party Moderator§r", - "(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+)§r§e has demoted §r(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+) §r§eto Party Member§r", - "§cYou can't demote yourself!§r", - "§6Party Members \\([0-9]+\\)§r", - "§eParty Leader: §r(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+) ?§r(?:§[a-zA-Z0-9]).§r", - "§eParty Members: §r(?:(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+)§r(?:§[a-zA-Z0-9]) . §r)+", - "§eParty Moderators: §r(?:(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+)§r(?:§[a-zA-Z0-9]) . §r)+", - "§eThe party invite to §r(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+) §r§ehas expired§r", - "(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+) §r§cdisabled All Invite§r", - "(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+) §r§aenabled All Invite§r", - "§cYou cannot invite that player\\.§r", - "§cYou are not allowed to invite players\\.§r", - "§eThe party leader, §r(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+) §r§ehas disconnected, they have §r§c5 §r§eminutes to rejoin before the party is disbanded\\.§r", - "(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+) §r§ehas disconnected, they have §r§c5 §r§eminutes to rejoin before they are removed from the party.§r", - "§cYou are not in a party right now\\.§r", - "§cThis party is currently muted\\.§r", - "(§r)*(§9P §8>)+(.*)" - ], - "color": 14737632, - "hovered_color": 16777120, - "selected_color": 10526880, - "prefix": "/pc " - }, - { - "enabled": true, - "name": "GUILD", - "unformatted": true, - "lowercase": false, - "starts": [ - "Guild >", - "G >" - ], - "color": 14737632, - "hovered_color": 16777120, - "selected_color": 10526880, - "prefix": "/gc " - }, - { - "enabled": true, - "name": "PM", - "unformatted": false, - "lowercase": false, - "regex": [ - "^(?§dTo|§dFrom) (?.+): §r(?§7.*)(?:§r)?$" - ], - "color": 14737632, - "hovered_color": 16777120, - "selected_color": 10526880, - "prefix": "/r " - } - ], - "version": 6 -} -``` - -The `version` property stores the version number of the Chat Tabs JSON file. This should not be touched unless you have -an older Chat Tab JSON and would like Chatting to automatically migrate to the newer version. The current version is `4` -. - -The `tabs` property stores all the chat tabs, in the order they should be displayed in. By default, there are 4 chat -tabs - ALL, PARTY, GUILD, and PM. ALL simply shows all messages; nothing is filtered. PARTY shows only party messages, -GUILD shows only guild messages, and PM only shows private messages. These can be modified to the user's free will. - -### Tab Syntax - -This is the default PARTY chat tab. We will be using this as an example, as it utilizes most of the chat tab features -that you may want to use. - -```json -{ - "enabled": true, - "name": "PARTY", - "unformatted": false, - "starts": [ - "§r§9Party §8> ", - "§r§9P §8> ", - "§eThe party was transferred to §r", - "§eKicked §r" - ], - "contains": [ - "§r§ehas invited you to join their party!" - ], - "ends": [ - "§r§eto the party! They have §r§c60 §r§eseconds to accept.§r", - ... - "§r§e because they were offline.§r" - ], - "equals": [ - "§cThe party was disbanded because all invites expired and the party was empty§r" - ], - "regex": [ - "(§r)*(§9Party §8>)+(.*)", - "(?:(?:§[a-zA-Z0-9])*\\[(...seconds to accept\\.§r", - "(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)... §r§ehas left the party\\.§r", - "(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP...joined the party\\.§r", - ... - "(§r)*(§9P §8>)+(.*)" - ], - "color": 14737632, - "hovered_color": 16777120, - "selected_color": 10526880, - "prefix": "/pc " -} -``` - -The `enabled` property allows you to disable a chat tab without removing the tab from the JSON file. Users will be able -to directly manage this property via a GUI in the future. - -The `name` property allows you to customize the display name of the tab. - -The `unformatted` property allows you to toggle whether the filters go through the raw message sent or the message -without color / formatting codes. For example... - -BEFORE - -```json -{ - "enabled": true, - "name": "EXAMPLE", - "unformatted": false, - "starts": [ - "§r§9Message §8> " - ] -} -``` - -AFTER - -```json -{ - "enabled": true, - "name": "EXAMPLE", - "unformatted": true, - "starts": [ - "Message > " - ] -} -``` - -The `starts` property allows you to only allow a message if it starts with a string in the `starts` property. For -example, if a message which contents were "Hello!", it would not be allowed, as it does not start anything in -the `starts` property. - -The `contains` property allows you to only allow a message if it contains a string in the `contains` property. - -The `ends` property does a similar function, except only allowing a message if it **ends** with anything in the `ends` -property rather than if it starts with anything. - -The `equals` property allows you to only allow a message if it equals with a string in the `equals` property. **_THIS IS -CASE SENSITIVE._** - -The `regex` property allows you to only allow a message if it matches a regex in the `regex` property. - -You can append `ignore_` to `starts`, `ends`, `equals`, or `regex` to ignore messages that match rather than allow, and -of course use both at the same time. - -The `color` property allows you to change the color of the chat tab text. It is in RGBA format. - -The `hovered_color` property allows you to change the color of the chat tab text while being hovered. This takes -priority over the `color` property. Like the `color` property, it is in RGBA format. - -The `selected_color` property allows you to change the color of the chat tab text while selected. This takes priority -over all the other color properties. Like the other color properties, it is in RGBA format. - -The `prefix` property appends the prefix to any message sent while in the specific chat tab **if it is not a command**. -This can be used to automatically send messages in a specific channel in servers, like in Hypixel. This is no longer required as of version 5. - -The `lowercase` property makes the message trigger lowercase. - -## Chat Tabs JSON Changelogs - -### Version 6 (Chatting 1.4.2 beta5) -- Changed PM tab to use regex instead of starts and sets `unformatted` to false -- Changed directory of Chat Tabs JSON to `{MINECRAFT DIRECTORY}/OneConfig/profiles/{PROFILE}/chattabs.json` - -### Version 5 (Chatting 1.4.0 [04363f5]) -- The `prefix` property is no longer a required property. -- Added `lowercase` property - -### Version 4 (Chatting 1.4.0 [eece3cb]) -- Added color text options (`color`, `hovered_color`, and `selected_color`) -- `version` is now actually an integer - -### Version 3 (Chatting 1.4.0-alpha1) -- Added `ignore_` options (`ignore_starts`, `ignore_ends`, `ignore_equals`, and `ignore_regex`) - -### Version 2 (1.0.0) -- Added `enabled` property \ No newline at end of file diff --git a/docs/docs.md b/docs/docs.md deleted file mode 100644 index b7ff82a..0000000 --- a/docs/docs.md +++ /dev/null @@ -1,3 +0,0 @@ -# Chatting Docs - -## - [Chat Tabs](chattabs.md) \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 74dc189..0d8658f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,11 +1,23 @@ -# Gradle Configuration -- DO NOT TOUCH THESE VALUES.` +# Gradle Configuration -- DO NOT TOUCH THESE VALUES. org.gradle.daemon=true org.gradle.parallel=true org.gradle.configureoncommand=true org.gradle.parallel.threads=4 org.gradle.jvmargs=-Xmx2G +loom.ignoreDependencyLoomVersionValidation=true +# gradle.properties file -- CHANGE THE VALUES STARTING WITH `mod.*` AND REMOVE THIS COMMENT. + +# Sets the name of your mod. mod.name=Chatting +# Sets the ID of your mod that mod loaders use to recognize it. mod.id=chatting -mod.version=2.0.7 -mod.group=org.polyfrost \ No newline at end of file +# Sets the version of your mod. Make sure to update this when you make changes according to the SemVer specification. +mod.version=1.0.0 +# Sets the Maven group ID of your mod. This is effectively unused but is good practice to set regardless. +mod.group=org.polyfrost + +# Configures the mod loader that we're developing for. +loom.platform=fabric +# Configures the Minecraft version that we're developing for. +minecraft.version=1.21.5 diff --git a/gradlew b/gradlew index 1aa94a4..b740cf1 100755 --- a/gradlew +++ b/gradlew @@ -55,7 +55,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. diff --git a/root.gradle.kts b/root.gradle.kts deleted file mode 100644 index c548169..0000000 --- a/root.gradle.kts +++ /dev/null @@ -1,18 +0,0 @@ -plugins { - id("dev.deftu.gradle.multiversion-root") -} - -preprocess { - // Adding new versions/loaders can be done like so: - // For each version, we add a new wrapper around the last from highest to lowest. - // Each mod loader needs to link up to the previous version's mod loader so that the mappings can be processed from the previous version. - // "1.12.2-forge"(11202, "srg") { - // "1.8.9-forge"(10809, "srg") - // } - - "1.8.9-forge"(10809, "srg") { - "1.8.9-fabric"(10809, "yarn") - } - - strictExtraMappings.set(true) -} diff --git a/settings.gradle.kts b/settings.gradle.kts index 1c2a298..8c087b2 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -21,11 +21,6 @@ pluginManagement { gradlePluginPortal() mavenCentral() } - - plugins { - kotlin("jvm") version("2.0.10") - id("dev.deftu.gradle.multiversion-root") version("2.35.0") - } } val projectName: String = extra["mod.name"]?.toString() @@ -33,19 +28,3 @@ val projectName: String = extra["mod.name"]?.toString() // Configures the root project Gradle name based on the value in `gradle.properties` rootProject.name = projectName -rootProject.buildFileName = "root.gradle.kts" - -// Adds all of our build target versions to the classpath if we need to add version-specific code. -// Update this list if you want to remove/add a version and/or mod loader. -// The format is: version-modloader (f.ex: 1.8.9-forge, 1.17.1-fabric, etc) -// **REMEMBER TO ALSO UPDATE THE `root.gradle.kts` AND `build.gradle.kts` FILES WITH THE NEW VERSION(S). -listOf( - "1.8.9-forge", - "1.8.9-fabric" -).forEach { version -> - include(":$version") - project(":$version").apply { - projectDir = file("versions/$version") - buildFileName = "../../build.gradle.kts" - } -} diff --git a/src/ducks/java/club/sk1er/patcher/config/OldPatcherConfig.java b/src/ducks/java/club/sk1er/patcher/config/OldPatcherConfig.java deleted file mode 100644 index 91e13bb..0000000 --- a/src/ducks/java/club/sk1er/patcher/config/OldPatcherConfig.java +++ /dev/null @@ -1,7 +0,0 @@ -package club.sk1er.patcher.config; - -public class OldPatcherConfig { - public static boolean transparentChat; // Chatting - public static boolean transparentChatOnlyWhenClosed; // Chatting - public static boolean transparentChatInputField; // Chatting -} diff --git a/src/ducks/java/club/sk1er/patcher/config/PatcherConfig.java b/src/ducks/java/club/sk1er/patcher/config/PatcherConfig.java deleted file mode 100644 index 1472f85..0000000 --- a/src/ducks/java/club/sk1er/patcher/config/PatcherConfig.java +++ /dev/null @@ -1,8 +0,0 @@ -package club.sk1er.patcher.config; - -public class PatcherConfig { - public static boolean transparentChatInputField; - public static boolean transparentChat; - public static boolean chatPosition; - public static boolean extendedChatLength; -} diff --git a/src/ducks/java/com/llamalad7/betterchat/BetterChat.java b/src/ducks/java/com/llamalad7/betterchat/BetterChat.java deleted file mode 100644 index 14a5a70..0000000 --- a/src/ducks/java/com/llamalad7/betterchat/BetterChat.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.llamalad7.betterchat; - -public class BetterChat { - public static ChatSettings getSettings() { - throw new AssertionError("Wyvest"); - } -} diff --git a/src/ducks/java/com/llamalad7/betterchat/ChatSettings.java b/src/ducks/java/com/llamalad7/betterchat/ChatSettings.java deleted file mode 100644 index d6f73b1..0000000 --- a/src/ducks/java/com/llamalad7/betterchat/ChatSettings.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.llamalad7.betterchat; - -public class ChatSettings { - public int xOffset; - public int yOffset; - public boolean smooth; -} diff --git a/src/main/java/org/polyfrost/chatting/hook/ChatHook.java b/src/main/java/org/polyfrost/chatting/hook/ChatHook.java deleted file mode 100644 index 78e150a..0000000 --- a/src/main/java/org/polyfrost/chatting/hook/ChatHook.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.polyfrost.chatting.hook; - -import net.minecraft.client.gui.ChatLine; - -public class ChatHook { - public static ChatLine currentLine = null; - public static boolean lineVisible = false; -} \ No newline at end of file diff --git a/src/main/java/org/polyfrost/chatting/hook/ChatLineHook.java b/src/main/java/org/polyfrost/chatting/hook/ChatLineHook.java deleted file mode 100644 index 63e8563..0000000 --- a/src/main/java/org/polyfrost/chatting/hook/ChatLineHook.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.polyfrost.chatting.hook; - -import net.minecraft.client.gui.ChatLine; -import net.minecraft.client.network.NetworkPlayerInfo; - -import java.lang.ref.WeakReference; -import java.util.HashSet; - -public interface ChatLineHook { - HashSet> chatting$chatLines = new HashSet<>(); - boolean chatting$hasDetected(); - NetworkPlayerInfo chatting$getPlayerInfo(); - - void chatting$updatePlayerInfo(); - - long chatting$getUniqueId(); - - ChatLine chatting$getFullMessage(); -} diff --git a/src/main/java/org/polyfrost/chatting/hook/GuiChatHook.java b/src/main/java/org/polyfrost/chatting/hook/GuiChatHook.java deleted file mode 100644 index 36e0f48..0000000 --- a/src/main/java/org/polyfrost/chatting/hook/GuiChatHook.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.polyfrost.chatting.hook; - -public interface GuiChatHook { - void chatting$triggerButtonReset(); -} diff --git a/src/main/java/org/polyfrost/chatting/hook/GuiNewChatHook.java b/src/main/java/org/polyfrost/chatting/hook/GuiNewChatHook.java deleted file mode 100644 index fda701f..0000000 --- a/src/main/java/org/polyfrost/chatting/hook/GuiNewChatHook.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.polyfrost.chatting.hook; - -import net.minecraft.client.gui.ChatLine; - -public interface GuiNewChatHook { - int chatting$getRight(); - - boolean chatting$isHovering(); - - ChatLine chatting$getHoveredLine(int mouseY); - - String chatting$getChattingChatComponent(int mouseY, int mouseButton); - - int chatting$getTextOpacity(); -} diff --git a/src/main/java/org/polyfrost/chatting/mixin/ChatHudAccessor.java b/src/main/java/org/polyfrost/chatting/mixin/ChatHudAccessor.java new file mode 100644 index 0000000..d9bf105 --- /dev/null +++ b/src/main/java/org/polyfrost/chatting/mixin/ChatHudAccessor.java @@ -0,0 +1,60 @@ +package org.polyfrost.chatting.mixin; + +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.hud.ChatHud; +import net.minecraft.client.gui.hud.ChatHudLine; +import net.minecraft.client.gui.hud.MessageIndicator; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; +import org.spongepowered.asm.mixin.gen.Invoker; + +import java.util.List; + +@Mixin(ChatHud.class) +public interface ChatHudAccessor { + + @Accessor + List getVisibleMessages(); + + @Accessor + int getScrolledLines(); + + + +// @Accessor +// boolean getHasUnreadNewMessages(); +// +// @Invoker("getHeight") +// int getHeight(); +// +// @Invoker("getWidth") +// int getWidth(); +// +// @Invoker("getMessageIndex") +// int getMessageIndex(double x, double y); +// +// @Invoker("toChatLineX") +// double toChatLineX(double x); +// +// @Invoker("toChatLineY") +// double toChatLineY(double x); +// + @Invoker + int invokeGetIndicatorX(ChatHudLine.Visible visible); +// + @Invoker + void invokeDrawIndicatorIcon(DrawContext drawContext, int i, int j, MessageIndicator.Icon icon); + + @Invoker + double invokeGetMessageOpacityMultiplier(int i); + + @Invoker + int invokeGetLineHeight(); +// +// @Invoker("isChatHidden") +// boolean isChatHidden(); +// +// @Invoker("getChatScale") +// double getChatScale(); + +} diff --git a/src/main/java/org/polyfrost/chatting/mixin/ChatHudMixin.java b/src/main/java/org/polyfrost/chatting/mixin/ChatHudMixin.java new file mode 100644 index 0000000..4e8882e --- /dev/null +++ b/src/main/java/org/polyfrost/chatting/mixin/ChatHudMixin.java @@ -0,0 +1,18 @@ +package org.polyfrost.chatting.mixin; + +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.hud.ChatHud; +import org.polyfrost.chatting.ModConfig; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(ChatHud.class) +public class ChatHudMixin { + +// @Inject(method = "render", at = @At("HEAD"), cancellable = true) +// private void cancelChat(DrawContext drawContext, int i, int j, int k, boolean bl, CallbackInfo ci) { +// if (ModConfig.INSTANCE.enabled) ci.cancel(); +// } +} diff --git a/src/main/java/org/polyfrost/chatting/mixin/ChatLineMixin.java b/src/main/java/org/polyfrost/chatting/mixin/ChatLineMixin.java deleted file mode 100644 index ea43146..0000000 --- a/src/main/java/org/polyfrost/chatting/mixin/ChatLineMixin.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * This file is from chat_heads is licensed under MPL-2.0, which can be found at https://www.mozilla.org/en-US/MPL/2.0/ - * See: https://github.com/dzwdz/chat_heads/blob/fabric-1.16.x/LICENSE - */ - -package org.polyfrost.chatting.mixin; - -import org.apache.commons.lang3.StringUtils; -import org.polyfrost.chatting.config.ChattingConfig; -import org.polyfrost.chatting.hook.ChatHook; -import org.polyfrost.chatting.hook.ChatLineHook; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.ChatLine; -import net.minecraft.client.network.NetHandlerPlayClient; -import net.minecraft.client.network.NetworkPlayerInfo; -import net.minecraft.util.IChatComponent; -import org.jetbrains.annotations.Nullable; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import java.lang.ref.WeakReference; -import java.util.HashMap; -import java.util.Map; -import java.util.regex.Pattern; - -@Mixin(ChatLine.class) -public class ChatLineMixin implements ChatLineHook { - @Unique - private boolean chatting$detected = false; - @Unique - private boolean chatting$first = true; - @Unique - private NetworkPlayerInfo chatting$playerInfo; - @Unique - private NetworkPlayerInfo chatting$detectedPlayerInfo; - @Unique - private static NetworkPlayerInfo chatting$lastPlayerInfo; - @Unique - private static long chatting$lastUniqueId = 0; - @Unique - private long chatting$uniqueId = 0; - @Unique - private ChatLine chatting$fullMessage = null; - @Unique - private static ChatLine chatting$lastChatLine = null; - @Unique - private static final Pattern chatting$pattern = Pattern.compile("(§.)|\\W"); - - @Inject(method = "", at = @At("RETURN")) - private void onInit(int i, IChatComponent iChatComponent, int chatId, CallbackInfo ci) { - chatting$lastUniqueId++; - chatting$uniqueId = chatting$lastUniqueId; - chatting$fullMessage = ChatHook.currentLine; - if (chatting$lastChatLine == ChatHook.currentLine) { - if (chatting$lastPlayerInfo != null) { - return; - } - } - chatting$lastChatLine = chatting$fullMessage; - chatting$chatLines.add(new WeakReference<>((ChatLine) (Object) this)); - NetHandlerPlayClient netHandler = Minecraft.getMinecraft().getNetHandler(); - if (netHandler == null) return; - Map nicknameCache = new HashMap<>(); - try { - for (String word : chatting$pattern.split(StringUtils.substringBefore(iChatComponent.getFormattedText(), ":"))) { - if (word.isEmpty()) continue; - chatting$playerInfo = netHandler.getPlayerInfo(word); - if (chatting$playerInfo == null) { - chatting$playerInfo = chatting$getPlayerFromNickname(word, netHandler, nicknameCache); - } - if (chatting$playerInfo != null) { - chatting$detectedPlayerInfo = chatting$playerInfo; - chatting$detected = true; - if (ChatHook.lineVisible) { - if (chatting$lastPlayerInfo != null && chatting$playerInfo.getGameProfile() == chatting$lastPlayerInfo.getGameProfile()) { - chatting$first = false; - if (ChattingConfig.INSTANCE.getHideChatHeadOnConsecutiveMessages()) { - chatting$playerInfo = null; - } - } - chatting$lastPlayerInfo = chatting$detectedPlayerInfo; - } - return; - } - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Unique - @Nullable - private static NetworkPlayerInfo chatting$getPlayerFromNickname(String word, NetHandlerPlayClient connection, Map nicknameCache) { - if (nicknameCache.isEmpty()) { - for (NetworkPlayerInfo p : connection.getPlayerInfoMap()) { - IChatComponent displayName = p.getDisplayName(); - if (displayName != null) { - String nickname = displayName.getUnformattedTextForChat(); - if (word.equals(nickname)) { - nicknameCache.clear(); - return p; - } - - nicknameCache.put(nickname, p); - } - } - } else { - // use prepared cache - return nicknameCache.get(word); - } - - return null; - } - - @Override - public boolean chatting$hasDetected() { - return chatting$detected; - } - - @Override - public NetworkPlayerInfo chatting$getPlayerInfo() { - return chatting$playerInfo; - } - - @Override - public void chatting$updatePlayerInfo() { - if (ChattingConfig.INSTANCE.getHideChatHeadOnConsecutiveMessages() && !chatting$first) { - chatting$playerInfo = null; - } else { - chatting$playerInfo = chatting$detectedPlayerInfo; - } - } - - @Override - public long chatting$getUniqueId() { - return chatting$uniqueId; - } - - @Override - public ChatLine chatting$getFullMessage() { - return chatting$fullMessage; - } -} diff --git a/src/main/java/org/polyfrost/chatting/mixin/ChatStyle_UnderlineLinks_Mixin.java b/src/main/java/org/polyfrost/chatting/mixin/ChatStyle_UnderlineLinks_Mixin.java deleted file mode 100644 index 7bbd6cf..0000000 --- a/src/main/java/org/polyfrost/chatting/mixin/ChatStyle_UnderlineLinks_Mixin.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.polyfrost.chatting.mixin; - -import net.minecraft.event.ClickEvent; -import net.minecraft.util.ChatStyle; -import net.minecraft.util.EnumChatFormatting; -import org.polyfrost.chatting.config.ChattingConfig; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(ChatStyle.class) -public abstract class ChatStyle_UnderlineLinks_Mixin { - @Shadow - private ClickEvent chatClickEvent; - - @Shadow - public abstract ChatStyle setUnderlined(Boolean underlined); - - @Shadow - public abstract ChatStyle setColor(EnumChatFormatting color); - - @Inject(method = "", at = @At("RETURN")) - private void underLineAndHighlightLinks(CallbackInfo ci) { - if (this.chatClickEvent != null && this.chatClickEvent.getAction() == ClickEvent.Action.OPEN_URL && ChattingConfig.INSTANCE.getUnderlinedLinks()) { - setUnderlined(true); - setColor(EnumChatFormatting.BLUE); - } - } -} diff --git a/src/main/java/org/polyfrost/chatting/mixin/ClientCommandHandlerMixin.java b/src/main/java/org/polyfrost/chatting/mixin/ClientCommandHandlerMixin.java deleted file mode 100644 index ee63ed3..0000000 --- a/src/main/java/org/polyfrost/chatting/mixin/ClientCommandHandlerMixin.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.polyfrost.chatting.mixin; - -import kotlin.Pair; -import net.minecraft.client.Minecraft; -import net.minecraft.command.CommandHandler; -import net.minecraft.command.ICommandSender; -import net.minecraft.util.BlockPos; -import net.minecraftforge.client.ClientCommandHandler; -import net.minecraftforge.fml.client.FMLClientHandler; -import org.polyfrost.chatting.chat.ChatShortcuts; -import org.polyfrost.chatting.config.ChattingConfig; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -import java.util.List; - -@Mixin(value = ClientCommandHandler.class, remap = false) -public class ClientCommandHandlerMixin extends CommandHandler { - @Redirect(method = "autoComplete", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/client/ClientCommandHandler;getTabCompletionOptions(Lnet/minecraft/command/ICommandSender;Ljava/lang/String;Lnet/minecraft/util/BlockPos;)Ljava/util/List;")) - private List addChatShortcuts(ClientCommandHandler instance, ICommandSender iCommandSender, String leftOfCursor, BlockPos blockPos) { - Minecraft mc = FMLClientHandler.instance().getClient(); - List autocompleteList = instance.getTabCompletionOptions(mc.thePlayer, leftOfCursor, mc.thePlayer.getPosition()); - if (ChattingConfig.INSTANCE.getChatShortcuts()) { - for (Pair pair : ChatShortcuts.INSTANCE.getShortcuts()) { - if (pair.getFirst().startsWith(leftOfCursor)) { - autocompleteList.add(pair.getFirst()); - } - } - } - return autocompleteList; - } -} diff --git a/src/main/java/org/polyfrost/chatting/mixin/EntityPlayerSPMixin.java b/src/main/java/org/polyfrost/chatting/mixin/EntityPlayerSPMixin.java deleted file mode 100644 index 26988c0..0000000 --- a/src/main/java/org/polyfrost/chatting/mixin/EntityPlayerSPMixin.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.polyfrost.chatting.mixin; - -import net.minecraft.client.entity.EntityPlayerSP; -import net.minecraft.client.network.NetHandlerPlayClient; -import net.minecraft.network.Packet; -import net.minecraft.network.play.client.C01PacketChatMessage; -import org.polyfrost.chatting.chat.ChatTab; -import org.polyfrost.chatting.chat.ChatTabs; -import org.polyfrost.chatting.config.ChattingConfig; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(value = EntityPlayerSP.class, priority = 0) -public class EntityPlayerSPMixin { - @Shadow @Final public NetHandlerPlayClient sendQueue; - - @Redirect(method = "sendChatMessage", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/NetHandlerPlayClient;addToSendQueue(Lnet/minecraft/network/Packet;)V")) - private void handleSentMessages(NetHandlerPlayClient instance, Packet packet, String value) { - if (value.startsWith("/")) { - this.sendQueue.addToSendQueue(packet); - return; - } - if (ChattingConfig.INSTANCE.getChatTabs() && !ChatTabs.INSTANCE.getCurrentTabs().isEmpty()) { - boolean sent = false; - for (ChatTab tab : ChatTabs.INSTANCE.getCurrentTabs()) { - if (tab.getPrefix() != null && !tab.getPrefix().isEmpty()) { - this.sendQueue.addToSendQueue(new C01PacketChatMessage(tab.getPrefix() + value)); - sent = true; - } - } - if (!sent) { - this.sendQueue.addToSendQueue(packet); - } - } else { - this.sendQueue.addToSendQueue(packet); - } - } -} \ No newline at end of file diff --git a/src/main/java/org/polyfrost/chatting/mixin/EntityRendererMixin.java b/src/main/java/org/polyfrost/chatting/mixin/EntityRendererMixin.java deleted file mode 100644 index 4da59fc..0000000 --- a/src/main/java/org/polyfrost/chatting/mixin/EntityRendererMixin.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.polyfrost.chatting.mixin; - -import dev.deftu.omnicore.client.render.OmniResolution; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.EntityRenderer; -import org.polyfrost.chatting.Chatting; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(EntityRenderer.class) -public class EntityRendererMixin { - @Inject(method = "updateCameraAndRender", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiIngame;renderGameOverlay(F)V", shift = At.Shift.AFTER)) - private void draw(float partialTicks, long nanoTime, CallbackInfo ci) { - Chatting.INSTANCE.getChatWindow().setGuiIngame(false); - ((GuiIngameForge_DrawChatAccessor) Minecraft.getMinecraft().ingameGUI).drawChat(OmniResolution.getScaledWidth(), OmniResolution.getScaledHeight()); - } -} diff --git a/src/main/java/org/polyfrost/chatting/mixin/GameSettings_ChatScaleChangeEvent_Mixin.java b/src/main/java/org/polyfrost/chatting/mixin/GameSettings_ChatScaleChangeEvent_Mixin.java deleted file mode 100644 index 8cebfce..0000000 --- a/src/main/java/org/polyfrost/chatting/mixin/GameSettings_ChatScaleChangeEvent_Mixin.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.polyfrost.chatting.mixin; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.settings.GameSettings; -import org.objectweb.asm.Opcodes; -import org.polyfrost.chatting.Chatting; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(GameSettings.class) -public class GameSettings_ChatScaleChangeEvent_Mixin { - @Shadow - protected Minecraft mc; - - @Inject(method = "setOptionFloatValue", at = @At(value = "FIELD", target = "Lnet/minecraft/client/settings/GameSettings;chatScale:F", opcode = Opcodes.PUTFIELD, shift = At.Shift.AFTER)) - private void onChatScaleChange(GameSettings.Options settingsOption, float value, CallbackInfo ci) { - Chatting.INSTANCE.getChatWindow().updateMCChatScale(); - } -} diff --git a/src/main/java/org/polyfrost/chatting/mixin/GuiChatMixin.java b/src/main/java/org/polyfrost/chatting/mixin/GuiChatMixin.java deleted file mode 100644 index 419c5c9..0000000 --- a/src/main/java/org/polyfrost/chatting/mixin/GuiChatMixin.java +++ /dev/null @@ -1,232 +0,0 @@ -package org.polyfrost.chatting.mixin; - -import com.google.common.collect.Lists; -import dev.deftu.omnicore.client.OmniClipboard; -import dev.deftu.omnicore.client.OmniDesktop; -import dev.deftu.omnicore.client.OmniKeyboard; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.*; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraftforge.fml.client.config.GuiUtils; -import org.apache.commons.lang3.StringUtils; -import org.lwjgl.input.Keyboard; -import org.lwjgl.input.Mouse; -import org.polyfrost.chatting.Chatting; -import org.polyfrost.chatting.chat.*; -import org.polyfrost.chatting.config.ChattingConfig; -import org.polyfrost.chatting.gui.components.CleanButton; -import org.polyfrost.chatting.gui.components.ClearButton; -import org.polyfrost.chatting.gui.components.ScreenshotButton; -import org.polyfrost.chatting.gui.components.SearchButton; -import org.polyfrost.chatting.hook.ChatLineHook; -import org.polyfrost.chatting.hook.GuiChatHook; -import org.polyfrost.chatting.hook.GuiNewChatHook; -import org.polyfrost.chatting.utils.ModCompatHooks; -import org.polyfrost.polyui.component.Drawable; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.ModifyArg; -import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import java.util.List; - -@Mixin(GuiChat.class) -public abstract class GuiChatMixin extends GuiScreen implements GuiChatHook { - @Shadow - protected GuiTextField inputField; - - @Shadow - public abstract void drawScreen(int mouseX, int mouseY, float partialTicks); - - @Shadow - private String defaultInputFieldText; - - /** - * Gets the modifier key name depending on the operating system - * - * @return "OPTION" if macOS, otherwise, "ALT" - */ - @Unique - private static String chatting$getModifierKey() { - return (OmniDesktop.isMac()) ? "OPTION" : "ALT"; - } - - @Unique - private static final List COPY_TOOLTIP = Lists.newArrayList( - "§e§lCopy To Clipboard", - "§b§lNORMAL CLICK§r §8- §7Full Message", - "§b§lCTRL CLICK§r §8- §7Single Line", - "§b§lSHIFT CLICK§r §8- §7Screenshot Message", - "", - "§e§lModifiers", - "§b§l" + chatting$getModifierKey() + "§r §8- §7Formatting Codes" - ); - - @Unique - private static final List DELETE_TOOLTIP = Lists.newArrayList( - "§b§lNORMAL CLICK§r §8- §7Full Message", - "§b§lCTRL CLICK§r §8- §7Single Line" - ); - - @Unique - private SearchButton chatting$searchButton; - - @Inject(method = "initGui", at = @At("TAIL")) - private void init(CallbackInfo ci) { - chatting$initButtons(); - if (Chatting.INSTANCE.getChatInput().getInputFieldDraft()) { - String command = (ChatHooks.INSTANCE.getCommandDraft().startsWith("/") ? "" : "/") + ChatHooks.INSTANCE.getCommandDraft(); - this.inputField.setText(this.inputField.getText().startsWith("/") ? command : ChatHooks.INSTANCE.getDraft()); - } - ChatHooks.INSTANCE.setTextField(this.inputField); - } - - @Inject(method = "updateScreen", at = @At("HEAD")) - private void updateScreen(CallbackInfo ci) { - if (ChattingConfig.INSTANCE.getChatSearch() && chatting$searchButton.isEnabled()) { - chatting$searchButton.getInputField().updateCursorCounter(); - } - } - - @Inject(method = "keyTyped", at = @At("HEAD"), cancellable = true) - private void keyTyped(char typedChar, int keyCode, CallbackInfo ci) { - if (ChattingConfig.INSTANCE.getChatSearch() && chatting$searchButton.isEnabled()) { - ci.cancel(); - if (keyCode == 1) { - chatting$searchButton.onMousePress(); - return; - } - chatting$searchButton.getInputField().textboxKeyTyped(typedChar, keyCode); - ChatSearchingManager.INSTANCE.setLastSearch(chatting$searchButton.getInputField().getText()); - } else if ((Keyboard.isKeyDown(219) || Keyboard.isKeyDown(220) || Keyboard.isKeyDown(29) || Keyboard.isKeyDown(157)) && keyCode == OmniKeyboard.KEY_TAB) { // either macos super key or ctrl key for any os - ChatHooks.INSTANCE.switchTab(); - } - } - - @Inject(method = "drawScreen", at = @At("HEAD")) - private void onDrawScreen(int mouseX, int mouseY, float partialTicks, CallbackInfo ci) { - boolean copy = ChattingConfig.INSTANCE.getChatCopy(); - boolean delete = ChattingConfig.INSTANCE.getChatDelete(); - if (!copy && !delete) return; - GuiNewChatHook hook = ((GuiNewChatHook) Minecraft.getMinecraft().ingameGUI.getChatGUI()); - Drawable hud = Chatting.INSTANCE.getChatWindow().get(); - int scale = new ScaledResolution(this.mc).getScaleFactor(); - int x = Mouse.getX(); - int right = (int) ((hook.chatting$getRight() + ModCompatHooks.getXOffset() + 1 + hud.getPadding().getX() * (ChattingConfig.INSTANCE.getExtendBG() ? 1f : 2f)) * hud.getScaleX() + (int) hud.getX()); - delete = delete && chatting$hovered(hook, x, right + (int) ((copy ? 10 : 0) * hud.getScaleX()), scale, hud); - copy = copy && chatting$hovered(hook, x, right, scale, hud); - - if (copy || delete) { - List tooltip = delete ? DELETE_TOOLTIP : COPY_TOOLTIP; - GuiUtils.drawHoveringText(tooltip, mouseX, mouseY, width, height, -1, this.fontRendererObj); - GlStateManager.disableLighting(); - } - } - - @Unique - private boolean chatting$hovered(GuiNewChatHook hook, int x, int right, int scale, Drawable hud) { - return hook.chatting$isHovering() && x > right * scale && x < (right + 9 * hud.getScaleX()) * scale; - } - - @Redirect(method = "drawScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiChat;drawRect(IIIII)V")) - private void cancelBG(int left, int top, int right, int bottom, int color) { - ChatInputBox chatInput = Chatting.INSTANCE.getChatInput(); - ChatHooks.INSTANCE.setInputBoxRight(chatInput.getCompactInputBox() ? Math.max((int) chatInput.getWidth() + 2, ChatHooks.INSTANCE.getInputRight() + (this.inputField.getText().length() < ModCompatHooks.getChatInputLimit() ? 8 : 2)) : width - 2); - chatInput.drawBG(); - } - - @Inject(method = "mouseClicked", at = @At("HEAD")) - private void mouseClicked(int mouseX, int mouseY, int mouseButton, CallbackInfo ci) { - GuiNewChatHook hook = ((GuiNewChatHook) Minecraft.getMinecraft().ingameGUI.getChatGUI()); - Drawable hud = Chatting.INSTANCE.getChatWindow().get(); - int scale = new ScaledResolution(this.mc).getScaleFactor(); - int x = Mouse.getX(); - if (hook.chatting$isHovering()) { - boolean copy = ChattingConfig.INSTANCE.getChatCopy(); - int right = (int) ((hook.chatting$getRight() + ModCompatHooks.getXOffset() + 1 + hud.getPadding().getX() * (ChattingConfig.INSTANCE.getExtendBG() ? 1f : 2f)) * hud.getScaleX() + (int) hud.getX()) * scale; - if (copy && x > right && x < right + 9 * hud.getScaleX() * scale || (mouseButton == 1 && ChattingConfig.INSTANCE.getRightClickCopy() && (!ChattingConfig.INSTANCE.getRightClickCopyCtrl() || OmniKeyboard.isCtrlKeyPressed()))) { - String message = hook.chatting$getChattingChatComponent(Mouse.getY(), mouseButton); - if (message == null) return; - OmniClipboard.setClipboardString(message); - } else if (ChattingConfig.INSTANCE.getChatDelete() && x > right + (copy ? 10 : 0) * hud.getScaleX() * scale && x < right + ((copy ? 10 : 0) + 9) * hud.getScaleX() * scale) { - ChatLine chatLine = hook.chatting$getHoveredLine(Mouse.getY()); - if (chatLine == null) return; - ModCompatHooks.getDrawnChatLines().removeIf(line -> chatting$remove(line, chatLine)); - ModCompatHooks.getChatLines().removeIf(line -> chatting$remove(line, chatLine)); - } - } - } - - @Unique - private boolean chatting$remove(ChatLine line, ChatLine chatLine) { - return OmniKeyboard.isCtrlKeyPressed() ? - ((ChatLineHook) line).chatting$getUniqueId() == ((ChatLineHook) chatLine).chatting$getUniqueId() : - ((ChatLineHook) ((ChatLineHook) line).chatting$getFullMessage()).chatting$getUniqueId() == ((ChatLineHook) ((ChatLineHook) chatLine).chatting$getFullMessage()).chatting$getUniqueId(); - } - - @ModifyArg(method = "keyTyped", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiChat;sendChatMessage(Ljava/lang/String;)V"), index = 0) - private String modifySentMessage(String original) { - if (ChattingConfig.INSTANCE.getChatShortcuts()) { - if (original.startsWith("/")) { - return "/" + ChatShortcuts.INSTANCE.handleSentCommand(StringUtils.substringAfter(original, "/")); - } - } - return original; - } - - @Inject(method = "keyTyped", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiChat;sendChatMessage(Ljava/lang/String;)V")) - private void clearDraft(CallbackInfo ci) { - if (Chatting.INSTANCE.getChatInput().getInputFieldDraft()) { - this.inputField.setText(this.inputField.getText().startsWith("/") ? "/" : ""); - } - } - - @Inject(method = "onGuiClosed", at = @At("HEAD")) - private void saveDraft(CallbackInfo ci) { - if (Chatting.INSTANCE.getChatInput().getInputFieldDraft()) { - if (this.inputField.getText().startsWith("/")) { - ChatHooks.INSTANCE.setCommandDraft(this.inputField.getText()); - } else { - if (this.inputField.getText().isEmpty() && this.defaultInputFieldText.equals("/")) return; - ChatHooks.INSTANCE.setDraft(this.inputField.getText()); - } - } - } - - - @Inject(method = "handleMouseInput", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiNewChat;scroll(I)V")) - private void handleMouseInput(CallbackInfo ci) { - ChatScrollingHook.INSTANCE.setShouldSmooth(true); - } - - @Unique - private void chatting$initButtons() { - chatting$searchButton = new SearchButton(); - if (ChattingConfig.INSTANCE.getChatSearch()) { - this.buttonList.add(chatting$searchButton); - } - ScreenshotButton screenshot = new ScreenshotButton(); - if (ChattingConfig.INSTANCE.getChatScreenshot()) { - this.buttonList.add(screenshot); - } - ClearButton clear = new ClearButton(); - if (ChattingConfig.INSTANCE.getChatDeleteHistory()) { - this.buttonList.add(clear); - } - if (ChattingConfig.INSTANCE.getChatTabs()) { - for (ChatTab chatTab : ChatTabs.INSTANCE.getTabs()) { - this.buttonList.add(chatTab.getButton()); - } - } - } - - @Override - public void chatting$triggerButtonReset() { - this.buttonList.removeIf(button -> button instanceof CleanButton); - chatting$initButtons(); - } -} diff --git a/src/main/java/org/polyfrost/chatting/mixin/GuiContainerCreativeMixin.java b/src/main/java/org/polyfrost/chatting/mixin/GuiContainerCreativeMixin.java deleted file mode 100644 index d308b4f..0000000 --- a/src/main/java/org/polyfrost/chatting/mixin/GuiContainerCreativeMixin.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.polyfrost.chatting.mixin; - -import net.minecraft.client.gui.inventory.GuiContainerCreative; -import org.polyfrost.chatting.Chatting; -import org.polyfrost.chatting.config.ChattingConfig; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(GuiContainerCreative.class) -public class GuiContainerCreativeMixin { - - @Inject(method = "handleMouseInput", at = @At(value = "INVOKE", target = "Lorg/lwjgl/input/Mouse;getEventDWheel()I"), cancellable = true) - private void cancelScrolling(CallbackInfo ci) { - if (Chatting.INSTANCE.getPeeking() && ChattingConfig.INSTANCE.getPeekScrolling()) { - ci.cancel(); - } - } -} \ No newline at end of file diff --git a/src/main/java/org/polyfrost/chatting/mixin/GuiIngameForgeMixin.java b/src/main/java/org/polyfrost/chatting/mixin/GuiIngameForgeMixin.java deleted file mode 100644 index 7d1fa54..0000000 --- a/src/main/java/org/polyfrost/chatting/mixin/GuiIngameForgeMixin.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.polyfrost.chatting.mixin; - -import net.minecraftforge.client.GuiIngameForge; -import org.polyfrost.chatting.Chatting; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.ModifyArgs; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.invoke.arg.Args; - -@Mixin(GuiIngameForge.class) -public class GuiIngameForgeMixin { - - @ModifyArgs(method = "renderChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;translate(FFF)V")) - private void cancelTranslate(Args args) { - args.set(1, 0f); - } - - @Inject(method = "renderChat", at = @At(value = "HEAD"), cancellable = true, remap = false) - private void cancelChat(int width, int height, CallbackInfo ci) { - if (!Chatting.INSTANCE.getChatWindow().canShow()) ci.cancel(); - } - - @Inject(method = "renderGameOverlay", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/client/GuiIngameForge;renderChat(II)V")) - private void setBypass(float partialTicks, CallbackInfo ci) { - Chatting.INSTANCE.getChatWindow().setGuiIngame(true); - } - -} diff --git a/src/main/java/org/polyfrost/chatting/mixin/GuiIngameForge_DrawChatAccessor.java b/src/main/java/org/polyfrost/chatting/mixin/GuiIngameForge_DrawChatAccessor.java deleted file mode 100644 index 8a2d12c..0000000 --- a/src/main/java/org/polyfrost/chatting/mixin/GuiIngameForge_DrawChatAccessor.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.polyfrost.chatting.mixin; - -import net.minecraftforge.client.GuiIngameForge; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Invoker; - -@Mixin(GuiIngameForge.class) -public interface GuiIngameForge_DrawChatAccessor { - @Invoker("renderChat") - void drawChat(int width, int height); -} diff --git a/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatAccessor.java b/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatAccessor.java deleted file mode 100644 index d0630ca..0000000 --- a/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatAccessor.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.polyfrost.chatting.mixin; - -import net.minecraft.client.gui.ChatLine; -import net.minecraft.client.gui.GuiNewChat; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -import java.util.List; - -@Mixin(GuiNewChat.class) -public interface GuiNewChatAccessor { - @Accessor - List getDrawnChatLines(); - - @Accessor - List getChatLines(); - - @Accessor - int getScrollPos(); -} diff --git a/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin.java b/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin.java deleted file mode 100644 index 9cbb3fa..0000000 --- a/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin.java +++ /dev/null @@ -1,431 +0,0 @@ -package org.polyfrost.chatting.mixin; - -import dev.deftu.clipboard.BufferedClipboardImage; -import dev.deftu.clipboard.Clipboard; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.*; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.util.EnumChatFormatting; -import net.minecraft.util.IChatComponent; -import net.minecraft.util.MathHelper; -import net.minecraft.util.ResourceLocation; -import org.lwjgl.input.Mouse; -import org.lwjgl.opengl.GL11; -import org.polyfrost.chatting.Chatting; -import org.polyfrost.chatting.chat.ChatSearchingManager; -import org.polyfrost.chatting.chat.ChatWindow; -import org.polyfrost.chatting.config.ChattingConfig; -import org.polyfrost.chatting.hook.ChatHook; -import org.polyfrost.chatting.hook.ChatLineHook; -import org.polyfrost.chatting.hook.GuiNewChatHook; -import org.polyfrost.chatting.utils.ModCompatHooks; -import org.polyfrost.oneconfig.api.ui.v1.Notifications; -import org.polyfrost.polyui.color.PolyColor; -import org.polyfrost.polyui.component.Drawable; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.*; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import org.spongepowered.asm.mixin.injection.invoke.arg.Args; - -import java.awt.image.BufferedImage; -import java.util.List; - -import static net.minecraft.client.gui.GuiNewChat.calculateChatboxHeight; -import static net.minecraft.client.gui.GuiNewChat.calculateChatboxWidth; - -@Mixin(value = GuiNewChat.class, priority = 990) -public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook { - @Unique - private int chatting$right = 0; - @Unique - private boolean chatting$isHovering; - @Unique - private boolean chatting$chatCheck; - @Unique - private int chatting$textOpacity; - @Shadow - @Final - private Minecraft mc; - @Shadow - @Final - private List drawnChatLines; - - @Shadow - public abstract boolean getChatOpen(); - - @Shadow - public abstract int getLineCount(); - - @Shadow - private int scrollPos; - - @Shadow - public abstract int getChatWidth(); - - @Unique - private static final ResourceLocation chatting$COPY = new ResourceLocation("chatting:copy.png"); - @Unique - private static final ResourceLocation chatting$DELETE = new ResourceLocation("chatting:delete.png"); - @Unique - private boolean chatting$lineInBounds = false; - @Unique - private ChatLine chatting$chatLine; - @Unique - private int chatting$totalLines = 0; - - @Unique - private boolean chatting$lastOpen, chatting$closing; - - @Unique - private long chatting$time; - - @Inject(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;popMatrix()V")) - private void drawClosing(int updateCounter, CallbackInfo ci) { - ChatWindow hud = Chatting.INSTANCE.getChatWindow(); - Drawable theHud = hud.get(); - - if (chatting$closing && hud.get().getHeight() - (hud.get().getHeight() + theHud.getPadding().getY() * 2) * theHud.getScaleY() > 9 * theHud.getScaleY()) { - int height = (hud.getCustomChatHeight() ? Chatting.INSTANCE.getChatHeight(true) : calculateChatboxHeight(this.mc.gameSettings.chatHeightFocused)); - for (int m = 0; m < this.drawnChatLines.size() && m < height / 9; ++m) { - ChatLine chatLine = this.drawnChatLines.get(m); - if (chatLine != null) { - int unFocusHeight = (hud.getCustomChatHeight() ? Chatting.INSTANCE.getChatHeight(false) : calculateChatboxHeight(this.mc.gameSettings.chatHeightUnfocused)); - boolean shouldShow = (ChattingConfig.INSTANCE.getFade() && m >= chatting$totalLines) || m >= unFocusHeight / 9; - if (!getChatOpen() && shouldShow) { - int q = m * 9; - String string = chatLine.getChatComponent().getFormattedText(); - GlStateManager.enableBlend(); - ModCompatHooks.redirectDrawString(string, ChattingConfig.INSTANCE.getFade() ? 0 : 3, -q - 8, 0xFFFFFFFF, chatLine); - GlStateManager.disableAlpha(); - GlStateManager.disableBlend(); - } - } - } - } - } - - @Inject(method = "drawChat", at = @At("HEAD")) - private void checkScreenshotKeybind(int j2, CallbackInfo ci) { - if (Chatting.INSTANCE.getKeybind().isPressed()) { - Chatting.INSTANCE.setDoTheThing(true); - } - chatting$chatCheck = false; - if (chatting$lastOpen != getChatOpen()) { - if (chatting$lastOpen) chatting$time = Minecraft.getSystemTime(); - chatting$lastOpen = getChatOpen(); - } - long duration = ChattingConfig.INSTANCE.getSmoothBG() ? (long) ChattingConfig.INSTANCE.getBgDuration() : 0; - chatting$closing = (Minecraft.getSystemTime() - chatting$time <= duration); - } - - @Unique - private int chatting$updateCounter; - - @ModifyVariable(method = "drawChat", at = @At("HEAD"), argsOnly = true) - private int setUpdateCounterWhenYes(int updateCounter) { - return (chatting$updateCounter = Chatting.INSTANCE.getDoTheThing() ? 0 : updateCounter); - } - - @ModifyVariable(method = "drawChat", at = @At("STORE"), index = 2) - private int setChatLimitWhenYes(int linesToDraw) { - return Chatting.INSTANCE.getDoTheThing() - ? calculateChatboxHeight(this.mc.gameSettings.chatHeightFocused) / 9 - : linesToDraw; - } - - @ModifyVariable(method = "drawChat", at = @At("STORE"), ordinal = 0) - private ChatLine captureChatLine(ChatLine chatLine) { - chatting$chatLine = chatLine; - return chatLine; - } - - @Inject(method = "drawChat", at = @At(value = "HEAD")) - private void startCaptureHeight(int updateCounter, CallbackInfo ci) { - int i = this.getLineCount(); - chatting$totalLines = 0; - List list = ChatSearchingManager.filterMessages(ChatSearchingManager.INSTANCE.getLastSearch(), this.drawnChatLines); - if (list != null && !list.isEmpty()) { - for (int m = 0; m + this.scrollPos < list.size() && m < i; ++m) { - ChatLine chatLine = list.get(m + this.scrollPos); - int o = chatting$getOpacity(updateCounter, chatLine); - if (o > 3) { - chatting$totalLines++; - } - } - } - ChatWindow chatWindow = Chatting.INSTANCE.getChatWindow(); - chatWindow.get().setHeight(chatting$totalLines * 9); - chatWindow.drawBG(); - } - - @Inject(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;pushMatrix()V", shift = At.Shift.AFTER)) - private void startScissor(int updateCounter, CallbackInfo ci) { - ChatWindow hud = Chatting.INSTANCE.getChatWindow(); - Drawable theHud = hud.get(); - int mcScale = new ScaledResolution(this.mc).getScaleFactor(); - GL11.glEnable(GL11.GL_SCISSOR_TEST); - int height = (int) hud.get().getHeight(); - GL11.glScissor((int) ((theHud.getX() - 3) * mcScale), this.mc.displayHeight - (int) (theHud.getY() + theHud.getHeight() + theHud.getScaleY()) * mcScale, (int) ((hud.get().getWidth() + 3 + (ChattingConfig.INSTANCE.getExtendBG() ? 0 : 20)) * mcScale), (int) ((height + theHud.getScaleY()) * mcScale)); - } - - @Inject(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;popMatrix()V")) - private void disableScissor(int updateCounter, CallbackInfo ci) { - GL11.glDisable(GL11.GL_SCISSOR_TEST); - } - - @ModifyArgs(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiNewChat;drawRect(IIIII)V", ordinal = 0)) - private void captureDrawRect(Args args, int updateCounter) { - args.set(4, 0/* Color.TRANSPARENT */); - if (this.mc.currentScreen instanceof GuiChat) { - int left = args.get(0); - int top = args.get(1); - int right = (int) args.get(2) + ModCompatHooks.getChatHeadOffset(); - args.set(2, right); - if (chatting$isHovered(left, top, right - left, 9)) { - chatting$isHovering = true; - chatting$lineInBounds = true; - } - if (chatting$isHovered(left, top, right - left, 9) || chatting$isHovered(right + 1, top, 9, 9) || chatting$isHovered(right + 11, top, 9, 9)) { - args.set(4, ChattingConfig.INSTANCE.getHoveredChatBackgroundColor().getRgba()); - } - } - } - - @ModifyVariable(method = "drawChat", at = @At(value = "STORE", ordinal = 0), ordinal = 6) - private int fadeTime(int value) { - return value + 200 - (int) (ChattingConfig.INSTANCE.getFadeTime() * 20); - } - - @Redirect(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiNewChat;getChatOpen()Z")) - private boolean noFade(GuiNewChat instance) { - Drawable hud = Chatting.INSTANCE.getChatWindow().get(); - return !ChattingConfig.INSTANCE.getFade() || instance.getChatOpen() || (chatting$closing && (hud.getHeight() + hud.getPadding().getY() * 2) * hud.getScaleY() > 9 * hud.getScaleY()); - } - - @Unique - private int chatting$getOpacity(int updateCounter, ChatLine chatLine) { - if (chatLine != null) { - float f = this.mc.gameSettings.chatOpacity * 0.9F + 0.1F; - int n = updateCounter - chatLine.getUpdatedCounter() + 200 - (int) (ChattingConfig.INSTANCE.getFadeTime() * 20); - if (n < 200 || !ChattingConfig.INSTANCE.getFade() || getChatOpen()) { - double d = (double) n / 200.0; - d = 1.0 - d; - d *= 10.0; - d = MathHelper.clamp_double(d, 0.0, 1.0); - d *= d; - int o = (int) (255 * d); - if (!ChattingConfig.INSTANCE.getFade() || getChatOpen()) { - o = 255; - } - o = (int) ((float) o * f); - if (o <= 3) { - o = 0; - } - return o; - } else { - return 0; - } - } - return Integer.MIN_VALUE; - } - - @ModifyArgs(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/FontRenderer;drawStringWithShadow(Ljava/lang/String;FFI)I")) - private void drawChatBox(Args args) { - if (this.mc.currentScreen instanceof GuiChat) { - int left = 0; - int top = (int) ((float) args.get(2) - 1); - int right = MathHelper.ceiling_float_int((float) getChatWidth()) + 4 + ModCompatHooks.getChatHeadOffset(); - if ((chatting$isHovering && chatting$lineInBounds) || chatting$isHovered(left, top, right + 20, 9)) { - chatting$isHovering = true; - chatting$drawCopyChatBox(right, top); - } - } - chatting$lineInBounds = false; - } - - @Inject(method = "setChatLine", at = @At("HEAD")) - private void captureComponent(IChatComponent chatComponent, int chatLineId, int updateCounter, boolean displayOnly, CallbackInfo ci) { - ChatHook.currentLine = new ChatLine(0, chatComponent, 0); - } - - @Inject(method = "setChatLine", at = @At(value = "NEW", target = "net/minecraft/client/gui/ChatLine", ordinal = 0)) - private void markVisible(IChatComponent chatComponent, int chatLineId, int updateCounter, boolean displayOnly, CallbackInfo ci) { - ChatHook.lineVisible = true; - } - - @Inject(method = "setChatLine", at = @At(value = "INVOKE", target = "Ljava/util/List;add(ILjava/lang/Object;)V", ordinal = 0, shift = At.Shift.AFTER)) - private void markVisible2(IChatComponent chatComponent, int chatLineId, int updateCounter, boolean displayOnly, CallbackInfo ci) { - ChatHook.lineVisible = false; - } - - @ModifyVariable(method = "setChatLine", at = @At(value = "STORE"), ordinal = 2) - private int wrap(int value) { - return Chatting.INSTANCE.getChatWindow().getCustomChatWidth() ? Chatting.INSTANCE.getChatWidth() : calculateChatboxWidth(this.mc.gameSettings.chatWidth); - } - - @Unique - private boolean chatting$isHovered(int x, int y, int width, int height) { - Drawable hud = Chatting.INSTANCE.getChatWindow().get(); - ScaledResolution scaleResolution = new ScaledResolution(this.mc); - int scale = scaleResolution.getScaleFactor(); - int mouseX = Mouse.getX(); - int mouseY = this.mc.displayHeight - Mouse.getY(); - int actualX = (int) (((int) hud.getX() + (x + hud.getPadding().getX()) * hud.getScaleX()) * scale); - int actualY = (int) (((int) hud.getY() + hud.getHeight() + (y - hud.getPadding().getY()) * hud.getScaleY()) * scale); - return mouseX > actualX && mouseX < actualX + width * hud.getScaleX() * scale && mouseY > actualY && mouseY < actualY + height * hud.getScaleY() * scale; - } - - @ModifyVariable(method = "drawChat", at = @At("STORE"), ordinal = 0) - private double modifyYeah(double value) { - chatting$textOpacity = chatting$getOpacity(chatting$updateCounter, chatting$chatLine); - if (chatting$textOpacity == Integer.MIN_VALUE) { - chatting$textOpacity = 0; - } - return chatting$closing ? 1 : value; - } - - @Inject(method = "getChatOpen", at = @At("HEAD"), cancellable = true) - private void chatPeek(CallbackInfoReturnable cir) { - cir.setReturnValue(this.mc.currentScreen instanceof GuiChat || Chatting.INSTANCE.getPeeking()); - } - - @Inject(method = "drawChat", at = @At("RETURN")) - private void checkStuff(int j2, CallbackInfo ci) { - if (!chatting$chatCheck && chatting$isHovering) { - chatting$isHovering = false; - } - } - - @Inject(method = "getChatScale", at = @At("HEAD"), cancellable = true) - private void chatScale(CallbackInfoReturnable cir) { - cir.setReturnValue(Chatting.INSTANCE.getChatWindow().get().getScaleY()); - } - - @Override - public int chatting$getRight() { - return chatting$right; - } - - @Override - public boolean chatting$isHovering() { - return chatting$isHovering; - } - - @Unique - private void chatting$drawCopyChatBox(int right, int top) { - chatting$chatCheck = true; - GlStateManager.enableRescaleNormal(); - GlStateManager.enableBlend(); - GlStateManager.enableDepth(); - GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); - GlStateManager.pushMatrix(); - int posLeft = right + 1; - int posRight = right + 10; - if (!ChattingConfig.INSTANCE.getExtendBG()) { - Drawable hud = Chatting.INSTANCE.getChatWindow().get(); - GlStateManager.translate(hud.getPadding().getX() * hud.getScaleX(), 0f, 0f); - } - if (ChattingConfig.INSTANCE.getChatCopy()) { - this.mc.getTextureManager().bindTexture(chatting$COPY); - chatting$right = right; - boolean hovered = chatting$isHovered(posLeft, top, posRight - posLeft, 9); - PolyColor color = hovered ? ChattingConfig.INSTANCE.getChatButtonHoveredBackgroundColor() : ChattingConfig.INSTANCE.getChatButtonBackgroundColor(); - drawRect(posLeft, top, posRight, top + 9, color.getRgba()); - color = hovered ? ChattingConfig.INSTANCE.getChatButtonHoveredColor() : ChattingConfig.INSTANCE.getChatButtonColor(); - GlStateManager.pushMatrix(); - GlStateManager.enableAlpha(); - GlStateManager.enableBlend(); - GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); - if (ChattingConfig.INSTANCE.getButtonShadow()) { - GlStateManager.color(0f, 0f, 0f, color.getAlpha()); - drawModalRectWithCustomSizedTexture(posLeft + 1, top + 1, 0f, 0f, 9, 9, 9, 9); - } - GlStateManager.color(color.red() / 255f, color.green() / 255f, color.blue() / 255f, color.getAlpha()); - drawModalRectWithCustomSizedTexture(posLeft, top, 0f, 0f, 9, 9, 9, 9); - GlStateManager.disableAlpha(); - GlStateManager.disableBlend(); - GlStateManager.popMatrix(); - posLeft += 10; - posRight += 10; - } - if (ChattingConfig.INSTANCE.getChatDelete()) { - this.mc.getTextureManager().bindTexture(chatting$DELETE); - boolean hovered = chatting$isHovered(posLeft, top, posRight - posLeft, 9); - PolyColor color = hovered ? ChattingConfig.INSTANCE.getChatButtonHoveredBackgroundColor() : ChattingConfig.INSTANCE.getChatButtonBackgroundColor(); - drawRect(posLeft, top, posRight, top + 9, color.getRgba()); - color = hovered ? ChattingConfig.INSTANCE.getChatButtonHoveredColor() : ChattingConfig.INSTANCE.getChatButtonColor(); - GlStateManager.pushMatrix(); - GlStateManager.enableAlpha(); - GlStateManager.enableBlend(); - GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); - if (ChattingConfig.INSTANCE.getButtonShadow()) { - GlStateManager.color(0f, 0f, 0f, color.getAlpha()); - drawModalRectWithCustomSizedTexture(posLeft + 1, top + 1, 0f, 0f, 9, 9, 9, 9); - } - GlStateManager.color(color.red() / 255f, color.green() / 255f, color.blue() / 255f, color.getAlpha()); - drawModalRectWithCustomSizedTexture(posLeft, top, 0f, 0f, 9, 9, 9, 9); - GlStateManager.disableAlpha(); - GlStateManager.disableBlend(); - GlStateManager.popMatrix(); - } - GlStateManager.disableLighting(); - GlStateManager.popMatrix(); - } - - @Override - public ChatLine chatting$getHoveredLine(int mouseY) { - if (this.getChatOpen()) { - ScaledResolution scaledresolution = new ScaledResolution(this.mc); - int i = scaledresolution.getScaleFactor(); - Drawable hud = Chatting.INSTANCE.getChatWindow().get(); - float f = hud.getScaleY(); - int k = (int) (mouseY / i - (scaledresolution.getScaledHeight() - hud.getY() + hud.getHeight() + hud.getPadding().getY() * hud.getScaleY()) + ModCompatHooks.getYOffset()); - k = MathHelper.floor_float((float) k / f); - - if (k >= 0) { - int l = Math.min(this.getLineCount(), this.drawnChatLines.size()); - - if (k < this.mc.fontRendererObj.FONT_HEIGHT * l + l) { - int i1 = k / this.mc.fontRendererObj.FONT_HEIGHT + this.scrollPos; - - if (i1 >= 0 && i1 < this.drawnChatLines.size()) { - List m = ChatSearchingManager.filterMessages(ChatSearchingManager.INSTANCE.getLastSearch(), this.drawnChatLines); - return m != null ? m.get(i1) : null; - } - - } - } - } - return null; - } - - @Override - public String chatting$getChattingChatComponent(int mouseY, int mouseButton) { - ChatLine subLine = chatting$getHoveredLine(mouseY); - if (subLine != null) { - ChatLine fullLine = ((ChatLineHook) subLine).chatting$getFullMessage(); - if (GuiScreen.isShiftKeyDown() && mouseButton == 0) { - if (fullLine != null) { - BufferedImage image = Chatting.INSTANCE.screenshotLine(subLine); - if (image != null) Clipboard.getInstance().setImage(new BufferedClipboardImage(image)); - } - return null; - } - ChatLine line = GuiScreen.isCtrlKeyDown() && mouseButton == 0 ? subLine : fullLine; - String message = line == null ? "Could not find chat message." : line.getChatComponent().getFormattedText(); - String actualMessage = GuiScreen.isAltKeyDown() ? message : EnumChatFormatting.getTextWithoutFormattingCodes(message); - Notifications.enqueue(Notifications.Type.Warning, "Chatting", line == null ? "Could not find chat message." : "Copied following text: " + actualMessage); - return actualMessage; - } - return null; - } - - @Override - public int chatting$getTextOpacity() { - return chatting$textOpacity; - } -} diff --git a/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin_ChatHeight.java b/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin_ChatHeight.java deleted file mode 100644 index 74be775..0000000 --- a/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin_ChatHeight.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.polyfrost.chatting.mixin; - -import net.minecraft.client.gui.GuiNewChat; -import org.polyfrost.chatting.Chatting; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(GuiNewChat.class) -public abstract class GuiNewChatMixin_ChatHeight { - @Shadow public abstract boolean getChatOpen(); - - @Inject(method = "getChatHeight", at = @At("HEAD"), cancellable = true) - private void customHeight_getChatHeight(CallbackInfoReturnable cir) { - if (Chatting.INSTANCE.getChatWindow().getCustomChatHeight()) - cir.setReturnValue(Chatting.INSTANCE.getChatHeight(getChatOpen())); - } - - @Inject(method = "getChatWidth", at = @At("HEAD"), cancellable = true) - private void customWidth_getChatWidth(CallbackInfoReturnable cir) { - if (Chatting.INSTANCE.getChatWindow().getCustomChatWidth()) - cir.setReturnValue(Chatting.INSTANCE.getChatWidth()); - } -} diff --git a/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin_ChatPeek.java b/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin_ChatPeek.java deleted file mode 100644 index f9ebe37..0000000 --- a/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin_ChatPeek.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.polyfrost.chatting.mixin; - -import net.minecraft.client.gui.GuiNewChat; -import org.polyfrost.chatting.Chatting; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(value = GuiNewChat.class, priority = 1100) -public class GuiNewChatMixin_ChatPeek { - - @Inject(method = "getChatOpen", at = @At("HEAD"), cancellable = true) - private void chatPeek(CallbackInfoReturnable cir) { - if (Chatting.INSTANCE.getPeeking()) cir.setReturnValue(true); - } - -} \ No newline at end of file diff --git a/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin_ChatSearching.java b/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin_ChatSearching.java deleted file mode 100644 index 4870c83..0000000 --- a/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin_ChatSearching.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.polyfrost.chatting.mixin; - -import net.minecraft.client.gui.ChatLine; -import net.minecraft.client.gui.GuiNewChat; -import net.minecraft.util.IChatComponent; -import org.objectweb.asm.Opcodes; -import org.polyfrost.chatting.chat.ChatSearchingManager; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import java.util.List; - -@Mixin(GuiNewChat.class) -public class GuiNewChatMixin_ChatSearching { - @Shadow - @Final - private List drawnChatLines; - - @Inject(method = "setChatLine", at = @At("HEAD")) - private void handleSetChatLine(IChatComponent chatComponent, int chatLineId, int updateCounter, boolean displayOnly, CallbackInfo ci) { - ChatSearchingManager.getCache().invalidateAll(); - } - - @Redirect(method = "drawChat", at = @At(value = "FIELD", target = "Lnet/minecraft/client/gui/GuiNewChat;drawnChatLines:Ljava/util/List;", opcode = Opcodes.GETFIELD)) - private List injected(GuiNewChat instance) { - return ChatSearchingManager.filterMessages(ChatSearchingManager.INSTANCE.getLastSearch(), this.drawnChatLines); - } -} diff --git a/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin_ChatTabs.java b/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin_ChatTabs.java deleted file mode 100644 index 84bb81e..0000000 --- a/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin_ChatTabs.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.polyfrost.chatting.mixin; - -import org.polyfrost.chatting.chat.ChatTabs; -import org.polyfrost.chatting.config.ChattingConfig; -import org.polyfrost.chatting.utils.ModCompatHooks; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.ChatLine; -import net.minecraft.client.gui.GuiNewChat; -import net.minecraft.util.IChatComponent; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import java.util.List; - -@Mixin(value = GuiNewChat.class, priority = 990) -public abstract class GuiNewChatMixin_ChatTabs { - @Shadow @Final private Minecraft mc; - - @Shadow public abstract void deleteChatLine(int id); - - @Shadow @Final private List chatLines; - - @Inject(method = "printChatMessageWithOptionalDeletion", at = @At("HEAD"), cancellable = true) - private void handlePrintChatMessage(IChatComponent chatComponent, int chatLineId, CallbackInfo ci) { - chatting$handleChatTabMessage(chatComponent, chatLineId, this.mc.ingameGUI.getUpdateCounter(), false, ci); - } - - @Inject(method = "setChatLine", at = @At("HEAD"), cancellable = true) - private void handleSetChatLine(IChatComponent chatComponent, int chatLineId, int updateCounter, boolean displayOnly, CallbackInfo ci) { - chatting$handleChatTabMessage(chatComponent, chatLineId, updateCounter, displayOnly, ci); - } - - @Unique - private void chatting$handleChatTabMessage(IChatComponent chatComponent, int chatLineId, int updateCounter, boolean displayOnly, CallbackInfo ci) { - if (ChattingConfig.INSTANCE.getChatTabs()) { - ChatTabs.INSTANCE.setHasCancelledAnimation(!ChatTabs.INSTANCE.shouldRender(chatComponent)); - if (!ChatTabs.INSTANCE.shouldRender(chatComponent)) { - if (chatLineId != 0) { - deleteChatLine(chatLineId); - } - if (!displayOnly) { - this.chatLines.add(0, new ChatLine(updateCounter, chatComponent, chatLineId)); - while (this.chatLines.size() > (100 + ModCompatHooks.getExtendedChatLength())) { - this.chatLines.remove(this.chatLines.size() - 1); - } - } - ci.cancel(); - } - } - } -} diff --git a/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin_Movable.java b/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin_Movable.java deleted file mode 100644 index e65a63a..0000000 --- a/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin_Movable.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.polyfrost.chatting.mixin; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.ChatLine; -import net.minecraft.client.gui.GuiNewChat; -import net.minecraft.client.gui.ScaledResolution; -import net.minecraft.util.MathHelper; -import org.polyfrost.chatting.Chatting; -import org.polyfrost.chatting.config.ChattingConfig; -import org.polyfrost.chatting.hook.ChatLineHook; -import org.polyfrost.chatting.utils.ModCompatHooks; -import org.polyfrost.oneconfig.api.hud.v1.HudManager; -import org.polyfrost.polyui.component.Drawable; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.*; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.invoke.arg.Args; - -@Mixin(GuiNewChat.class) -public abstract class GuiNewChatMixin_Movable { - - @Shadow - public abstract int getChatWidth(); - - @Unique - private static ChatLine chatting$currentLine; - - @ModifyArgs(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;translate(FFF)V", ordinal = 0)) - private void translate(Args args) { - Drawable hud = Chatting.INSTANCE.getChatWindow().get(); - args.set(0, hud.getX() + hud.getPadding().getX() * hud.getScaleX()); - args.set(1, hud.getY() + hud.getHeight() - hud.getPadding().getY() * hud.getScaleY()); - } - - @ModifyVariable(method = "drawChat", at = @At(value = "STORE", ordinal = 0), ordinal = 4) - private int width(int value) { - return MathHelper.ceiling_float_int((float) this.getChatWidth()); - } - - @ModifyConstant(method = "drawChat", constant = @Constant(intValue = 9, ordinal = 0)) - private int chatMode(int constant) { - return constant; - } - - @Inject(method = "drawChat", at = @At(value = "HEAD"), cancellable = true) - private void exampleChat(int updateCounter, CallbackInfo ci) { - if (HudManager.isPanelOpen()) ci.cancel(); - } - - @ModifyConstant(method = "getChatComponent", constant = @Constant(intValue = 3)) - private int mouseX(int constant) { - Drawable hud = Chatting.INSTANCE.getChatWindow().get(); - return (int) ((hud.getX()) + (hud.getPadding().getX() + 1) * hud.getScaleX()); - } - - @ModifyConstant(method = "getChatComponent", constant = @Constant(intValue = 27)) - private int mouseY(int constant) { - int height = new ScaledResolution(Minecraft.getMinecraft()).getScaledHeight(); - Drawable hud = Chatting.INSTANCE.getChatWindow().get(); - return height - (int) (hud.getY() + hud.getHeight() - hud.getPadding().getY() * hud.getScaleY() + ModCompatHooks.getChatPosition()); - } - - @ModifyVariable(method = "getChatComponent", at = @At("STORE"), ordinal = 0) - private ChatLine capture(ChatLine chatLine) { - chatting$currentLine = chatLine; - return chatLine; - } - - @ModifyConstant(method = "getChatComponent", constant = @Constant(intValue = 0)) - private int offset(int value) { - return ((ChatLineHook) chatting$currentLine).chatting$hasDetected() || ChattingConfig.INSTANCE.getOffsetNonPlayerMessages() ? ModCompatHooks.getChatHeadOffset() : 0; - } - - @Redirect(method = "getChatComponent", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiNewChat;getChatScale()F", ordinal = 0)) - private float getScale(GuiNewChat instance) { - return Chatting.INSTANCE.getChatWindow().get().getScaleX(); - } - - @ModifyArg(method = "getChatComponent", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/MathHelper;floor_float(F)I", ordinal = 2)) - private float width(float value) { - Drawable hud = Chatting.INSTANCE.getChatWindow().get(); - return hud.getX() + hud.getWidth(); - } - -} \ No newline at end of file diff --git a/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin_Scrolling.java b/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin_Scrolling.java deleted file mode 100644 index 6f54155..0000000 --- a/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin_Scrolling.java +++ /dev/null @@ -1,60 +0,0 @@ -package org.polyfrost.chatting.mixin; - -import net.minecraft.client.gui.Gui; -import net.minecraft.client.gui.GuiNewChat; -import org.polyfrost.chatting.chat.ChatScrollingHook; -import org.polyfrost.chatting.config.ChattingConfig; -import org.polyfrost.polyui.animate.Animation; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(GuiNewChat.class) -public abstract class GuiNewChatMixin_Scrolling extends Gui { - @Shadow - private int scrollPos; - - @Unique - private final Animation chatting$scrollingAnimation = Animation.Type.EaseInOutQuad.create((long) (ChattingConfig.INSTANCE.getScrollingSpeed() * 1000L), 0f, 0f); - - @Inject(method = "drawChat", at = @At("HEAD")) - private void chatting$scrollingAnimationStart(int updateCounter, CallbackInfo ci) { - boolean shouldSmooth = ChatScrollingHook.INSTANCE.getShouldSmooth(); - if (shouldSmooth) ChatScrollingHook.INSTANCE.setShouldSmooth(false); - if (ChattingConfig.INSTANCE.getSmoothScrolling()) { - if (!chatting$scrollingAnimation.isFinished()) { - if (Math.abs(chatting$scrollingAnimation.getTo() - this.scrollPos) > 1 && shouldSmooth) { - chatting$scrollingAnimation.setFrom(chatting$scrollingAnimation.getValue()); - chatting$scrollingAnimation.setTo(this.scrollPos); - chatting$scrollingAnimation.reset(); - } else { - chatting$scrollingAnimation.finishNow(); - } - } - } - } - - @Redirect(method = "drawChat", at = @At(value = "FIELD", target = "Lnet/minecraft/client/gui/GuiNewChat;scrollPos:I")) - private int redirectPos(GuiNewChat instance) { - return ChattingConfig.INSTANCE.getSmoothScrolling() ? (int) chatting$scrollingAnimation.getValue() : this.scrollPos; - } - - @Redirect(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiNewChat;drawRect(IIIII)V", ordinal = 1)) - private void redirectScrollBar(int left, int top, int right, int bottom, int color) { - if (!ChattingConfig.INSTANCE.getRemoveScrollBar()) { - drawRect(left, top, right, bottom, color); - } - } - - @Redirect(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiNewChat;drawRect(IIIII)V", ordinal = 2)) - private void redirectScrollBar2(int left, int top, int right, int bottom, int color) { - if (!ChattingConfig.INSTANCE.getRemoveScrollBar()) { - drawRect(left, top, right, bottom, color); - } - } - -} diff --git a/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin_SmoothMessages.java b/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin_SmoothMessages.java deleted file mode 100644 index c088082..0000000 --- a/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin_SmoothMessages.java +++ /dev/null @@ -1,105 +0,0 @@ -package org.polyfrost.chatting.mixin; - -import net.minecraft.client.gui.GuiNewChat; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.util.EnumChatFormatting; -import net.minecraft.util.IChatComponent; -import org.polyfrost.chatting.chat.ChatSearchingManager; -import org.polyfrost.chatting.chat.ChatTabs; -import org.polyfrost.chatting.config.ChattingConfig; -import org.polyfrost.chatting.utils.ModCompatHooks; -import org.polyfrost.polyui.animate.Animation; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.ModifyArg; -import org.spongepowered.asm.mixin.injection.ModifyVariable; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import java.util.List; -import java.util.Locale; - -/** - * Taken from BetterChat under LGPL 3.0 - * https://github.com/LlamaLad7/Better-Chat/blob/1.8.9/LICENSE - */ -@Mixin(GuiNewChat.class) -public abstract class GuiNewChatMixin_SmoothMessages { - @Shadow - private boolean isScrolled; - - @Shadow - public abstract float getChatScale(); - - @Unique - private int chatting$newLines; - - @Unique - private Animation chatting$anim = Animation.Type.EaseInOutQuad.create((long) (1.0f - ChattingConfig.INSTANCE.getMessageSpeed()) * 1000L, 0f, 1f); - @Unique - private float chatting$animationPercent; - @Unique - private int chatting$lineBeingDrawn; - - @Inject(method = "drawChat", at = @At("HEAD")) - private void modifyChatRendering(CallbackInfo ci) { - if (chatting$anim != null) { - if (chatting$anim.isFinished()) { - chatting$anim = null; - } else { - chatting$animationPercent = chatting$anim.getValue(); - } - } else { - chatting$animationPercent = 1; - } - } - - @Inject(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;pushMatrix()V", ordinal = 0, shift = At.Shift.AFTER)) - private void translate(CallbackInfo ci) { - float y = 0; - if (ChattingConfig.INSTANCE.getSmoothChat() && !this.isScrolled) { - y += (9 - 9 * chatting$animationPercent) * this.getChatScale(); - } - GlStateManager.translate(0, y, 0); - } - - @ModifyArg(method = "drawChat", at = @At(value = "INVOKE", target = "Ljava/util/List;get(I)Ljava/lang/Object;", ordinal = 0, remap = false), index = 0) - private int getLineBeingDrawn(int line) { - chatting$lineBeingDrawn = line; - return line; - } - - @ModifyArg(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/FontRenderer;drawStringWithShadow(Ljava/lang/String;FFI)I")) - private int modifyTextOpacity(int original) { - if (ChattingConfig.INSTANCE.getSmoothChat() && chatting$lineBeingDrawn <= chatting$newLines) { - int opacity = (original >> 24) & 0xFF; - opacity *= chatting$animationPercent; - return (original & ~(0xFF << 24)) | (opacity << 24); - } else { - return original; - } - } - - @Inject(method = "printChatMessageWithOptionalDeletion", at = @At("HEAD")) - private void resetPercentage(IChatComponent chatComponent, int chatLineId, CallbackInfo ci) { - if (!EnumChatFormatting.getTextWithoutFormattingCodes(chatComponent.getUnformattedText()).toLowerCase(Locale.ENGLISH).contains(ChatSearchingManager.INSTANCE.getLastSearch().toLowerCase(Locale.ENGLISH))) { - return; - } - if (ModCompatHooks.getBetterChatSmoothMessages()) { - return; - } - if (ChatTabs.INSTANCE.getHasCancelledAnimation()) { - ChatTabs.INSTANCE.setHasCancelledAnimation(false); - return; - } - chatting$anim = Animation.Type.EaseInOutQuad.create((long) (1.0f - ChattingConfig.INSTANCE.getMessageSpeed()) * 1000L, 0f, 1f); - } - - @ModifyVariable(method = "setChatLine", at = @At("STORE"), ordinal = 0) - private List setNewLines(List original) { - chatting$newLines = original.size() - 1; - return original; - } -} diff --git a/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin_TextRendering.java b/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin_TextRendering.java deleted file mode 100644 index c636e2c..0000000 --- a/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin_TextRendering.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.polyfrost.chatting.mixin; - -import net.minecraft.client.gui.ChatLine; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.gui.GuiNewChat; -import org.polyfrost.chatting.utils.ModCompatHooks; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; - -@Mixin(value = GuiNewChat.class, priority = 990) -public class GuiNewChatMixin_TextRendering { - @Unique - private ChatLine chatting$drawingLine = null; - - @Inject(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/ChatLine;getChatComponent()Lnet/minecraft/util/IChatComponent;"), locals = LocalCapture.CAPTURE_FAILSOFT) - private void captureChatLine(int updateCounter, CallbackInfo ci, int i, boolean bl, int j, int k, float f, float g, int l, int m, ChatLine chatLine, int n, double d, int o, int p, int q) { - chatting$drawingLine = chatLine; - } - - @Redirect(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/FontRenderer;drawStringWithShadow(Ljava/lang/String;FFI)I")) - private int redirectDrawString(FontRenderer instance, String text, float x, float y, int color) { - return ModCompatHooks.redirectDrawString(text, x, y, color, chatting$drawingLine); - } -} diff --git a/src/main/java/org/polyfrost/chatting/mixin/GuiTextFieldMixin.java b/src/main/java/org/polyfrost/chatting/mixin/GuiTextFieldMixin.java deleted file mode 100644 index 189c683..0000000 --- a/src/main/java/org/polyfrost/chatting/mixin/GuiTextFieldMixin.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.polyfrost.chatting.mixin; - -import net.minecraft.client.gui.GuiTextField; -import org.polyfrost.chatting.chat.ChatHooks; -import org.polyfrost.chatting.config.ChattingConfig; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.ModifyVariable; - -@Mixin(GuiTextField.class) -public abstract class GuiTextFieldMixin { - - @ModifyVariable(method = "drawTextBox", at = @At(value = "STORE"), ordinal = 5) - private int getRight(int right) { - if (ChatHooks.INSTANCE.checkField(this)) ChatHooks.INSTANCE.setInputRight(right); - return right; - } -} diff --git a/src/main/java/org/polyfrost/chatting/mixin/GuiUtilsMixin.java b/src/main/java/org/polyfrost/chatting/mixin/GuiUtilsMixin.java deleted file mode 100644 index 41eb223..0000000 --- a/src/main/java/org/polyfrost/chatting/mixin/GuiUtilsMixin.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.polyfrost.chatting.mixin; - -import net.minecraft.client.gui.FontRenderer; -import net.minecraftforge.fml.client.config.GuiUtils; -import org.polyfrost.chatting.config.ChattingConfig; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(value = GuiUtils.class, remap = false) -public class GuiUtilsMixin { - @Shadow - public static void drawGradientRect(int zLevel, int left, int top, int right, int bottom, int startColor, int endColor) { - } - - @Redirect(method = "drawHoveringText", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/client/config/GuiUtils;drawGradientRect(IIIIIII)V")) - private static void redirectBackground(int zLevel, int left, int top, int right, int bottom, int startColor, int endColor) { - if (!ChattingConfig.INSTANCE.getRemoveTooltipBackground()) { - drawGradientRect(zLevel, left, top, right, bottom, startColor, endColor); - } - } - - @Redirect(method = "drawHoveringText", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/FontRenderer;drawStringWithShadow(Ljava/lang/String;FFI)I")) - private static int redirectText(FontRenderer instance, String text, float x, float y, int color) { - switch (ChattingConfig.INSTANCE.getTooltipTextRenderType()) { - case 0: - return instance.drawString(text, x, y, color, false); -// case 2: TODO -// return TextRenderer.drawBorderedText(text, x, y, color, 255); - default: - return instance.drawStringWithShadow(text, x, y, color); - } - } -} diff --git a/src/main/java/org/polyfrost/chatting/mixin/InventoryPlayerMixin.java b/src/main/java/org/polyfrost/chatting/mixin/InventoryPlayerMixin.java deleted file mode 100644 index 40ecf7b..0000000 --- a/src/main/java/org/polyfrost/chatting/mixin/InventoryPlayerMixin.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.polyfrost.chatting.mixin; - -import net.minecraft.entity.player.InventoryPlayer; -import org.polyfrost.chatting.Chatting; -import org.polyfrost.chatting.config.ChattingConfig; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(InventoryPlayer.class) -public class InventoryPlayerMixin { - @Inject(method = "changeCurrentItem", at = @At("HEAD"), cancellable = true) - private void cancelHotbarScrolling(int direction, CallbackInfo ci) { - if (Chatting.INSTANCE.getPeeking() && ChattingConfig.INSTANCE.getPeekScrolling()) { - ci.cancel(); - } - } -} \ No newline at end of file diff --git a/src/main/java/org/polyfrost/chatting/mixin/compat/ChatPeekMixin_SkyHanni.java b/src/main/java/org/polyfrost/chatting/mixin/compat/ChatPeekMixin_SkyHanni.java deleted file mode 100644 index 508bd94..0000000 --- a/src/main/java/org/polyfrost/chatting/mixin/compat/ChatPeekMixin_SkyHanni.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.polyfrost.chatting.mixin.compat; - -import org.polyfrost.chatting.config.ChattingConfig; -import org.polyfrost.oneconfig.api.ui.v1.Notifications; -import org.spongepowered.asm.mixin.Dynamic; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Pseudo; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Pseudo -@Mixin(targets = {"at.hannibal2.skyhanni.features.chat.ChatPeek"}) -public class ChatPeekMixin_SkyHanni { - - @Unique - private static long chatting$lastNotify = System.currentTimeMillis(); - - @Dynamic("SkyHanni") - @Inject(method = "peek", at = @At("RETURN"), cancellable = true) - private static void cancel(CallbackInfoReturnable cir) { - if (!ChattingConfig.INSTANCE.getChatPeek() && cir.getReturnValue()) { - if (System.currentTimeMillis() - chatting$lastNotify >= 1000) { - Notifications.enqueue(Notifications.Type.Info, "Chatting", "SkyHanni's chat peek has been replaced by Chatting. You can configure this via OneConfig, by clicking the right shift key on your keyboard, or by typing /chatting in your chat."); - chatting$lastNotify = System.currentTimeMillis(); - } - } - cir.setReturnValue(false); - } -} \ No newline at end of file diff --git a/src/main/java/org/polyfrost/chatting/mixin/compat/ChatTabsMixin_SkytilsCopyChat.java b/src/main/java/org/polyfrost/chatting/mixin/compat/ChatTabsMixin_SkytilsCopyChat.java deleted file mode 100644 index 03ce3fd..0000000 --- a/src/main/java/org/polyfrost/chatting/mixin/compat/ChatTabsMixin_SkytilsCopyChat.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.polyfrost.chatting.mixin.compat; - -import net.minecraft.client.gui.GuiScreen; -import org.polyfrost.chatting.config.ChattingConfig; -import org.polyfrost.oneconfig.api.ui.v1.Notifications; -import org.spongepowered.asm.mixin.Dynamic; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Pseudo; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Pseudo -@Mixin(targets = "gg.skytils.skytilsmod.features.impl.handlers.ChatTabs") -public class ChatTabsMixin_SkytilsCopyChat { - - @Unique - private static long chatting$lastNotify = System.currentTimeMillis(); - - @Dynamic("Skytils") - @Redirect(method = "onAttemptCopy", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiScreen;isCtrlKeyDown()Z")) - private boolean onAttemptCopy() { - boolean isCtrlKeyDown = GuiScreen.isCtrlKeyDown(); - if (!ChattingConfig.INSTANCE.getRightClickCopy() && isCtrlKeyDown) { - if (System.currentTimeMillis() - chatting$lastNotify >= 1000) { - Notifications.enqueue(Notifications.Type.Info, "Chatting", "Skytils' Copy Chat has been replaced by Chatting. You can configure this via OneConfig, by clicking the right shift key on your keyboard, or by typing /chatting in your chat."); - chatting$lastNotify = System.currentTimeMillis(); - } - } - return false; - } - - @Dynamic("Skytils") - @Redirect(method = "onAttemptCopy", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiScreen;isShiftKeyDown()Z")) - private boolean onAttemptCopyShift() { - boolean isShiftKeyDown = GuiScreen.isShiftKeyDown(); - if (!ChattingConfig.INSTANCE.getRightClickCopy() && isShiftKeyDown) { - if (System.currentTimeMillis() - chatting$lastNotify >= 1000) { - Notifications.enqueue(Notifications.Type.Info, "Chatting", "Skytils' Copy Chat has been replaced by Chatting. You can configure this via OneConfig, by clicking the right shift key on your keyboard, or by typing /chatting in your chat."); - chatting$lastNotify = System.currentTimeMillis(); - } - } - return false; - } -} diff --git a/src/main/java/org/polyfrost/chatting/mixin/compat/EssentialKeybindingRegistryMixin.java b/src/main/java/org/polyfrost/chatting/mixin/compat/EssentialKeybindingRegistryMixin.java deleted file mode 100644 index 253ebd8..0000000 --- a/src/main/java/org/polyfrost/chatting/mixin/compat/EssentialKeybindingRegistryMixin.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.polyfrost.chatting.mixin.compat; - -import org.polyfrost.chatting.config.ChattingConfig; -import org.polyfrost.oneconfig.api.ui.v1.Notifications; -import org.spongepowered.asm.mixin.Dynamic; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Pseudo; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Pseudo -@Mixin(targets = {"gg.essential.key.EssentialKeybindingRegistry"}) -public class EssentialKeybindingRegistryMixin { - - @Unique - private long chatting$lastNotify = System.currentTimeMillis(); - - @Dynamic("Essential") - @Inject(method = "isHoldingChatPeek", at = @At("RETURN"), cancellable = true) - private void overrideChatPeek(CallbackInfoReturnable cir) { - if (!ChattingConfig.INSTANCE.getChatPeek() && cir.getReturnValue()) { - if (System.currentTimeMillis() - chatting$lastNotify >= 1000) { - Notifications.enqueue(Notifications.Type.Info, "Chatting", "Essential's chat peek has been replaced by Chatting. You can configure this via OneConfig, by clicking the right shift key on your keyboard, or by typing /chatting in your chat."); - chatting$lastNotify = System.currentTimeMillis(); - } - } - cir.setReturnValue(false); - } -} \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/chatting/ChatWindow.kt b/src/main/kotlin/org/polyfrost/chatting/ChatWindow.kt new file mode 100644 index 0000000..89a2dcc --- /dev/null +++ b/src/main/kotlin/org/polyfrost/chatting/ChatWindow.kt @@ -0,0 +1,127 @@ +package org.polyfrost.chatting + +import dev.deftu.omnicore.client.render.OmniResolution +import net.minecraft.client.font.TextRenderer +import net.minecraft.client.gui.DrawContext +import net.minecraft.client.gui.hud.ChatHudLine +import net.minecraft.client.gui.screen.ChatScreen +import net.minecraft.network.message.ChatVisibility +import net.minecraft.util.math.ColorHelper +import org.polyfrost.chatting.mixin.ChatHudAccessor +import org.polyfrost.oneconfig.api.hud.v1.Hud +import org.polyfrost.oneconfig.utils.v1.OneImage +import org.polyfrost.oneconfig.utils.v1.dsl.mc +import org.polyfrost.polyui.color.argb +import org.polyfrost.polyui.color.rgba +import org.polyfrost.polyui.component.Drawable +import org.polyfrost.polyui.component.impl.Text +import org.polyfrost.polyui.data.PolyImage +import org.polyfrost.polyui.unit.Vec2 +import org.polyfrost.polyui.unit.milliseconds +import java.util.* +import javax.swing.text.StyleConstants.getComponent +import kotlin.math.round + +class ChatWindow() : Hud() { + + override fun title(): String { + return "Chat" + } + + override fun category(): Category { + return Category.INFO + } + + override fun create(): Drawable { + return ChatComponent() + } + + override fun updateFrequency(): Long { + return 25.milliseconds + } + + override fun multipleInstancesAllowed() = false + + override fun defaultPosition(): Vec2 { + return Vec2(200f, 200f) + } + + override fun update(): Boolean { + if (get() !is ChatComponent) return false + val accessor = mc.inGameHud.chatHud as ChatHudAccessor + hidden = mc.options.chatVisibility.getValue() == ChatVisibility.HIDDEN && accessor.visibleMessages.isEmpty() + + val bl = mc.currentScreen is ChatScreen + var u = 0 + val d = mc.options.chatOpacity.getValue().toDouble() * 0.9 + 0.1 + val component = get() as ChatComponent + component.renderingLines.clear() + while (u + accessor.scrolledLines < accessor.visibleMessages.size && u < mc.inGameHud.chatHud.visibleLineCount) { + val v = u + accessor.scrolledLines + val visible = accessor.visibleMessages[v] + if (visible != null) { + val w = mc.inGameHud.ticks - visible.comp_895() + if (w < 200 || bl) { + val h = if (bl) 1.0 else accessor.invokeGetMessageOpacityMultiplier(w) + val opacity = 255.0 * h + if ((opacity * d).toInt() > 3) { + component.renderingLines[visible] = opacity + } + } + } + ++u + } + + return true + } + + override fun hasBackground() = false + + class ChatComponent() : Drawable() { + + override var width = 0f + + override var height = 0f + + var renderingLines = LinkedHashMap() + + override fun draw() { // height might equal 0 + val accessor = mc.inGameHud.chatHud as ChatHudAccessor + width = (mc.inGameHud.chatHud.width + 12) * OmniResolution.scaleFactor.toFloat() + height = renderingLines.size * accessor.invokeGetLineHeight() * OmniResolution.scaleFactor.toFloat() + super.draw() + } + + override fun render() { + renderer.rect(x, y, width, height, rgba(0, 0, 0, 0.5f)) + val accessor = mc.inGameHud.chatHud as ChatHudAccessor + val drawContext = DrawContext(mc, mc.bufferBuilders.entityVertexConsumers) + val lineHeight = accessor.invokeGetLineHeight() + val spacing = mc.options.chatLineSpacing.getValue().toDouble() + val mcScale = OmniResolution.scaleFactor.toFloat() + val chatScale = mc.inGameHud.chatHud.chatScale.toFloat() + val chatOpacity = mc.options.chatOpacity.getValue() * 0.9 + 0.1 + val mcX = x / mcScale + val mcY = y / mcScale + renderingLines.reversed().onEachIndexed { i, (visible, opacity) -> + val textOpacity = (opacity * chatOpacity).toInt() + val textX = 4 + val lineY = i * lineHeight + val textY = round(lineY + spacing * 5 + 1).toInt() // trust me + val messageIndicator = visible.indicator() + if (messageIndicator != null) { + val color = messageIndicator.comp_899() or (textOpacity shl 24) + renderer.rect(x, y + lineY.toFloat() * mcScale, 2 * mcScale, lineHeight * mcScale, argb(color)) + renderer. +// drawContext.fill(0, lineY, 2, lineY + lineHeight, color) + } + drawContext.matrices.push() + drawContext.matrices.translate(mcX, mcY, 0f) + drawContext.matrices.scale(chatScale, chatScale, 1f) + drawContext.drawTextWithShadow(mc.textRenderer, visible.comp_896(), textX, textY, ColorHelper.withAlpha(textOpacity, -1)) + drawContext.matrices.pop() + } + } + + } +} \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/chatting/Chatting.kt b/src/main/kotlin/org/polyfrost/chatting/Chatting.kt index 2289799..5634a08 100644 --- a/src/main/kotlin/org/polyfrost/chatting/Chatting.kt +++ b/src/main/kotlin/org/polyfrost/chatting/Chatting.kt @@ -1,268 +1,16 @@ package org.polyfrost.chatting -import dev.deftu.clipboard.BufferedClipboardImage -import dev.deftu.clipboard.Clipboard -import dev.deftu.omnicore.client.OmniDesktop -import net.minecraft.client.gui.ChatLine -import net.minecraft.client.gui.GuiChat -import net.minecraft.client.gui.GuiNewChat -import net.minecraft.client.renderer.GlStateManager -import net.minecraft.client.renderer.OpenGlHelper -import net.minecraft.client.settings.KeyBinding -import net.minecraftforge.common.MinecraftForge.EVENT_BUS -import net.minecraftforge.fml.client.registry.ClientRegistry -import net.minecraftforge.fml.common.Loader -import net.minecraftforge.fml.common.Mod -import net.minecraftforge.fml.common.event.FMLInitializationEvent -import net.minecraftforge.fml.common.event.FMLLoadCompleteEvent -import net.minecraftforge.fml.common.event.FMLPostInitializationEvent -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import net.minecraftforge.fml.common.gameevent.TickEvent -import org.lwjgl.input.Keyboard -import org.polyfrost.chatting.chat.* -import org.polyfrost.chatting.config.ChattingConfig -import org.polyfrost.chatting.hook.ChatLineHook -import org.polyfrost.chatting.mixin.GuiNewChatAccessor -import org.polyfrost.chatting.utils.ModCompatHooks -import org.polyfrost.chatting.utils.createBindFramebuffer -import org.polyfrost.chatting.utils.screenshot +import net.fabricmc.api.ClientModInitializer import org.polyfrost.oneconfig.api.commands.v1.CommandManager -import org.polyfrost.oneconfig.api.ui.v1.Notifications -import org.polyfrost.oneconfig.utils.v1.dsl.mc -import org.polyfrost.oneconfig.utils.v1.dsl.openUI -import org.polyfrost.polyui.component.extensions.onClick -import java.awt.image.BufferedImage -import java.io.File -import java.net.URI -import java.nio.file.Paths -import java.text.SimpleDateFormat -import java.util.Date +import org.polyfrost.oneconfig.api.hud.v1.Hud +import org.polyfrost.oneconfig.api.hud.v1.HudManager +object Chatting : ClientModInitializer { -@Mod( - modid = Chatting.ID, - name = Chatting.NAME, - version = Chatting.VER, - modLanguageAdapter = "org.polyfrost.oneconfig.utils.v1.forge.KotlinLanguageAdapter" -) -object Chatting { - - val keybind = KeyBinding("Screenshot Chat", Keyboard.KEY_NONE, "Chatting") - const val NAME = "@MOD_NAME@" - const val VER = "@MOD_VERSION@" - const val ID = "@MOD_ID@" - var doTheThing = false - var isPatcher = false - private set - var isBetterChat = false - private set - var isSkytils = false - private set - var isHychat = false - private set - - val chatWindow = ChatWindow() - val chatInput = ChatInputBox() - - var peeking = false - get() = ChattingConfig.chatPeek && field - - private val fileFormatter: SimpleDateFormat = SimpleDateFormat("yyyy-MM-dd_HH.mm.ss'.png'") - - val oldModDir = Paths.get("W-OVERFLOW", NAME) - - @Mod.EventHandler - fun onInitialization(event: FMLInitializationEvent) { - ChattingConfig - if (!ChattingConfig.enabled) { - ChattingConfig.enabled = true - ChattingConfig.save() - } - if (!chatWindow.transferOverScale) { - chatWindow.normalScale = chatWindow.get().scaleX - chatWindow.transferOverScale = true - ChattingConfig.save() - } - chatWindow.updateMCChatScale() - CommandManager.register(CommandManager.literal("chatting").executes { ChattingConfig.openUI(); 1 }) - ClientRegistry.registerKeyBinding(keybind) - EVENT_BUS.register(this) - ChatTabs.initialize() - ChatShortcuts.initialize() - } - - @Mod.EventHandler - fun onPostInitialization(event: FMLPostInitializationEvent) { - isPatcher = Loader.isModLoaded("patcher") - isBetterChat = Loader.isModLoaded("betterchat") - isSkytils = Loader.isModLoaded("skytils") - isHychat = Loader.isModLoaded("hychat") + override fun onInitializeClient() { + ModConfig.preload() + CommandManager.register(ModCommand) + HudManager.register(ChatWindow()) } - @Mod.EventHandler - fun onForgeLoad(event: FMLLoadCompleteEvent) { - if (ChattingConfig.informForAlternatives) { - if (isHychat) { - Notifications.enqueue( - Notifications.Type.Info, - NAME, - "Hychat can be removed as it is replaced by Chatting. Click here for more information.", - ).onClick { OmniDesktop.browse(URI("https://microcontrollersdev.github.io/Alternatives/1.8.9/hychat")) } - } - if (isSkytils) { - try { - skytilsCompat(Class.forName("gg.skytils.skytilsmod.core.Config")) - } catch (e: Exception) { - e.printStackTrace() - try { - skytilsCompat(Class.forName("skytils.skytilsmod.core.Config")) - } catch (e: Exception) { - e.printStackTrace() - } - } - } - if (isBetterChat) { - Notifications.enqueue( - Notifications.Type.Info, - NAME, - "BetterChat can be removed as it is replaced by Chatting. Click here to open your mods folder to delete the BetterChat file.", - ).onClick { - OmniDesktop.open(File("./mods")) - } - } - } - } - - private fun skytilsCompat(skytilsClass: Class<*>) { - val instance = skytilsClass.getDeclaredField("INSTANCE").get(null) - val chatTabs = skytilsClass.getDeclaredField("chatTabs") - chatTabs.isAccessible = true - if (chatTabs.getBoolean(instance)) { - Notifications.enqueue( - Notifications.Type.Info, - NAME, - "Skytils' chat tabs can be disabled as it is replace by Chatting.\nClick here to automatically do this.", - ).onClick { - chatTabs.setBoolean(instance, false) - ChattingConfig.chatTabs = true - ChattingConfig.hypixelOnlyChatTabs = true - ChattingConfig.save() - skytilsClass.getMethod("markDirty").invoke(instance) - skytilsClass.getMethod("writeData").invoke(instance) - false - } - } - val copyChat = skytilsClass.getDeclaredField("copyChat") - copyChat.isAccessible = true - if (copyChat.getBoolean(instance)) { - Notifications.enqueue( - Notifications.Type.Info, - NAME, - "Skytils' copy chat messages can be disabled as it is replace by Chatting.\nClick here to automatically do this.", - ).onClick { - copyChat.setBoolean(instance, false) - skytilsClass.getMethod("markDirty").invoke(instance) - skytilsClass.getMethod("writeData").invoke(instance) - false - } - } - } - - @SubscribeEvent - fun onTickEvent(event: TickEvent.ClientTickEvent) { - if (event.phase == TickEvent.Phase.START && mc.theWorld != null && mc.thePlayer != null) { - if ((mc.currentScreen == null || mc.currentScreen is GuiChat)) { - if (doTheThing) { - screenshotChat() - doTheThing = false - } - } - } - } - - fun getChatHeight(opened: Boolean): Int { - return if (opened) chatWindow.focusedHeight else chatWindow.unfocusedHeight - } - - fun getChatWidth(): Int { - return chatWindow.customWidth - } - - fun screenshotLine(line: ChatLine): BufferedImage? { - return screenshot( - linkedMapOf().also { map -> - val fullMessage = (line as ChatLineHook).`chatting$getFullMessage`() - for (chatLine in (mc.ingameGUI.chatGUI as GuiNewChatAccessor).drawnChatLines) { - if ((chatLine as ChatLineHook).`chatting$getFullMessage`() == fullMessage) { - map[chatLine] = chatLine.chatComponent.formattedText - } - } - } - ) - } - - private fun screenshotChat() { - screenshotChat(0) - } - - fun screenshotChat(scrollPos: Int) { - val hud = mc.ingameGUI - val chat = hud.chatGUI - val chatLines = LinkedHashMap() - ChatSearchingManager.filterMessages( - ChatSearchingManager.lastSearch, - (chat as GuiNewChatAccessor).drawnChatLines - )?.let { drawnLines -> - val chatHeight = - if (chatWindow.customChatHeight) getChatHeight(true) / 9 else GuiNewChat.calculateChatboxHeight( - mc.gameSettings.chatHeightFocused / 9 - ) - for (i in scrollPos until drawnLines.size.coerceAtMost(scrollPos + chatHeight)) { - chatLines[drawnLines[i]] = drawnLines[i].chatComponent.formattedText - } - - Clipboard.getInstance().setImage(BufferedClipboardImage(screenshot(chatLines))) - } - } - - private fun screenshot(messages: HashMap): BufferedImage? { - if (messages.isEmpty()) { - Notifications.enqueue(Notifications.Type.Warning, "Chatting", "Chat window is empty.") - return null - } - if (!OpenGlHelper.isFramebufferEnabled()) { - Notifications.enqueue( - Notifications.Type.Error, - "Chatting", - "Screenshot failed, please disable “Fast Render” in OptiFine’s “Performance” tab." - ) - return null - } - - val fr = ModCompatHooks.fontRenderer - val border = ChattingConfig.textRenderType == 2 - val offset = if (border) 1 else 0 - val width = messages.maxOf { fr.getStringWidth(it.value) + (if (ChattingConfig.showChatHeads && ((it.key as ChatLineHook).`chatting$hasDetected`() || ChattingConfig.offsetNonPlayerMessages)) 10 else 0) } + if (border) 2 else 1 - val fb = createBindFramebuffer(width * 2, (messages.size * 9 + offset) * 2) - val file = File(mc.mcDataDir, "screenshots/chat/" + fileFormatter.format(Date())) - - GlStateManager.scale(2f, 2f, 1f) - messages.entries.forEachIndexed { i: Int, entry: MutableMap.MutableEntry -> - ModCompatHooks.redirectDrawString(entry.value, offset.toFloat(), (messages.size - 1 - i) * 9f + offset.toFloat(), 0xFFFFFFFF.toInt(), entry.key) - } - - val image = fb.screenshot(file) - mc.entityRenderer.setupOverlayRendering() - mc.framebuffer.bindFramebuffer(true) - Notifications.enqueue( - Notifications.Type.Info, - "Chatting", - "Chat screenshotted successfully." + (if (ChattingConfig.copyMode != 1) "\nClick to open." else ""), - ).onClick { - if (!OmniDesktop.open(file)) { - Notifications.enqueue(Notifications.Type.Error, "Chatting", "Could not browse!") - } - } - return image - } } diff --git a/src/main/kotlin/org/polyfrost/chatting/ModCommand.kt b/src/main/kotlin/org/polyfrost/chatting/ModCommand.kt new file mode 100644 index 0000000..a1c00fd --- /dev/null +++ b/src/main/kotlin/org/polyfrost/chatting/ModCommand.kt @@ -0,0 +1,15 @@ +package org.polyfrost.chatting + +import org.polyfrost.oneconfig.api.commands.v1.factories.annotated.Command +import org.polyfrost.oneconfig.api.commands.v1.factories.annotated.Handler +import org.polyfrost.oneconfig.utils.v1.dsl.openUI + +@Command(ModConstants.ID) +object ModCommand { + + @Handler + private fun main() { + ModConfig.openUI() + } + +} diff --git a/src/main/kotlin/org/polyfrost/chatting/config/ChattingConfig.kt b/src/main/kotlin/org/polyfrost/chatting/ModConfig.kt similarity index 56% rename from src/main/kotlin/org/polyfrost/chatting/config/ChattingConfig.kt rename to src/main/kotlin/org/polyfrost/chatting/ModConfig.kt index 3736050..fc09383 100644 --- a/src/main/kotlin/org/polyfrost/chatting/config/ChattingConfig.kt +++ b/src/main/kotlin/org/polyfrost/chatting/ModConfig.kt @@ -1,27 +1,14 @@ -package org.polyfrost.chatting.config - -import club.sk1er.patcher.config.OldPatcherConfig -import org.polyfrost.chatting.Chatting -import org.polyfrost.chatting.chat.ChatShortcuts -import org.polyfrost.chatting.chat.ChatTab -import org.polyfrost.chatting.chat.ChatTabs -import org.polyfrost.chatting.gui.components.TabButton -import org.polyfrost.chatting.hook.ChatLineHook -import org.polyfrost.chatting.hook.GuiChatHook -import org.polyfrost.chatting.utils.ModCompatHooks +package org.polyfrost.chatting + +import dev.deftu.omnicore.client.OmniKeyboard import org.polyfrost.oneconfig.api.config.v1.Config -import org.polyfrost.oneconfig.api.config.v1.Property import org.polyfrost.oneconfig.api.config.v1.annotations.* import org.polyfrost.oneconfig.api.hypixel.v1.HypixelUtils -import org.polyfrost.oneconfig.utils.v1.dsl.mc +import org.polyfrost.oneconfig.api.ui.v1.keybind.KeybindManager import org.polyfrost.polyui.color.rgba -import org.polyfrost.polyui.input.KeyBinder +import org.polyfrost.polyui.input.KeybindHelper -object ChattingConfig : Config( - "chatting.json", - "/chatting_dark.svg", - Category.QOL, -) { +object ModConfig : Config("${ModConstants.ID}.json", ModConstants.NAME, Category.OTHER) { @Dropdown( title = "Text Render Type", category = "General", options = ["No Shadow", "Shadow", "Full Shadow"], @@ -29,6 +16,12 @@ object ChattingConfig : Config( ) var textRenderType = 1 + @Color( + title = "Chat Background Color", category = "General", + description = "The color of the chat background." + ) + var chatBackgroundColor = rgba(0, 0, 0, 0.5f) + @Color( title = "Hover Message Background Color", category = "General", description = "The color of the chat background when hovering over a message." @@ -48,7 +41,7 @@ object ChattingConfig : Config( @Switch( title = "Inform Outdated Mods", category = "General", - description = "Inform the user when a mod can be replaced by Chatting.", + description = "Inform the user when a mod can be replaced by Chatting." ) var informForAlternatives = true @@ -66,27 +59,19 @@ object ChattingConfig : Config( @Keybind( title = "Peek KeyBind" ) - var chatPeekBind = KeyBinder.Bind('z') { - if (chatPeek) { - if (peekMode == 0 /* HOLD */) { - Chatting.peeking = it - } else { - Chatting.peeking = !Chatting.peeking - } - if (!Chatting.peeking) mc.ingameGUI.chatGUI.resetScroll() - } - false - } + var chatPeekBind = KeybindHelper.builder().keys(OmniKeyboard.KEY_Z).does { + }.build() - @RadioButton( - title = "Peek Mode", - options = ["Held", "Toggle"], - ) - var peekMode = 0 +// @DualOption( +// title = "Peek Mode", +// left = "Held", +// right = "Toggle" +// ) + var peekMode = false @Switch( title = "Underlined Links", category = "General", - description = "Makes clickable links in chat blue and underlined.", + description = "Makes clickable links in chat blue and underlined." ) var underlinedLinks = false @@ -105,6 +90,13 @@ object ChattingConfig : Config( ) var messageSpeed = 0.5f + @Switch( + title = "Disable for Edits", + category = "Animations", subcategory = "Messages", + description = "Disable smooth animations for edited messages." + ) + var disableSmoothEdits = true + @Switch( title = "Smooth Chat Background", category = "Animations", subcategory = "Background", @@ -240,32 +232,19 @@ object ChattingConfig : Config( ) var hideChatHeadOnConsecutiveMessages = true - /*/ - @Property( - type = PropertyType.SWITCH, - title = "Show Timestamp", - description = "Show message timestamp.", - category = "General" + @Info( + title = "If Chatting detects a public chat message that seems like spam, and the probability is higher than this, it will hide it.", + category = "Player Chats", + description = "" ) - var showTimestamp = false + var ignored = false - @Property( - type = PropertyType.SWITCH, - title = "Timestamp Only On Hover", - description = "Show timestamp only on mouse hover.", - category = "General" + @Info( + title = "Made for Hypixel Skyblock. Set to 100% to disable. 95% is a reasonable threshold to use it at. May not be accurate.", + category = "Player Chats", + description = "" ) - var showTimestampHover = true - - */ - -// @Info( TODO -// text = "If Chatting detects a public chat message that seems like spam, and the probability is higher than this, it will hide it.\n" + "Made for Hypixel Skyblock. Set to 100% to disable. 95% is a reasonable threshold to use it at.\n" + "Note that this is not and never will be 100% accurate; however, it's pretty much guaranteed to block most spam.", -// size = 2, -// category = "Player Chats", -// type = InfoType.INFO -// ) -// var ignored = false + var ignored1 = false @Slider( min = 80F, max = 100F, title = "Spam Blocker Threshold", category = "Player Chats" @@ -308,13 +287,13 @@ object ChattingConfig : Config( ) var hypixelOnlyChatTabs = true -// @Info( TODO -// category = "Tabs", -// type = InfoType.INFO, -// text = "You can use the SHIFT key to select multiple tabs, as well as CTRL + TAB to switch to the next tab.", -// size = 2 -// ) -// var ignored2 = true + @Info( + category = "Tabs", + title = "You can use the SHIFT key to select multiple tabs, as well as CTRL + TAB to switch to the next tab.", + description = "" + ) + @Transient + var ignored2 = true @Switch( title = "Chat Shortcuts", category = "Shortcuts" @@ -346,115 +325,4 @@ object ChattingConfig : Config( ) var tooltipTextRenderType = 1 - var isPatcherMigrated = false - var isPatcherMigratedPt2CauseImStupid = false - - init { - - try { - Class.forName("club.sk1er.patcher.config.OldPatcherConfig") - val chatWindow = Chatting.chatWindow - if (!isPatcherMigrated) { - if (OldPatcherConfig.transparentChat) { - - if (OldPatcherConfig.transparentChatOnlyWhenClosed) { - chatWindow.backgroundOpacity = 0f - chatWindow.useDifferentOpenOpacity = true - chatWindow.openOpacity = 0 - } else { - chatWindow.backgroundOpacity = 0f - } - } - if (OldPatcherConfig.transparentChatInputField) { - Chatting.chatInput.setBackground(false) - } - isPatcherMigrated = true - - save() - } - if (!isPatcherMigratedPt2CauseImStupid) { - if (OldPatcherConfig.transparentChat) { - if (OldPatcherConfig.transparentChatOnlyWhenClosed && chatWindow.openOpacity == 255) { - chatWindow.openOpacity = 0 - } - } - - isPatcherMigratedPt2CauseImStupid = true - - save() - } - } catch (_: ClassNotFoundException) { - } - - addDependency("rightClickCopyCtrl", "rightClickCopy") - addDependency("fadeTime", "fade") - addDependency("offsetNonPlayerMessages", "showChatHeads") - addDependency("hideChatHeadOnConsecutiveMessages", "showChatHeads") - addDependency("hypixelOnlyChatTabs", "chatTabs") - addDependency("hypixelOnlyChatShortcuts", "chatShortcuts") - addDependency("scrollingSpeed", "smoothScrolling") - addDependency("messageSpeed", "smoothChat") - addDependency("bgDuration", "smoothBG") - addDependency("peekScrolling", "chatPeek") - addDependency("chatPeekBind", "chatPeek") - addDependency("peekMode", "chatPeek") - addDependency("smoothChat", "BetterChat Smooth Chat") { - if (!ModCompatHooks.betterChatSmoothMessages) Property.Display.HIDDEN else Property.Display.SHOWN - } - addCallback("peekMode") { - Chatting.peeking = false - } - addCallback("hideChatHeadOnConsecutiveMessages") { - ChatLineHook.`chatting$chatLines`.map { it.get() as ChatLineHook? }.forEach { it?.`chatting$updatePlayerInfo`() } - } - addCallback("chatTabs") { - ChatTabs.initialize() - if (!chatTabs) { - val dummy = ChatTab( - true, - "ALL", - unformatted = false, - lowercase = false, - startsWith = null, - contains = null, - endsWith = null, - equals = null, - uncompiledRegex = null, - ignoreStartsWith = null, - ignoreContains = null, - ignoreEndsWith = null, - ignoreEquals = null, - uncompiledIgnoreRegex = null, - color = TabButton.color, - hoveredColor = TabButton.hoveredColor, - selectedColor = TabButton.selectedColor, - prefix = "" - ) - dummy.initialize() - ChatTabs.currentTabs.clear() - ChatTabs.currentTabs.add(dummy) - } else { - ChatTabs.currentTabs.clear() - ChatTabs.currentTabs.add(ChatTabs.tabs[0]) - } - } - addCallback("chatShortcuts") { - ChatShortcuts.initialize() - } - listOf( - "chatSearch", - "chatScreenshot", - "chatDeleteHistory", - "chatTabs" - ).forEach { - addCallback(it) { - mc.currentScreen?.let { screen -> - if (screen is GuiChatHook) { - screen.`chatting$triggerButtonReset`() - } - } - } - } - // addDependency("showTimestampHover", "showTimestamp") - } } diff --git a/src/main/kotlin/org/polyfrost/chatting/ModConstants.kt b/src/main/kotlin/org/polyfrost/chatting/ModConstants.kt new file mode 100644 index 0000000..4a39335 --- /dev/null +++ b/src/main/kotlin/org/polyfrost/chatting/ModConstants.kt @@ -0,0 +1,10 @@ +package org.polyfrost.chatting + +object ModConstants { + + // Sets the variables from `gradle.properties`. Depends on the `bloom` DGT plugin. + const val ID = "@MOD_ID@" + const val NAME = "@MOD_NAME@" + const val VERSION = "@MOD_VERSION@" + +} diff --git a/src/main/kotlin/org/polyfrost/chatting/chat/ChatHooks.kt b/src/main/kotlin/org/polyfrost/chatting/chat/ChatHooks.kt deleted file mode 100644 index 67081b1..0000000 --- a/src/main/kotlin/org/polyfrost/chatting/chat/ChatHooks.kt +++ /dev/null @@ -1,35 +0,0 @@ -package org.polyfrost.chatting.chat - -import net.minecraft.client.gui.GuiTextField - -object ChatHooks { - var draft = "" - - var commandDraft = "" - - var inputBoxRight = 0 - - var inputRight = 0 - - var textField: GuiTextField? = null - - fun resetDraft() { - draft = "" - commandDraft = "" - } - - fun checkField(field: Any): Boolean { - return field == textField - } - - fun switchTab() { - val current = ChatTabs.currentTabs.firstOrNull() - if (current == null) { - ChatTabs.currentTabs.add(ChatTabs.tabs[0]) - } else { - val nextIndex = (ChatTabs.tabs.indexOf(current) + 1) % ChatTabs.tabs.size - ChatTabs.currentTabs.clear() - ChatTabs.currentTabs.add(ChatTabs.tabs[nextIndex]) - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/chatting/chat/ChatInputBox.kt b/src/main/kotlin/org/polyfrost/chatting/chat/ChatInputBox.kt deleted file mode 100644 index 64cedf8..0000000 --- a/src/main/kotlin/org/polyfrost/chatting/chat/ChatInputBox.kt +++ /dev/null @@ -1,51 +0,0 @@ -package org.polyfrost.chatting.chat - -import dev.deftu.omnicore.client.render.OmniMatrixStack -import org.polyfrost.oneconfig.api.config.v1.annotations.Switch -import org.polyfrost.oneconfig.api.hud.v1.LegacyHud - -class ChatInputBox : LegacyHud() { - - @Switch( - title = "Compact Input Box", - description = "Make the chat input box the same width as the chat box." - ) - var compactInputBox = false - - @Switch( - title = "Input Field Draft", - description = "Drafts the text you wrote in the input field after closing the chat and backs it up when opening the chat again." - ) - var inputFieldDraft = false - - fun drawBG() { -// if (!ModCompatHooks.shouldDrawInputBox) return -// GlStateManager.enableAlpha() -// GlStateManager.enableBlend() -// val scale = OmniResolution.scaleFactor.toFloat() -// drawBackground(2f, OmniResolution.scaledHeight - 14f + (if (OmniResolution.viewportHeight % 2 == 1) scale - 1 else 0f) / scale, inputBoxRight - 2f, 12f, 1f) -// GlStateManager.disableBlend() -// GlStateManager.disableAlpha() - } - - fun setBackground(boolean: Boolean) { -// background = boolean - } - - override var height: Float - get() = 20f - set(value) {} - override var width: Float - get() = 100f - set(value) {} - - override fun category() = Category.INFO - - override fun render(stack: OmniMatrixStack, x: Float, y: Float, scaleX: Float, scaleY: Float) { - - } - - override fun title() = "Chat Input Box" - - override fun update() = false -} \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/chatting/chat/ChatRegexes.kt b/src/main/kotlin/org/polyfrost/chatting/chat/ChatRegexes.kt deleted file mode 100644 index 0d6909e..0000000 --- a/src/main/kotlin/org/polyfrost/chatting/chat/ChatRegexes.kt +++ /dev/null @@ -1,11 +0,0 @@ -package org.polyfrost.chatting.chat - -data class ChatRegexes(val regexList: List?) { - val compiledRegexList: MutableList = arrayListOf() - - init { - regexList?.forEach { - compiledRegexList.add(Regex(it)) - } - } -} diff --git a/src/main/kotlin/org/polyfrost/chatting/chat/ChatScrollingHook.kt b/src/main/kotlin/org/polyfrost/chatting/chat/ChatScrollingHook.kt deleted file mode 100644 index 982329a..0000000 --- a/src/main/kotlin/org/polyfrost/chatting/chat/ChatScrollingHook.kt +++ /dev/null @@ -1,5 +0,0 @@ -package org.polyfrost.chatting.chat - -object ChatScrollingHook { - var shouldSmooth = false -} \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/chatting/chat/ChatSearchingManager.kt b/src/main/kotlin/org/polyfrost/chatting/chat/ChatSearchingManager.kt deleted file mode 100644 index 6cdb280..0000000 --- a/src/main/kotlin/org/polyfrost/chatting/chat/ChatSearchingManager.kt +++ /dev/null @@ -1,69 +0,0 @@ -package org.polyfrost.chatting.chat - -import com.github.benmanes.caffeine.cache.Cache -import com.github.benmanes.caffeine.cache.Caffeine -import dev.deftu.textile.minecraft.MCTextFormat -import net.minecraft.client.gui.ChatLine -import net.minecraft.util.ChatComponentText -import org.polyfrost.chatting.chat.ChatTabs.currentTabs -import org.polyfrost.chatting.hook.ChatHook -import java.util.concurrent.LinkedBlockingQueue -import java.util.concurrent.ThreadPoolExecutor -import java.util.concurrent.TimeUnit -import java.util.concurrent.atomic.AtomicInteger - -object ChatSearchingManager { - private var counter: AtomicInteger = AtomicInteger(0) - private var POOL: ThreadPoolExecutor = ThreadPoolExecutor( - 50, 50, - 0L, TimeUnit.SECONDS, - LinkedBlockingQueue() - ) { r -> - Thread( - r, - "Chat Filter Cache Thread ${counter.incrementAndGet()}" - ) - } - - @JvmStatic - val cache: Cache> = Caffeine.newBuilder().executor(POOL).maximumSize(5000).build() - - var lastSearch = "" - - @JvmStatic - fun filterMessages(text: String, list: List): List? { - val chatTabMessages = filterChatTabMessages(lastSearch) - if (chatTabMessages != null) { - return chatTabMessages - } - return filterMessages2(text, list) - } - - @JvmStatic - fun filterMessages2(text: String, list: List): List? { - if (text.isBlank()) return list - val cached = cache.getIfPresent(text) - return cached ?: run { - cache.put(text, list.filter { - MCTextFormat.stripFormat(it.chatComponent.unformattedText).lowercase() - .contains(text.lowercase()) - }) - cache.getIfPresent(text) - } - } - - @JvmStatic - fun filterChatTabMessages(text: String): List? { - val currentTabs = currentTabs.firstOrNull() - if (currentTabs?.messages?.isEmpty() == false) { - val list: MutableList = ArrayList() - for (message in currentTabs.messages?: emptyList()) { - ChatHook.lineVisible = true - list.add(ChatLine(0, ChatComponentText(message), 0)) - ChatHook.lineVisible = false - } - return filterMessages2(text, list) - } - return null - } -} \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/chatting/chat/ChatShortcuts.kt b/src/main/kotlin/org/polyfrost/chatting/chat/ChatShortcuts.kt deleted file mode 100644 index 273add7..0000000 --- a/src/main/kotlin/org/polyfrost/chatting/chat/ChatShortcuts.kt +++ /dev/null @@ -1,79 +0,0 @@ -package org.polyfrost.chatting.chat - -import org.polyfrost.chatting.Chatting -import com.google.gson.JsonObject -import com.google.gson.JsonParser -import org.polyfrost.oneconfig.api.config.v1.ConfigManager -import kotlin.io.path.* - -object ChatShortcuts { - private val oldShortcutsFile = Chatting.oldModDir.resolve("chatshortcuts.json") - private val shortcutsFile = ConfigManager.active().folder.resolve("chatshortcuts.json") - private val PARSER = JsonParser() - - private var initialized = false - - val shortcuts = object : ArrayList>() { - private val comparator = Comparator> { o1, o2 -> - return@Comparator o2.first.length.compareTo(o1.first.length) - } - - override fun add(element: Pair): Boolean { - val value = super.add(element) - sortWith(comparator) - return value - } - } - - fun initialize() { - if (initialized) { - return - } else { - initialized = true - } - if (shortcutsFile.exists()) { - try { - val jsonObj = PARSER.parse(shortcutsFile.readText()).asJsonObject - for (shortcut in jsonObj.entrySet()) { - shortcuts.add(shortcut.key to shortcut.value.asString) - } - return - } catch (_: Throwable) { - shortcutsFile.moveTo(shortcutsFile.parent.resolve("chatshortcuts.json.bak")) - } - } - shortcutsFile.createFile() - if (oldShortcutsFile.exists()) { - shortcutsFile.writeText( - oldShortcutsFile.readText() - ) - } else { - shortcutsFile.writeText(JsonObject().toString()) - } - } - - fun removeShortcut(key: String) { - shortcuts.removeIf { it.first == key } - val jsonObj = PARSER.parse(shortcutsFile.readText()).asJsonObject - jsonObj.remove(key) - shortcutsFile.writeText(jsonObj.toString()) - } - - fun writeShortcut(key: String, value: String) { - shortcuts.add(key to value) - val jsonObj = PARSER.parse(shortcutsFile.readText()).asJsonObject - jsonObj.addProperty(key, value) - shortcutsFile.writeText(jsonObj.toString()) - } - - fun handleSentCommand(command: String): String { - shortcuts.forEach { - if (command == it.first || (command.startsWith(it.first) && command.substringAfter(it.first) - .startsWith(" ")) - ) { - return command.replaceFirst(it.first, it.second) - } - } - return command - } -} \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/chatting/chat/ChatTab.kt b/src/main/kotlin/org/polyfrost/chatting/chat/ChatTab.kt deleted file mode 100644 index c71a35b..0000000 --- a/src/main/kotlin/org/polyfrost/chatting/chat/ChatTab.kt +++ /dev/null @@ -1,114 +0,0 @@ -package org.polyfrost.chatting.chat - -import com.google.gson.annotations.SerializedName -import net.minecraft.util.EnumChatFormatting -import net.minecraft.util.IChatComponent -import org.polyfrost.chatting.gui.components.TabButton -import org.polyfrost.oneconfig.utils.v1.dsl.mc -import java.util.Locale - -data class ChatTab( - val enabled: Boolean, - val name: String, - val unformatted: Boolean, - val lowercase: Boolean?, - @SerializedName("starts") val startsWith: List?, - val contains: List?, - @SerializedName("ends") val endsWith: List?, - val equals: List?, - @SerializedName("regex") val uncompiledRegex: List?, - @SerializedName("ignore_starts") val ignoreStartsWith: List?, - @SerializedName("ignore_contains") val ignoreContains: List?, - @SerializedName("ignore_ends") val ignoreEndsWith: List?, - @SerializedName("ignore_equals") val ignoreEquals: List?, - @SerializedName("ignore_regex") val uncompiledIgnoreRegex: List?, - val color: Int?, - @SerializedName("hovered_color") val hoveredColor: Int?, - @SerializedName("selected_color") val selectedColor: Int?, - val prefix: String? -) { - lateinit var button: TabButton - lateinit var compiledRegex: ChatRegexes - lateinit var compiledIgnoreRegex: ChatRegexes - @Transient - var messages: List? = ArrayList() - - //Ugly hack to make GSON not make button / regex null - fun initialize() { - compiledRegex = ChatRegexes(uncompiledRegex) - compiledIgnoreRegex = ChatRegexes(uncompiledIgnoreRegex) - val width = mc.fontRendererObj.getStringWidth(name) - button = TabButton(653452, run { - val returnValue = x - 2 - x += 6 + width - return@run returnValue - }, width + 4, 12, this) - } - - fun shouldRender(chatComponent: IChatComponent): Boolean { - val message = - (if (unformatted) EnumChatFormatting.getTextWithoutFormattingCodes(chatComponent.unformattedText) else chatComponent.formattedText).let { - if (lowercase == true) it.lowercase( - Locale.ENGLISH - ) else it - } - ignoreStartsWith?.forEach { - if (message.startsWith(it)) { - return false - } - } - ignoreEquals?.forEach { - if (message == it) { - return false - } - } - ignoreEndsWith?.forEach { - if (message.endsWith(it)) { - return false - } - } - ignoreContains?.forEach { - if (message.contains(it)) { - return false - } - } - compiledIgnoreRegex.compiledRegexList.forEach { - if (it.matches(message)) { - return false - } - } - if (startsWith.isNullOrEmpty() && equals.isNullOrEmpty() && endsWith.isNullOrEmpty() && contains.isNullOrEmpty() && uncompiledRegex.isNullOrEmpty()) { - return true - } - equals?.forEach { - if (message == it) { - return true - } - } - startsWith?.forEach { - if (message.startsWith(it)) { - return true - } - } - endsWith?.forEach { - if (message.endsWith(it)) { - return true - } - } - contains?.forEach { - if (message.contains(it)) { - return true - } - } - compiledRegex.compiledRegexList.forEach { - if (it.matches(message)) { - return true - } - } - return false - } - - companion object { - private var x = 4 - } -} diff --git a/src/main/kotlin/org/polyfrost/chatting/chat/ChatTabs.kt b/src/main/kotlin/org/polyfrost/chatting/chat/ChatTabs.kt deleted file mode 100644 index bf06637..0000000 --- a/src/main/kotlin/org/polyfrost/chatting/chat/ChatTabs.kt +++ /dev/null @@ -1,354 +0,0 @@ -package org.polyfrost.chatting.chat - -import com.google.gson.* -import net.minecraft.util.IChatComponent -import org.polyfrost.chatting.Chatting -import org.polyfrost.chatting.gui.components.TabButton -import org.polyfrost.oneconfig.api.config.v1.ConfigManager -import org.polyfrost.oneconfig.utils.v1.dsl.mc -import kotlin.io.path.* - -object ChatTabs { - private val GSON = GsonBuilder().setPrettyPrinting().create() - private val PARSER = JsonParser() - val tabs = arrayListOf() - var currentTabs: ArrayList = object : ArrayList() { - override fun add(element: ChatTab): Boolean { - val returnValue = super.add(element) - if (mc.theWorld != null && returnValue) { - mc.ingameGUI.chatGUI.refreshChat() - } - return returnValue - } - } - var hasCancelledAnimation = false - private var initialized = false - - private val tabFile = ConfigManager.active().folder.resolve("chattabs.json") - private val oldTabFile = Chatting.oldModDir.resolve("chattabs.json") - - fun initialize() { - if (initialized) { - return - } else { - initialized = true - } - if (!tabFile.exists()) { - if (oldTabFile.exists()) { - oldTabFile.moveTo(tabFile) - handleFile() - } else { - generateNewFile() - } - } else { - handleFile() - } - tabs.forEach { - it.initialize() - } - currentTabs.clear() - currentTabs.add(tabs[0]) - } - - private fun handleFile() { - try { - val chatTabJson = GSON.fromJson(tabFile.readText(), ChatTabsJson::class.java) - when (chatTabJson.version) { - 1 -> { - // ver 2 adds `enabled` - chatTabJson.tabs.forEach { - applyVersion2Changes(it.asJsonObject) - applyVersion3Changes(it.asJsonObject) - applyVersion4Changes(it.asJsonObject) - applyVersion5Changes(it.asJsonObject) - applyVersion6Changes(it.asJsonObject) - } - chatTabJson.version = ChatTabsJson.VERSION - tabFile.writeText(GSON.toJson(chatTabJson)) - } - - 2 -> { - // ver 3 adds ignore_ - chatTabJson.tabs.forEach { - applyVersion3Changes(it.asJsonObject) - applyVersion4Changes(it.asJsonObject) - applyVersion5Changes(it.asJsonObject) - applyVersion6Changes(it.asJsonObject) - } - chatTabJson.version = ChatTabsJson.VERSION - tabFile.writeText(GSON.toJson(chatTabJson)) - } - - 3 -> { - // ver 4 adds color options - chatTabJson.tabs.forEach { - applyVersion4Changes(it.asJsonObject) - applyVersion5Changes(it.asJsonObject) - applyVersion6Changes(it.asJsonObject) - } - chatTabJson.version = ChatTabsJson.VERSION - tabFile.writeText(GSON.toJson(chatTabJson)) - } - - 4 -> { - // ver 5 adds lowercase - chatTabJson.tabs.forEach { - applyVersion5Changes(it.asJsonObject) - applyVersion6Changes(it.asJsonObject) - } - chatTabJson.version = ChatTabsJson.VERSION - tabFile.writeText(GSON.toJson(chatTabJson)) - } - - 5 -> { - // ver 6 changes pm regex - chatTabJson.tabs.forEach { - applyVersion6Changes(it.asJsonObject) - } - chatTabJson.version = ChatTabsJson.VERSION - tabFile.writeText(GSON.toJson(chatTabJson)) - } - } - chatTabJson.tabs.forEach { - val chatTab = GSON.fromJson(it.toString(), ChatTab::class.java) - if (chatTab.enabled) { - tabs.add(chatTab) - } - } - } catch (e: Throwable) { - e.printStackTrace() - tabFile.deleteIfExists() - generateNewFile() - } - } - - private fun applyVersion2Changes(json: JsonObject) { - json.addProperty("enabled", true) - } - - private fun applyVersion3Changes(json: JsonObject) { - json.add("ignore_starts", JsonArray()) - json.add("ignore_contains", JsonArray()) - json.add("ignore_ends", JsonArray()) - json.add("ignore_equals", JsonArray()) - json.add("ignore_regex", JsonArray()) - } - - private fun applyVersion4Changes(json: JsonObject) { - json.addProperty("color", TabButton.color) - json.addProperty("hovered_color", TabButton.hoveredColor) - json.addProperty("selected_color", TabButton.selectedColor) - } - - private fun applyVersion5Changes(json: JsonObject) { - json.addProperty("lowercase", false) - } - - private fun applyVersion6Changes(json: JsonObject) { - if (json.has("starts")) { - val starts = json["starts"].asJsonArray - var detected = false - starts.iterator().let { - while (it.hasNext()) { - when (it.next().asString) { - "To " -> { - detected = true - it.remove() - } - - "From " -> { - detected = true - it.remove() - } - } - } - } - if (detected) { - json.add("regex", JsonArray().apply { - add(JsonPrimitive("^(?§dTo|§dFrom) (?.+): §r(?.*)(?:§r)?\$")) - }) - json.remove("unformatted") - json.addProperty("unformatted", false) - } - } - if (json.has("ends")) { - val ends = json["ends"].asJsonArray - var detected = false - ends.iterator().let { - while (it.hasNext()) { - when (it.next().asString) { - "§r§ehas invited you to join their party!" -> { - detected = true - it.remove() - } - } - } - } - if (detected) { - json.add("contains", JsonArray().apply { - add(JsonPrimitive("§r§ehas invited you to join their party!")) - }) - } - } - } - - fun shouldRender(message: IChatComponent): Boolean { - if (currentTabs.isEmpty()) return true - for (tab in currentTabs) { - if (tab.shouldRender(message)) { - return true - } - } - return false - } - - private fun generateNewFile() { - tabFile.createFile() - val jsonObject = JsonObject() - val defaultTabs = generateDefaultTabs() - jsonObject.add("tabs", defaultTabs) - jsonObject.addProperty("version", ChatTabsJson.VERSION) - tabFile.writeText(GSON.toJson(jsonObject)) - } - - private fun generateDefaultTabs(): JsonArray { - val all = ChatTab( - true, - "ALL", - unformatted = false, - lowercase = false, - startsWith = null, - contains = null, - endsWith = null, - equals = null, - uncompiledRegex = null, - ignoreStartsWith = null, - ignoreContains = null, - ignoreEndsWith = null, - ignoreEquals = null, - uncompiledIgnoreRegex = null, - color = TabButton.color, - hoveredColor = TabButton.hoveredColor, - selectedColor = TabButton.selectedColor, - prefix = "" - ) - val party = ChatTab( - true, - "PARTY", - unformatted = false, - lowercase = false, - startsWith = listOf("§r§9Party §8> ", "§r§9P §8> ", "§eThe party was transferred to §r", "§eKicked §r"), - contains = listOf("§r§ehas invited you to join their party!"), - endsWith = listOf( - "§r§eto the party! They have §r§c60 §r§eseconds to accept.§r", - "§r§ehas disbanded the party!§r", - "§r§ehas disconnected, they have §r§c5 §r§eminutes to rejoin before they are removed from the party.§r", - " §r§ejoined the party.§r", - " §r§ehas left the party.§r", - " §r§ehas been removed from the party.§r", - "§r§e because they were offline.§r" - ), - equals = listOf("§cThe party was disbanded because all invites expired and the party was empty§r"), - uncompiledRegex = listOf( //regexes from https://github.com/kwevin/Hychat-Tabs/blob/main/tabs/re-add%20prefixes%20%26%20fix%20shortened%20tags/chat.json cause i cant write regex - "(§r)*(§9Party §8\u003e)+(.*)", - "(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+) §r§einvited §r(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+) §r§eto the party! They have §r§c60 §r§eseconds to accept\\.§r", - "(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+) §r§ehas left the party\\.§r", - "(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+) §r§ejoined the party\\.§r", - "§eYou left the party\\.§r", - "§eYou have joined §r(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+)\u0027s §r§eparty!§r", - "§cThe party was disbanded because all invites expired and the party was empty§r", - "§cYou cannot invite that player since they\u0027re not online\\.§r", - "§eThe party leader, §r(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+)§r§e, warped you to §r(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+)§r§e\u0027s house\\.§r", - "§eSkyBlock Party Warp §r§7\\([0-9]+ players?\\)§r", - "§a. §r(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+)§r§f §r§awarped to your server§r", - "§eYou summoned §r(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+)§r§f §r§eto your server\\.§r", - "§eThe party leader, §r(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+)§r§e, warped you to their house\\.§r", - "(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+) §r§aenabled Private Game§r", - "(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+) §r§cdisabled Private Game§r", - "§cThe party is now muted\\. §r", - "§aThe party is no longer muted\\.§r", - "§cThere are no offline players to remove\\.§r", - "(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+) §r§ehas been removed from the party\\.§r", - "§eThe party was transferred to §r(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+) §r§eby §r(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+)§r", - "(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+)§r§e has promoted §r(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+) §r§eto Party Leader§r", - "(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+)§r§e has promoted §r(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+) §r§eto Party Moderator§r", - "(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+) §r§eis now a Party Moderator§r", - "(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+)§r§e has demoted §r(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+) §r§eto Party Member§r", - "§cYou can\u0027t demote yourself!§r", - "§6Party Members \\([0-9]+\\)§r", - "§eParty Leader: §r(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+) ?§r(?:§[a-zA-Z0-9]).§r", - "§eParty Members: §r(?:(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+)§r(?:§[a-zA-Z0-9]) . §r)+", - "§eParty Moderators: §r(?:(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+)§r(?:§[a-zA-Z0-9]) . §r)+", - "§eThe party invite to §r(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+) §r§ehas expired§r", - "(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+) §r§cdisabled All Invite§r", - "(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+) §r§aenabled All Invite§r", - "§cYou cannot invite that player\\.§r", - "§cYou are not allowed to invite players\\.§r", - "§eThe party leader, §r(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+) §r§ehas disconnected, they have §r§c5 §r§eminutes to rejoin before the party is disbanded\\.§r", - "(?:(?:§[a-zA-Z0-9])*\\[(?:(?:VIP)|(?:VIP§r§6\\+)|(?:MVP)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+)|(?:MVP(?:§r)?(?:§[a-zA-Z0-9])\\+\\+)|(?:(?:§r)?§fYOUTUBE))(?:§r)?(?:(?:§[a-zA-Z0-9]))?\\] [a-zA-Z0-9_]+|§7[a-zA-Z0-9_]+) §r§ehas disconnected, they have §r§c5 §r§eminutes to rejoin before they are removed from the party.§r", - "§cYou are not in a party right now\\.§r", - "§cThis party is currently muted\\.§r", - "(§r)*(§9P §8\u003e)+(.*)" - ), - ignoreStartsWith = null, - ignoreContains = null, - ignoreEndsWith = null, - ignoreEquals = null, - uncompiledIgnoreRegex = null, - color = TabButton.color, - hoveredColor = TabButton.hoveredColor, - selectedColor = TabButton.selectedColor, - prefix = "/pc " - ) - val guild = ChatTab( - true, - "GUILD", - unformatted = true, - lowercase = false, - startsWith = listOf("Guild >", "G >"), - contains = null, - endsWith = null, - equals = null, - uncompiledRegex = null, - ignoreStartsWith = null, - ignoreContains = null, - ignoreEndsWith = null, - ignoreEquals = null, - uncompiledIgnoreRegex = null, - color = TabButton.color, - hoveredColor = TabButton.hoveredColor, - selectedColor = TabButton.selectedColor, - prefix = "/gc " - ) - val pm = ChatTab( - true, - "PM", - unformatted = false, - lowercase = false, - startsWith = null, - contains = null, - endsWith = null, - equals = null, - uncompiledRegex = listOf("^(?§dTo|§dFrom) (?.+): §r(?.*)(?:§r)?\$"), - ignoreStartsWith = null, - ignoreContains = null, - ignoreEndsWith = null, - ignoreEquals = null, - uncompiledIgnoreRegex = null, - color = TabButton.color, - hoveredColor = TabButton.hoveredColor, - selectedColor = TabButton.selectedColor, - prefix = "/r " - ) - tabs.add(all) - tabs.add(party) - tabs.add(guild) - tabs.add(pm) - val jsonArray = JsonArray() - jsonArray.add(PARSER.parse(GSON.toJson(all)).asJsonObject) - jsonArray.add(PARSER.parse(GSON.toJson(party)).asJsonObject) - jsonArray.add(PARSER.parse(GSON.toJson(guild)).asJsonObject) - jsonArray.add(PARSER.parse(GSON.toJson(pm)).asJsonObject) - return jsonArray - } -} diff --git a/src/main/kotlin/org/polyfrost/chatting/chat/ChatTabsJson.kt b/src/main/kotlin/org/polyfrost/chatting/chat/ChatTabsJson.kt deleted file mode 100644 index c5939c3..0000000 --- a/src/main/kotlin/org/polyfrost/chatting/chat/ChatTabsJson.kt +++ /dev/null @@ -1,15 +0,0 @@ -package org.polyfrost.chatting.chat - -import com.google.gson.JsonArray -import com.google.gson.annotations.SerializedName - -data class ChatTabsJson(@SerializedName("tabs") val tabs: JsonArray, var version: Int) { - - override fun toString(): String { - return "{\"tabs\": $tabs, \"version\": $version}" - } - - companion object { - const val VERSION = 6 - } -} \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/chatting/chat/ChatWindow.kt b/src/main/kotlin/org/polyfrost/chatting/chat/ChatWindow.kt deleted file mode 100644 index c21dcd2..0000000 --- a/src/main/kotlin/org/polyfrost/chatting/chat/ChatWindow.kt +++ /dev/null @@ -1,217 +0,0 @@ -package org.polyfrost.chatting.chat - -import club.sk1er.patcher.config.PatcherConfig -import net.minecraft.client.gui.ChatLine -import net.minecraft.client.gui.GuiNewChat -import net.minecraft.util.ChatComponentText -import org.polyfrost.chatting.Chatting -import org.polyfrost.chatting.config.ChattingConfig -import org.polyfrost.chatting.utils.ModCompatHooks -import org.polyfrost.oneconfig.api.config.v1.annotations.Button -import org.polyfrost.oneconfig.api.config.v1.annotations.Slider -import org.polyfrost.oneconfig.api.config.v1.annotations.Switch -import org.polyfrost.oneconfig.api.hud.v1.Hud -import org.polyfrost.oneconfig.utils.v1.dsl.mc -import org.polyfrost.polyui.color.mutable -import org.polyfrost.polyui.color.rgba -import org.polyfrost.polyui.component.impl.Block -import org.polyfrost.polyui.unit.Vec2 -import org.polyfrost.polyui.unit.Vec4 -import net.minecraft.client.renderer.GlStateManager as GL - -class ChatWindow : Hud() { - - override fun defaultPosition() = Vec2(2f, 1080f - 27f - 45f - 12f) - - override fun hasBackground() = false - - private val exampleList: List = listOf( - ChatLine(0, ChatComponentText("§bChatting"), 0), - ChatLine(0, ChatComponentText(""), 0), - ChatLine(0, ChatComponentText("§aThis is a movable chat"), 0), - ChatLine(0, ChatComponentText("§eDrag me around!"), 0), - ChatLine(0, ChatComponentText("Click to drag"), 0) - ) - - var isGuiIngame = false - - var wasInChatGui = false - - var normalScale = 1f - var lastChatGuiScale = -1f - var transferOverScale = false - - @Switch( - title = "Custom Chat Height", - description = "Set a custom height for the chat window. Allows for more customization than the vanilla chat height options." - ) - var customChatHeight = false - - @Slider( - min = 20F, max = 2160F, title = "Focused Height (px)", - description = "The height of the chat window when focused." - ) - var focusedHeight = 180 - - @Slider( - min = 20F, max = 2160F, title = "Unfocused Height (px)", - description = "The height of the chat window when unfocused." - ) - var unfocusedHeight = 90 - - @Switch( - title = "Custom Chat Width", - description = "Set a custom width for the chat window. Allows for more customization than the vanilla chat width options." - ) - var customChatWidth = false - - @Slider( - min = 20F, max = 2160F, title = "Custom Width (px)", - description = "The width of the chat window when focused." - ) - var customWidth = 320 - - @Switch( - title = "Different Opacity When Open", - description = "Change the opacity of the chat window when it is open." - ) - var useDifferentOpenOpacity = false - - @Slider( - min = 0F, max = 255F, title = "Open Background Opacity", - description = "The opacity of the chat window when it is open." - ) - var openOpacity = 120 - - @Slider( - min = 0F, max = 255F, title = "Open Border Opacity", - description = "The opacity of the chat window border when it is open." - ) - var openBorderOpacity = 255 - - @Button( - title = "Revert to Vanilla Chat Window", - description = "Revert the chat window to the vanilla chat window, instead of the Chattings custom chat window.", - text = "Revert" - ) - private fun revertToVanilla() { - if (isReal) { - get().padding = Vec4.ZERO - get().radii = floatArrayOf(0f) - } - ChattingConfig.smoothBG = false - } - - @Button( - title = "Revert to Chatting Chat Window", - description = "Revert the chat window to the Chatting custom chat window, instead of the vanilla chat window.", - text = "Revert" - ) - private fun revertToChatting() { - if (isReal) { - get().padding = Vec4.of(5f, 5f, 5f, 5f) - get().radii = floatArrayOf(5f) - } - ChattingConfig.smoothBG = true - } - - fun renderExample(x: Float, y: Float, scaleX: Float, scaleY: Float) { - if (!isReal) return - GL.pushMatrix() - GL.translate(x, y + scaleY, 0f) - GL.scale(scaleX, scaleY, 1f) - for (chat in exampleList) { - ModCompatHooks.redirectDrawString(chat.chatComponent.formattedText, 0f, 0f, -1, chat) - GL.translate(0f, 9f, 0f) - } - GL.popMatrix() - } - - fun drawBackground(x: Float, y: Float, width: Float, height: Float, scale: Float) { - if (Chatting.isPatcher && PatcherConfig.transparentChat) return -// val animatingOpacity = wasInChatGui && (ChattingConfig.smoothBG && (previousAnimationWidth != width || previousAnimationHeight != height)) -// wasInChatGui = mc.currentScreen is GuiChat || animatingOpacity -// previousAnimationWidth = width -// previousAnimationHeight = height -// val bgOpacity = openOpacity -// val borderOpacity = openBorderOpacity -// val tempBgAlpha = bgColor.alpha -// val tempBorderAlpha = borderColor.alpha -// bgColor.alpha = if (useDifferentOpenOpacity && wasInChatGui) bgOpacity else bgColor.alpha -// borderColor.alpha = if (useDifferentOpenOpacity && wasInChatGui) borderOpacity else borderColor.alpha -// super.drawBackground(x, y, width, height, scale) -// bgColor.alpha = tempBgAlpha -// borderColor.alpha = tempBorderAlpha - } - - fun drawBG() { -// animationWidth = widthAnimation.get() -// animationHeight = heightAnimation.get() -// width = position.width + (if (mc.ingameGUI.chatGUI.chatOpen && !Chatting.peeking && ChattingConfig.extendBG) ModCompatHooks.chatButtonOffset else 0) * scale -// val heightEnd = if (height == 0) 0f else (height + paddingY * 2f) * scale -// val duration = ChattingConfig.bgDuration -// GL.enableAlpha() -// GL.enableBlend() -// if (width != widthAnimation.end) { -// if (ChattingConfig.smoothBG) { -// widthAnimation = EaseOutQuart(duration, animationWidth, width, false) -// } else { -// animationWidth = width -// } -// } -// if (heightEnd != heightAnimation.end) { -// if (ChattingConfig.smoothBG) { -// heightAnimation = EaseOutQuart(duration, animationHeight, heightEnd, false) -// } else { -// animationHeight = heightEnd -// } -// } -// if (animationHeight <= 0.3f || !background || HudCore.editing) return -// nanoVG(true) { -// val scale = UResolution.scaleFactor.toFloat() -// drawBackground(position.x, position.bottomY - animationHeight + (if (UResolution.windowHeight % 2 == 1) scale - 1 else 0f) / scale, animationWidth, animationHeight, this@ChatWindow.scale) -// } -// GL.disableAlpha() - } - - fun canShow(): Boolean { - return true -// showInChat = true -// return isEnabled && (shouldShow() || Platform.getGuiPlatform().isInChat) && (isGuiIngame xor isCachingIgnored) - } - - override fun category() = Category.INFO - - override fun create() = object : Block(color = rgba(0, 0, 0, 120f / 255f).mutable()) { - override var width: Float - get() = ((if (customChatWidth) Chatting.getChatWidth() else GuiNewChat.calculateChatboxWidth(mc.gameSettings.chatWidth)) + 4 + ModCompatHooks.chatHeadOffset) * get().scaleX - set(value) {} - override var height: Float - get() = 9f * 5f * get().scaleY - set(value) {} - - override fun render() { - super.render() - if(!isReal) renderExample(x, y, scaleX, scaleY) - } - } - - var backgroundOpacity: Float - get() = get().color.alpha - set(value) { - get().color = get().color.mutable().also { it.alpha = value } - } - - fun updateMCChatScale() { - if (lastChatGuiScale != mc.gameSettings.chatScale) { - lastChatGuiScale = mc.gameSettings.chatScale -// scale = normalScale * mc.gameSettings.chatScale - } - } - - override fun multipleInstancesAllowed() = false - override fun title() = "Chat Window" - - override fun update() = false - -} \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/chatting/gui/components/CleanButton.kt b/src/main/kotlin/org/polyfrost/chatting/gui/components/CleanButton.kt deleted file mode 100644 index d764ce0..0000000 --- a/src/main/kotlin/org/polyfrost/chatting/gui/components/CleanButton.kt +++ /dev/null @@ -1,110 +0,0 @@ -package org.polyfrost.chatting.gui.components - -import club.sk1er.patcher.config.PatcherConfig -import dev.deftu.omnicore.client.render.OmniResolution -import net.minecraft.client.Minecraft -import net.minecraft.client.gui.GuiButton -import net.minecraft.client.renderer.GlStateManager -import org.polyfrost.chatting.Chatting -import org.polyfrost.chatting.chat.ChatHooks -import org.polyfrost.chatting.config.ChattingConfig - -/** - * Taken from ChatShortcuts under MIT License - * https://github.com/P0keDev/ChatShortcuts/blob/master/LICENSE - * @author P0keDev - */ -open class CleanButton( - buttonId: Int, - private val x: () -> Int, - widthIn: Int, - heightIn: Int, - name: String, - private val renderType: () -> RenderType, - private val textColor: (packedFGColour: Int, enabled: Boolean, hovered: Boolean) -> Int = { packedFGColour: Int, enabled: Boolean, hovered: Boolean -> - var j = 14737632 - if (packedFGColour != 0) { - j = packedFGColour - } else if (!enabled) { - j = 10526880 - } else if (hovered) { - j = 16777120 - } - j - }, -) : - GuiButton(buttonId, x.invoke(), 0, widthIn, heightIn, name) { - - open fun isEnabled(): Boolean { - return false - } - - open fun onMousePress() { - - } - - open fun setPositionY() { - yPosition = OmniResolution.scaledHeight - 27 + if (Chatting.chatInput.compactInputBox && xPosition - ChatHooks.inputBoxRight >= 1) 13 else 0 - } - - override fun mousePressed(mc: Minecraft, mouseX: Int, mouseY: Int): Boolean { - val isPressed = - visible && mouseX >= xPosition && mouseY >= yPosition && mouseX < xPosition + width && mouseY < yPosition + height - if (isPressed) { - onMousePress() - } - return isPressed - } - - override fun drawButton(mc: Minecraft, mouseX: Int, mouseY: Int) { - enabled = isEnabled() - xPosition = x() - setPositionY() - if (visible) { - val fontrenderer = mc.fontRendererObj - GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f) - GlStateManager.enableAlpha() - GlStateManager.enableBlend() - GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0) - GlStateManager.blendFunc(770, 771) - hovered = - mouseX >= xPosition && mouseY >= yPosition && mouseX < xPosition + width && mouseY < yPosition + height - if (!Chatting.isPatcher || !PatcherConfig.transparentChatInputField) { - drawRect( - xPosition, - yPosition, - xPosition + width, - yPosition + height, - getBackgroundColor(hovered) - ) - } - mouseDragged(mc, mouseX, mouseY) - val j = textColor(packedFGColour, enabled, hovered) - when (renderType()) { - RenderType.NONE, RenderType.SHADOW -> { - drawCenteredString( - fontrenderer, - displayString, - xPosition + width / 2, - yPosition + (height - 8) / 2, - j - ) - } - - RenderType.FULL -> { -// TextRenderer.drawBorderedText( TODO -// displayString, -// ((xPosition + width / 2) - (fontrenderer.getStringWidth(displayString) / 2)).toFloat(), -// (yPosition + (height - 8) / 2).toFloat(), -// j, -// (mc.ingameGUI.chatGUI as GuiNewChatHook).`chatting$getTextOpacity`() -// ) - } - } - } - } - - private fun getBackgroundColor(hovered: Boolean) = - if (hovered) ChattingConfig.chatButtonHoveredBackgroundColor.rgba - else ChattingConfig.chatButtonBackgroundColor.rgba -} \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/chatting/gui/components/ClearButton.kt b/src/main/kotlin/org/polyfrost/chatting/gui/components/ClearButton.kt deleted file mode 100644 index e9bc313..0000000 --- a/src/main/kotlin/org/polyfrost/chatting/gui/components/ClearButton.kt +++ /dev/null @@ -1,58 +0,0 @@ -package org.polyfrost.chatting.gui.components - -import dev.deftu.omnicore.client.OmniChat -import dev.deftu.omnicore.client.render.OmniResolution -import dev.deftu.textile.minecraft.MCSimpleTextHolder -import dev.deftu.textile.minecraft.MCTextFormat -import net.minecraft.client.Minecraft -import net.minecraft.client.renderer.GlStateManager -import net.minecraft.util.ResourceLocation -import org.polyfrost.chatting.Chatting -import org.polyfrost.chatting.config.ChattingConfig -import org.polyfrost.chatting.config.ChattingConfig.chatButtonColor -import org.polyfrost.chatting.config.ChattingConfig.chatButtonHoveredColor -import org.polyfrost.oneconfig.utils.v1.Multithreading -import org.polyfrost.oneconfig.utils.v1.dsl.mc - -class ClearButton : - CleanButton( - 13379014, { if (ChattingConfig.chatSearch) OmniResolution.scaledWidth - 28 else OmniResolution.scaledWidth - 14 }, 12, 12, "", - { RenderType.NONE }) { - - var times = 0 - - override fun onMousePress() { - ++times - if (times > 1) { - times = 0 - mc.ingameGUI.chatGUI.clearChatMessages() - } else { - OmniChat.displayClientMessage(MCSimpleTextHolder("Click again to clear the chat!").withFormatting( - MCTextFormat.RED, MCTextFormat.BOLD)) - Multithreading.submit { - Thread.sleep(3000) - times = 0 - } - } - } - - override fun drawButton(mc: Minecraft, mouseX: Int, mouseY: Int) { - super.drawButton(mc, mouseX, mouseY) - if (visible) { - GlStateManager.pushMatrix() - GlStateManager.enableAlpha() - GlStateManager.enableBlend() - GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0) - GlStateManager.blendFunc(770, 771) - mc.textureManager.bindTexture(ResourceLocation(Chatting.ID, "delete.png")) - val color = if (hovered) chatButtonHoveredColor else chatButtonColor - if (ChattingConfig.buttonShadow) { - GlStateManager.color(0f, 0f, 0f, color.alpha) - drawModalRectWithCustomSizedTexture(xPosition + 2, yPosition + 2, 0f, 0f, 10, 10, 10f, 10f) - } - GlStateManager.color(color.r / 255f, color.g / 255f, color.b / 255f, color.alpha) - drawModalRectWithCustomSizedTexture(xPosition + 1, yPosition + 1, 0f, 0f, 10, 10, 10f, 10f) - GlStateManager.popMatrix() - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/chatting/gui/components/RenderType.kt b/src/main/kotlin/org/polyfrost/chatting/gui/components/RenderType.kt deleted file mode 100644 index a150d64..0000000 --- a/src/main/kotlin/org/polyfrost/chatting/gui/components/RenderType.kt +++ /dev/null @@ -1,7 +0,0 @@ -package org.polyfrost.chatting.gui.components - -enum class RenderType { - NONE, - SHADOW, - FULL -} \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/chatting/gui/components/ScreenshotButton.kt b/src/main/kotlin/org/polyfrost/chatting/gui/components/ScreenshotButton.kt deleted file mode 100644 index 1f0127d..0000000 --- a/src/main/kotlin/org/polyfrost/chatting/gui/components/ScreenshotButton.kt +++ /dev/null @@ -1,47 +0,0 @@ -package org.polyfrost.chatting.gui.components - -import dev.deftu.omnicore.client.OmniScreen -import dev.deftu.omnicore.client.render.OmniResolution -import net.minecraft.client.Minecraft -import net.minecraft.client.gui.Gui -import net.minecraft.client.gui.GuiChat -import net.minecraft.client.renderer.GlStateManager -import net.minecraft.util.ResourceLocation -import org.polyfrost.chatting.Chatting -import org.polyfrost.chatting.config.ChattingConfig -import org.polyfrost.chatting.mixin.GuiNewChatAccessor -import org.polyfrost.oneconfig.utils.v1.dsl.mc - -class ScreenshotButton : - CleanButton( - 448318, { - if (ChattingConfig.chatSearch && ChattingConfig.chatDeleteHistory) OmniResolution.scaledWidth - 42 else if (ChattingConfig.chatSearch || ChattingConfig.chatDeleteHistory) OmniResolution.scaledWidth - 28 else OmniResolution.scaledWidth - 14 - }, 12, 12, "", - { RenderType.NONE }) { - - override fun onMousePress() { - if (OmniScreen.currentScreen is GuiChat) { - Chatting.screenshotChat((mc.ingameGUI.chatGUI as GuiNewChatAccessor).scrollPos) - } - } - - override fun drawButton(mc: Minecraft, mouseX: Int, mouseY: Int) { - super.drawButton(mc, mouseX, mouseY) - if (visible) { - GlStateManager.pushMatrix() - GlStateManager.enableAlpha() - GlStateManager.enableBlend() - GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0) - GlStateManager.blendFunc(770, 771) - mc.textureManager.bindTexture(ResourceLocation(Chatting.ID, "screenshot.png")) - val color = if (hovered) ChattingConfig.chatButtonHoveredColor else ChattingConfig.chatButtonColor - if (ChattingConfig.buttonShadow) { - GlStateManager.color(0f, 0f, 0f, color.alpha) - Gui.drawModalRectWithCustomSizedTexture(xPosition + 2, yPosition + 2, 0f, 0f, 10, 10, 10f, 10f) - } - GlStateManager.color(color.r / 255f, color.g / 255f, color.b / 255f, color.alpha) - Gui.drawModalRectWithCustomSizedTexture(xPosition + 1, yPosition + 1, 0f, 0f, 10, 10, 10f, 10f) - GlStateManager.popMatrix() - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/chatting/gui/components/SearchButton.kt b/src/main/kotlin/org/polyfrost/chatting/gui/components/SearchButton.kt deleted file mode 100644 index 2aedd63..0000000 --- a/src/main/kotlin/org/polyfrost/chatting/gui/components/SearchButton.kt +++ /dev/null @@ -1,80 +0,0 @@ -package org.polyfrost.chatting.gui.components - -import dev.deftu.omnicore.client.render.OmniResolution -import net.minecraft.client.Minecraft -import net.minecraft.client.gui.Gui -import net.minecraft.client.gui.GuiTextField -import net.minecraft.client.renderer.GlStateManager -import net.minecraft.util.ResourceLocation -import org.polyfrost.chatting.Chatting -import org.polyfrost.chatting.chat.ChatSearchingManager -import org.polyfrost.chatting.config.ChattingConfig -import org.polyfrost.oneconfig.utils.v1.dsl.mc -import org.polyfrost.polyui.color.rgba - -class SearchButton() : - CleanButton( - 3993935, { OmniResolution.scaledWidth - 14 }, 12, 12, "", - { RenderType.NONE }) { - val inputField = SearchTextField() - private var chatBox = false - - override fun isEnabled(): Boolean { - return chatBox - } - - override fun onMousePress() { - chatBox = !chatBox - inputField.setEnabled(chatBox) - inputField.isFocused = chatBox - ChatSearchingManager.lastSearch = "" - inputField.text = "" - } - - override fun drawButton(mc: Minecraft, mouseX: Int, mouseY: Int) { - - inputField.drawTextBox() - super.drawButton(mc, mouseX, mouseY) - if (visible) { - GlStateManager.pushMatrix() - GlStateManager.enableAlpha() - GlStateManager.enableBlend() - GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0) - GlStateManager.blendFunc(770, 771) - mc.textureManager.bindTexture(ResourceLocation(Chatting.ID, "search.png")) - val color = if (isEnabled()) rgba(200, 200, 200, 1f) else if (hovered) ChattingConfig.chatButtonHoveredColor else ChattingConfig.chatButtonColor - if (ChattingConfig.buttonShadow) { - GlStateManager.color(0f, 0f, 0f, color.alpha) - Gui.drawModalRectWithCustomSizedTexture(xPosition + 2, yPosition + 2, 0f, 0f, 10, 10, 10f, 10f) - } - GlStateManager.color(color.r / 255f, color.g / 255f, color.b / 255f, color.alpha) - Gui.drawModalRectWithCustomSizedTexture(xPosition + 1, yPosition + 1, 0f, 0f, 10, 10, 10f, 10f) - GlStateManager.popMatrix() - } - } - - inner class SearchTextField : GuiTextField( - 69420, - mc.fontRendererObj, - OmniResolution.scaledWidth * 4 / 5 - 60, - OmniResolution.scaledHeight - 26, - OmniResolution.scaledWidth / 5, - 12 - ) { - - init { - maxStringLength = 100 - enableBackgroundDrawing = true - isFocused = false - text = "" - setCanLoseFocus(true) - } - - override fun drawTextBox() { - if (isEnabled()) { - if (!isFocused) isFocused = true - super.drawTextBox() - } - } - } -} diff --git a/src/main/kotlin/org/polyfrost/chatting/gui/components/TabButton.kt b/src/main/kotlin/org/polyfrost/chatting/gui/components/TabButton.kt deleted file mode 100644 index 7dac408..0000000 --- a/src/main/kotlin/org/polyfrost/chatting/gui/components/TabButton.kt +++ /dev/null @@ -1,48 +0,0 @@ -package org.polyfrost.chatting.gui.components - -import dev.deftu.omnicore.client.OmniKeyboard -import dev.deftu.omnicore.client.render.OmniResolution -import org.polyfrost.chatting.chat.ChatTab -import org.polyfrost.chatting.chat.ChatTabs -import org.polyfrost.chatting.config.ChattingConfig - -class TabButton(buttonId: Int, x: Int, widthIn: Int, heightIn: Int, private val chatTab: ChatTab) : - CleanButton(buttonId, { x }, widthIn, heightIn, chatTab.name, { RenderType.values()[ChattingConfig.textRenderType] }, { packedFGColour: Int, enabled: Boolean, hovered: Boolean -> - var j = chatTab.color ?: color - if (packedFGColour != 0) { - j = packedFGColour - } else if (!enabled) { - j = chatTab.selectedColor ?: selectedColor - } else if (hovered) { - j = chatTab.hoveredColor ?: hoveredColor - } - j - }) { - - override fun onMousePress() { - if (OmniKeyboard.isShiftKeyPressed) { - if (ChatTabs.currentTabs.contains(chatTab)) { - ChatTabs.currentTabs.remove(chatTab) - } else { - ChatTabs.currentTabs.add(chatTab) - } - } else { - ChatTabs.currentTabs.clear() - ChatTabs.currentTabs.add(chatTab) - } - } - - override fun setPositionY() { - yPosition = OmniResolution.scaledHeight - 26 - } - - override fun isEnabled(): Boolean { - return ChatTabs.currentTabs.contains(chatTab) - } - - companion object { - const val color: Int = 14737632 - const val hoveredColor: Int = 16777120 - const val selectedColor: Int = 10526880 - } -} \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/chatting/utils/ModCompatHooks.kt b/src/main/kotlin/org/polyfrost/chatting/utils/ModCompatHooks.kt deleted file mode 100644 index 1a8105e..0000000 --- a/src/main/kotlin/org/polyfrost/chatting/utils/ModCompatHooks.kt +++ /dev/null @@ -1,129 +0,0 @@ -package org.polyfrost.chatting.utils - -import org.polyfrost.oneconfig.utils.v1.dsl.mc -import club.sk1er.patcher.config.PatcherConfig -import com.llamalad7.betterchat.BetterChat -import dev.deftu.omnicore.client.render.OmniGameRendering -import dev.deftu.omnicore.client.render.OmniMatrixStack -import net.minecraft.client.gui.ChatLine -import net.minecraft.client.gui.FontRenderer -import net.minecraft.client.gui.Gui -import net.minecraft.client.renderer.GlStateManager -import org.polyfrost.chatting.Chatting.isBetterChat -import org.polyfrost.chatting.Chatting.isPatcher -import org.polyfrost.chatting.config.ChattingConfig -import org.polyfrost.chatting.config.ChattingConfig.offsetNonPlayerMessages -import org.polyfrost.chatting.config.ChattingConfig.showChatHeads -import org.polyfrost.chatting.hook.ChatLineHook -import org.polyfrost.chatting.mixin.GuiNewChatAccessor -import org.polyfrost.polyui.color.alpha - -// This exists because mixin doesn't like dummy classes -//TODO this is no longer an issue, but its nice for organization... keep or remove? -object ModCompatHooks { - @JvmStatic - val xOffset - get() = if (isBetterChat) BetterChat.getSettings().xOffset else 0 - - @JvmStatic - val yOffset - get() = if (isBetterChat) BetterChat.getSettings().yOffset else 0 - - @JvmStatic - val chatPosition - get() = if (isPatcher && PatcherConfig.chatPosition) 12 else 0 - - @JvmStatic - val betterChatSmoothMessages - get() = if (isBetterChat) BetterChat.getSettings().smooth else false - - @JvmStatic - val extendedChatLength - get() = if (isPatcher) 32667 else 0 - - @JvmStatic - val fontRenderer: FontRenderer - get() = mc.fontRendererObj - - @JvmStatic - val chatLines: List - get() = (mc.ingameGUI.chatGUI as GuiNewChatAccessor).chatLines - - @JvmStatic - val drawnChatLines: List - get() = (mc.ingameGUI.chatGUI as GuiNewChatAccessor).drawnChatLines - - @JvmStatic - val chatHeadOffset - get() = if (showChatHeads) 10 else 0 - - @JvmStatic - val chatButtonOffset - get() = (if (ChattingConfig.chatCopy) 10 else 0) + (if (ChattingConfig.chatDelete) 10 else 0) - - @JvmStatic - val chatInputLimit - get() = if (isPatcher && PatcherConfig.extendedChatLength) 256 else 100 - - @JvmStatic - val shouldDrawInputBox - get() = !isPatcher || !PatcherConfig.transparentChatInputField - - @JvmStatic - fun redirectDrawString(text: String, x: Float, y: Float, color: Int, chatLine: ChatLine): Int { - var actualX = x - if (showChatHeads) { - val hook = chatLine as ChatLineHook - if (hook.`chatting$hasDetected`() || offsetNonPlayerMessages) { - actualX += 10f - } - val networkPlayerInfo = hook.`chatting$getPlayerInfo`() - if (networkPlayerInfo != null) { - GlStateManager.enableBlend() - GlStateManager.enableAlpha() - GlStateManager.enableTexture2D() - mc.textureManager.bindTexture(networkPlayerInfo.locationSkin) - GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0) - GlStateManager.color(1.0f, 1.0f, 1.0f, color.alpha / 255f) - Gui.drawScaledCustomSizeModalRect( - (x).toInt(), - (y - 1f).toInt(), - 8.0f, - 8.0f, - 8, - 8, - 8, - 8, - 64.0f, - 64.0f - ) - Gui.drawScaledCustomSizeModalRect( - (x).toInt(), - (y - 1f).toInt(), - 40.0f, - 8.0f, - 8, - 8, - 8, - 8, - 64.0f, - 64.0f - ) - GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f) - } - } - val stack = OmniMatrixStack() - return when (ChattingConfig.textRenderType) { - 0 -> { - OmniGameRendering.drawText(stack, text, actualX, y, color, false) - 0 // todo - } - 1 -> { - OmniGameRendering.drawText(stack, text, actualX, y, color, true) - 0 - } -// 2 -> TextRenderer.drawBorderedText(text, actualX, y, color, color.alpha / 255f) TODO - else -> fontRenderer.drawString(text, actualX, y, color, true) - } - } -} diff --git a/src/main/kotlin/org/polyfrost/chatting/utils/RenderUtils.kt b/src/main/kotlin/org/polyfrost/chatting/utils/RenderUtils.kt deleted file mode 100644 index 39bdfe7..0000000 --- a/src/main/kotlin/org/polyfrost/chatting/utils/RenderUtils.kt +++ /dev/null @@ -1,115 +0,0 @@ -@file:JvmName("RenderUtils") - -package org.polyfrost.chatting.utils - -import net.minecraft.client.renderer.GlStateManager -import net.minecraft.client.renderer.texture.TextureUtil -import net.minecraft.client.shader.Framebuffer -import org.lwjgl.BufferUtils -import org.lwjgl.opengl.GL11 -import org.lwjgl.opengl.GL12 -import org.polyfrost.chatting.config.ChattingConfig -import java.awt.image.BufferedImage -import java.io.File -import javax.imageio.ImageIO - -/** - * Taken from https://github.com/Moulberry/HyChat - */ -fun createBindFramebuffer(w: Int, h: Int): Framebuffer { - val framebuffer = Framebuffer(w, h, false) - framebuffer.framebufferColor[0] = 0x36 / 255f - framebuffer.framebufferColor[1] = 0x39 / 255f - framebuffer.framebufferColor[2] = 0x3F / 255f - framebuffer.framebufferClear() - GlStateManager.matrixMode(5889) - GlStateManager.loadIdentity() - GlStateManager.ortho(0.0, w.toDouble(), h.toDouble(), 0.0, 1000.0, 3000.0) - GlStateManager.matrixMode(5888) - GlStateManager.loadIdentity() - GlStateManager.translate(0.0f, 0.0f, -2000.0f) - framebuffer.bindFramebuffer(true) - return framebuffer -} - -/** - * Taken from https://github.com/Moulberry/HyChat - */ -fun Framebuffer.screenshot(file: File): BufferedImage { - val w = this.framebufferWidth - val h = this.framebufferHeight - val i = w * h - val pixelBuffer = BufferUtils.createIntBuffer(i) - val pixelValues = IntArray(i) - GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1) - GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1) - GlStateManager.bindTexture(this.framebufferTexture) - GL11.glGetTexImage(GL11.GL_TEXTURE_2D, 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, pixelBuffer) - pixelBuffer[pixelValues] //Load buffer into array - TextureUtil.processPixelValues(pixelValues, w, h) //Flip vertically - val bufferedimage = BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB) - val j = this.framebufferTextureHeight - this.framebufferHeight - for (k in j until this.framebufferTextureHeight) { - for (l in 0 until this.framebufferWidth) { - bufferedimage.setRGB(l, k - j, pixelValues[k * this.framebufferTextureWidth + l]) - } - } - if (ChattingConfig.copyMode != 1) { - try { - file.parentFile.mkdirs() - ImageIO.write(bufferedimage, "png", file) - } catch (e: Exception) { - e.printStackTrace() - } - } - return bufferedimage -} -/*/ -private val timePattern = Regex("\\[\\d+:\\d+:\\d+]") -private var lastLines = mutableListOf() -fun timestampPre() { - if (!ChattingConfig.showTimestampHover) return - val drawnChatLines = (Minecraft.getMinecraft().ingameGUI.chatGUI as GuiNewChatAccessor).drawnChatLines - val chatLine = getChatLineOverMouse(UMouse.getTrueX().roundToInt(), UMouse.getTrueY().roundToInt()) - - lastLines.clear() - for (line in drawnChatLines) { - val chatComponent = line.chatComponent.createCopy() - val newline = ChatLine(line.updatedCounter, chatComponent, line.chatLineID) - lastLines.add(newline) - } - - drawnChatLines.map { - if (it != chatLine) it.chatComponent.siblings.removeAll { itt -> - timePattern.find(ChatColor.stripControlCodes(itt.unformattedText)!!) != null - } - } -} - -fun timestampPost() { - if (!ChattingConfig.showTimestampHover) return - val drawnChatLines = (Minecraft.getMinecraft().ingameGUI.chatGUI as GuiNewChatAccessor).drawnChatLines - drawnChatLines.clear() - drawnChatLines.addAll(lastLines) -} - -private fun getChatLineOverMouse(mouseX: Int, mouseY: Int): ChatLine? { - val chat = Minecraft.getMinecraft().ingameGUI.chatGUI - if (!chat.chatOpen) return null - val scaledResolution = ScaledResolution(Minecraft.getMinecraft()) - val i = scaledResolution.scaleFactor - val f = chat.chatScale - val j = MathHelper.floor_float((mouseX / i - 3).toFloat() / f) - val k = MathHelper.floor_float((mouseY / i - 27).toFloat() / f) - if (j < 0 || k < 0) return null - val drawnChatLines = (chat as GuiNewChatAccessor).drawnChatLines - val l = chat.lineCount.coerceAtMost(drawnChatLines.size) - if (j <= MathHelper.floor_float(chat.chatWidth.toFloat() / f) && k < fontRenderer.FONT_HEIGHT * l + l) { - val m = k / Minecraft.getMinecraft().fontRendererObj.FONT_HEIGHT + chat.scrollPos - if (m >= 0 && m < drawnChatLines.size) - return drawnChatLines[m] - } - return null -} - - */ \ No newline at end of file diff --git a/src/main/resources/assets/chatting/copy.png b/src/main/resources/assets/chatting/copy.png deleted file mode 100644 index cb1a1a4088528eb9bd53b11b63dc8b2227258fef..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 121 zcmeAS@N?(olHy`uVBq!ia0vp^oFL4>1|%O$WD@{V4xTQKAre!2doOY^C~z=ufAPP* zGErrPMv4EUbDi=TeJZB!&Uz$Wf2u6&y0Xn~vsdopS#d5gn_l0T@Zw%?uQ3B(dM1~s T?*Zc&pjix_u6{1-oD!M<^&Tgr diff --git a/src/main/resources/assets/chatting/delete.png b/src/main/resources/assets/chatting/delete.png deleted file mode 100644 index 81de387c779db67317d4fc49c81bc83dd4124b70..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 158 zcmeAS@N?(olHy`uVBq!ia0vp^oFL4>1|%O$WD@{Vsh%#5Are!Q6{I>&8yk0=G&KI> z&a}wr49_I5GYQHPjw~Kr(;ItwdJ;?%COdGk9-Vn$%Mv5*mbO_(T0*U7?G$j$XsWMU z%(Y;~k(1mTJ~y diff --git a/src/main/resources/assets/chatting/reply.png b/src/main/resources/assets/chatting/reply.png deleted file mode 100644 index f3d76e6a05d3f22610dd8cf0c81d85c14a1278a0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 120 zcmeAS@N?(olHy`uVBq!ia0vp^oFL4>1|%O$WD@{V_MR?|Are#9`Z;njDDYf*@jpH; zCn4fZ*r5Zw%O6S4a1&JAuTm=Pk#u9pE{n*s`{{FvG?`&f(&AhLOA*I Tzlb~p8pYu0>gTe~DWM4fw&f?D diff --git a/src/main/resources/assets/chatting/screenshot.png b/src/main/resources/assets/chatting/screenshot.png deleted file mode 100644 index b0a2f22c630d9585d76387f136689cdd03f4c141..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 125 zcmeAS@N?(olHy`uVBq!ia0vp^AT}2V8<6ZZI=>f4xp=xbhDc0Z>+i_Npuo}e?|=I3 zD2vp}?(P;I&ijt6ZZ0uey7yH!zA<9I*OU8jmU`a`x6)M}XN6Zs{_%PL$ Yb7i>%3zRmv1I=UbboFyt=akR{0FT`%0ssI2 diff --git a/src/main/resources/assets/chatting/search.png b/src/main/resources/assets/chatting/search.png deleted file mode 100644 index a5be87768e69906a65c49c20e23ac63e64d6050f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 158 zcmeAS@N?(olHy`uVBq!ia0vp^AT}2V8<6ZZI=>f4F%}28J29*~C-V}>VM%xNb!1@J z*w6hZkrl}2EbxddW?alTRVg`1RI)hmKdsO w_}Vy_G2S)dVF+SiGBAsnAmLzrlm`eHo-i7p-~H_QVxV>gPgg&ebxsLQ0J3Z*=l}o! diff --git a/src/main/resources/chatting_dark.svg b/src/main/resources/chatting_dark.svg deleted file mode 100644 index 42db03e..0000000 --- a/src/main/resources/chatting_dark.svg +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json new file mode 100644 index 0000000..2fa797f --- /dev/null +++ b/src/main/resources/fabric.mod.json @@ -0,0 +1,26 @@ +{ + "schemaVersion": 1, + "id": "${mod_id}", + "version": "${mod_version}", + "name": "${mod_name}", + "description": "${mod_description}", + "authors": [ + "Your Name" + ], + "environment": "*", + "entrypoints": { + "client": [ + { + "adapter": "kotlin", + "value": "org.polyfrost.chatting.Chatting" + } + ] + }, + "mixins": [ + "mixins.${mod_id}.json" + ], + "depends": { + "minecraft": "~${minor_mc_version}", + "fabricloader": ">=0.15.11" + } +} \ No newline at end of file diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info deleted file mode 100644 index 4bc9f07..0000000 --- a/src/main/resources/mcmod.info +++ /dev/null @@ -1,18 +0,0 @@ -[ - { - "modid": "${mod_id}", - "name": "${mod_name}", - "description": "A chat mod adding utilities such as extremely customizable chat tabs, chat shortcuts, chat screenshots, and message copying.", - "version": "${mod_version}", - "mcversion": "1.8.9", - "url": "", - "updateUrl": "", - "authorList": [ - "Polyfrost" - ], - "credits": "Mo2men#2806 for chat icons, Pablo", - "logoFile": "", - "screenshots": [], - "dependencies": [] - } -] diff --git a/src/main/resources/mixins.chatting.json b/src/main/resources/mixins.chatting.json index 6782af8..6232be2 100644 --- a/src/main/resources/mixins.chatting.json +++ b/src/main/resources/mixins.chatting.json @@ -1,35 +1,14 @@ { - "compatibilityLevel": "JAVA_8", - "minVersion": "0.7", + "compatibilityLevel": "${java_version}", + "minVersion": "0.8", "package": "org.polyfrost.chatting.mixin", "refmap": "mixins.${mod_id}.refmap.json", - "verbose": true, + "injectors": { + "maxShiftBy": 5 + }, "client": [ - "ChatLineMixin", - "ClientCommandHandlerMixin", - "EntityPlayerSPMixin", - "EntityRendererMixin", - "GameSettings_ChatScaleChangeEvent_Mixin", - "GuiChatMixin", - "GuiIngameForge_DrawChatAccessor", - "GuiContainerCreativeMixin", - "GuiIngameForgeMixin", - "GuiNewChatAccessor", - "GuiNewChatMixin", - "GuiNewChatMixin_ChatHeight", - "GuiNewChatMixin_ChatPeek", - "GuiNewChatMixin_ChatSearching", - "GuiNewChatMixin_ChatTabs", - "GuiNewChatMixin_Movable", - "GuiNewChatMixin_Scrolling", - "GuiNewChatMixin_SmoothMessages", - "GuiNewChatMixin_TextRendering", - "GuiTextFieldMixin", - "GuiUtilsMixin", - "ChatStyle_UnderlineLinks_Mixin", - "InventoryPlayerMixin", - "compat.ChatPeekMixin_SkyHanni", - "compat.ChatTabsMixin_SkytilsCopyChat", - "compat.EssentialKeybindingRegistryMixin" - ] + "ChatHudAccessor", + "ChatHudMixin" + ], + "verbose": true } diff --git a/versions/mainProject b/versions/mainProject deleted file mode 100644 index dd1433e..0000000 --- a/versions/mainProject +++ /dev/null @@ -1 +0,0 @@ -1.8.9-forge \ No newline at end of file From 1fef87cfd1f0aabf1b881cbba22fbe09aefcbffd Mon Sep 17 00:00:00 2001 From: ImToggle Date: Tue, 9 Sep 2025 21:53:04 +0800 Subject: [PATCH 02/30] todo: text rendering --- build.gradle.kts | 8 +- .../chatting/mixin/ChatHudAccessor.java | 46 +------ .../chatting/mixin/ChatHudMixin.java | 18 ++- .../chatting/mixin/HudManagerMixin.java | 22 ++++ .../org/polyfrost/chatting/ChatWindow.kt | 116 +++--------------- .../kotlin/org/polyfrost/chatting/Chatting.kt | 3 +- .../org/polyfrost/chatting/ModConfig.kt | 10 +- .../kotlin/org/polyfrost/chatting/Util.kt | 12 ++ .../chatting/component/ChatComponent.kt | 93 ++++++++++++++ .../chatting/component/ChatLineComponent.kt | 38 ++++++ .../chatting/event/HudEditorEvent.kt | 6 + .../chatting/event/NewMessageEvent.kt | 7 ++ src/main/resources/mixins.chatting.json | 5 +- 13 files changed, 219 insertions(+), 165 deletions(-) create mode 100644 src/main/java/org/polyfrost/chatting/mixin/HudManagerMixin.java create mode 100644 src/main/kotlin/org/polyfrost/chatting/Util.kt create mode 100644 src/main/kotlin/org/polyfrost/chatting/component/ChatComponent.kt create mode 100644 src/main/kotlin/org/polyfrost/chatting/component/ChatLineComponent.kt create mode 100644 src/main/kotlin/org/polyfrost/chatting/event/HudEditorEvent.kt create mode 100644 src/main/kotlin/org/polyfrost/chatting/event/NewMessageEvent.kt diff --git a/build.gradle.kts b/build.gradle.kts index aca15ab..2b0180d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,8 +4,8 @@ import dev.deftu.gradle.utils.GameSide plugins { java - kotlin("jvm") version("2.0.10") - val dgtVersion = "2.39.0" + kotlin("jvm") version("2.1.0") + val dgtVersion = "2.51.0" id("dev.deftu.gradle.tools") version(dgtVersion) // Applies several configurations to things such as the Java version, project name/version, etc. id("dev.deftu.gradle.tools.resources") version(dgtVersion) // Applies resource processing so that we can replace tokens, such as our mod name/version, in our resources. id("dev.deftu.gradle.tools.bloom") version(dgtVersion) // Applies the Bloom plugin, which allows us to replace tokens in our source files, such as being able to use `@MOD_VERSION` in our source files. @@ -20,8 +20,8 @@ plugins { toolkitLoomHelper { useOneConfig { - version = "1.0.0-alpha.106" - loaderVersion = "1.1.0-alpha.46" + version = "1.0.0-alpha.140" + loaderVersion = "1.1.0-alpha.49" for (module in arrayOf("commands", "config", "config-impl", "events", "internal", "ui", "utils")) { +module diff --git a/src/main/java/org/polyfrost/chatting/mixin/ChatHudAccessor.java b/src/main/java/org/polyfrost/chatting/mixin/ChatHudAccessor.java index d9bf105..1e45081 100644 --- a/src/main/java/org/polyfrost/chatting/mixin/ChatHudAccessor.java +++ b/src/main/java/org/polyfrost/chatting/mixin/ChatHudAccessor.java @@ -1,12 +1,9 @@ package org.polyfrost.chatting.mixin; -import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.hud.ChatHud; import net.minecraft.client.gui.hud.ChatHudLine; -import net.minecraft.client.gui.hud.MessageIndicator; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; -import org.spongepowered.asm.mixin.gen.Invoker; import java.util.List; @@ -14,47 +11,6 @@ public interface ChatHudAccessor { @Accessor - List getVisibleMessages(); - - @Accessor - int getScrolledLines(); - - - -// @Accessor -// boolean getHasUnreadNewMessages(); -// -// @Invoker("getHeight") -// int getHeight(); -// -// @Invoker("getWidth") -// int getWidth(); -// -// @Invoker("getMessageIndex") -// int getMessageIndex(double x, double y); -// -// @Invoker("toChatLineX") -// double toChatLineX(double x); -// -// @Invoker("toChatLineY") -// double toChatLineY(double x); -// - @Invoker - int invokeGetIndicatorX(ChatHudLine.Visible visible); -// - @Invoker - void invokeDrawIndicatorIcon(DrawContext drawContext, int i, int j, MessageIndicator.Icon icon); - - @Invoker - double invokeGetMessageOpacityMultiplier(int i); - - @Invoker - int invokeGetLineHeight(); -// -// @Invoker("isChatHidden") -// boolean isChatHidden(); -// -// @Invoker("getChatScale") -// double getChatScale(); + List getMessages(); } diff --git a/src/main/java/org/polyfrost/chatting/mixin/ChatHudMixin.java b/src/main/java/org/polyfrost/chatting/mixin/ChatHudMixin.java index 4e8882e..a5e7563 100644 --- a/src/main/java/org/polyfrost/chatting/mixin/ChatHudMixin.java +++ b/src/main/java/org/polyfrost/chatting/mixin/ChatHudMixin.java @@ -1,8 +1,13 @@ package org.polyfrost.chatting.mixin; -import net.minecraft.client.gui.DrawContext; +import com.llamalad7.mixinextras.sugar.Local; import net.minecraft.client.gui.hud.ChatHud; -import org.polyfrost.chatting.ModConfig; +import net.minecraft.client.gui.hud.ChatHudLine; +import net.minecraft.client.gui.hud.MessageIndicator; +import net.minecraft.network.message.MessageSignatureData; +import net.minecraft.text.Text; +import org.polyfrost.chatting.event.NewMessageEvent; +import org.polyfrost.oneconfig.api.event.v1.EventManager; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -11,8 +16,9 @@ @Mixin(ChatHud.class) public class ChatHudMixin { -// @Inject(method = "render", at = @At("HEAD"), cancellable = true) -// private void cancelChat(DrawContext drawContext, int i, int j, int k, boolean bl, CallbackInfo ci) { -// if (ModConfig.INSTANCE.enabled) ci.cancel(); -// } + @Inject(method = "addMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignatureData;Lnet/minecraft/client/gui/hud/MessageIndicator;)V", at = @At("TAIL")) + private void createMessage(Text text, MessageSignatureData messageSignatureData, MessageIndicator messageIndicator, CallbackInfo ci, @Local(ordinal = 0) ChatHudLine chatHudLine) { + EventManager.INSTANCE.post(new NewMessageEvent(chatHudLine)); + } + } diff --git a/src/main/java/org/polyfrost/chatting/mixin/HudManagerMixin.java b/src/main/java/org/polyfrost/chatting/mixin/HudManagerMixin.java new file mode 100644 index 0000000..febed2c --- /dev/null +++ b/src/main/java/org/polyfrost/chatting/mixin/HudManagerMixin.java @@ -0,0 +1,22 @@ +package org.polyfrost.chatting.mixin; + +import org.polyfrost.chatting.event.HudEditorEvent; +import org.polyfrost.oneconfig.api.event.v1.EventManager; +import org.polyfrost.oneconfig.api.hud.v1.HudManager; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(value = HudManager.class, remap = false) +public class HudManagerMixin { + + @Shadow + private static boolean panelExists; + + @Inject(method = "toggleHudPicker", at = @At("TAIL")) + private void editor(CallbackInfo ci) { + EventManager.INSTANCE.post(new HudEditorEvent(panelExists)); + } +} diff --git a/src/main/kotlin/org/polyfrost/chatting/ChatWindow.kt b/src/main/kotlin/org/polyfrost/chatting/ChatWindow.kt index 89a2dcc..b5e28b3 100644 --- a/src/main/kotlin/org/polyfrost/chatting/ChatWindow.kt +++ b/src/main/kotlin/org/polyfrost/chatting/ChatWindow.kt @@ -1,127 +1,41 @@ package org.polyfrost.chatting -import dev.deftu.omnicore.client.render.OmniResolution -import net.minecraft.client.font.TextRenderer -import net.minecraft.client.gui.DrawContext -import net.minecraft.client.gui.hud.ChatHudLine -import net.minecraft.client.gui.screen.ChatScreen -import net.minecraft.network.message.ChatVisibility -import net.minecraft.util.math.ColorHelper -import org.polyfrost.chatting.mixin.ChatHudAccessor +import org.polyfrost.chatting.component.ChatComponent +import org.polyfrost.chatting.component.ChatLineComponent import org.polyfrost.oneconfig.api.hud.v1.Hud -import org.polyfrost.oneconfig.utils.v1.OneImage -import org.polyfrost.oneconfig.utils.v1.dsl.mc -import org.polyfrost.polyui.color.argb -import org.polyfrost.polyui.color.rgba import org.polyfrost.polyui.component.Drawable import org.polyfrost.polyui.component.impl.Text -import org.polyfrost.polyui.data.PolyImage -import org.polyfrost.polyui.unit.Vec2 import org.polyfrost.polyui.unit.milliseconds -import java.util.* -import javax.swing.text.StyleConstants.getComponent -import kotlin.math.round -class ChatWindow() : Hud() { +class ChatWindow(preview: Boolean) : Hud(id = "chat.yml", title = "Chat", category = Category.INFO) { - override fun title(): String { - return "Chat" - } + var isPreview = preview - override fun category(): Category { - return Category.INFO + override fun clone(): Hud { + return (super.clone() as ChatWindow).apply { isPreview = false } } override fun create(): Drawable { - return ChatComponent() + return if (isPreview) Text("Chat", fontSize = 32f) else ChatComponent() } override fun updateFrequency(): Long { return 25.milliseconds } - override fun multipleInstancesAllowed() = false - - override fun defaultPosition(): Vec2 { - return Vec2(200f, 200f) - } - override fun update(): Boolean { - if (get() !is ChatComponent) return false - val accessor = mc.inGameHud.chatHud as ChatHudAccessor - hidden = mc.options.chatVisibility.getValue() == ChatVisibility.HIDDEN && accessor.visibleMessages.isEmpty() - - val bl = mc.currentScreen is ChatScreen - var u = 0 - val d = mc.options.chatOpacity.getValue().toDouble() * 0.9 + 0.1 - val component = get() as ChatComponent - component.renderingLines.clear() - while (u + accessor.scrolledLines < accessor.visibleMessages.size && u < mc.inGameHud.chatHud.visibleLineCount) { - val v = u + accessor.scrolledLines - val visible = accessor.visibleMessages[v] - if (visible != null) { - val w = mc.inGameHud.ticks - visible.comp_895() - if (w < 200 || bl) { - val h = if (bl) 1.0 else accessor.invokeGetMessageOpacityMultiplier(w) - val opacity = 255.0 * h - if ((opacity * d).toInt() > 3) { - component.renderingLines[visible] = opacity - } - } - } - ++u + if (get() is Text) return false + get().width = (320 + 12) * mcScale + val size = get().children!!.count { + val creationTick = (it as ChatLineComponent).visible.comp_895 + val canRender = inChatScreen || creationTick == -1 || creationTick >= 200 + it.renders = canRender + return@count canRender } - + get().height = size * 9 * mcScale return true } override fun hasBackground() = false - class ChatComponent() : Drawable() { - - override var width = 0f - - override var height = 0f - - var renderingLines = LinkedHashMap() - - override fun draw() { // height might equal 0 - val accessor = mc.inGameHud.chatHud as ChatHudAccessor - width = (mc.inGameHud.chatHud.width + 12) * OmniResolution.scaleFactor.toFloat() - height = renderingLines.size * accessor.invokeGetLineHeight() * OmniResolution.scaleFactor.toFloat() - super.draw() - } - - override fun render() { - renderer.rect(x, y, width, height, rgba(0, 0, 0, 0.5f)) - val accessor = mc.inGameHud.chatHud as ChatHudAccessor - val drawContext = DrawContext(mc, mc.bufferBuilders.entityVertexConsumers) - val lineHeight = accessor.invokeGetLineHeight() - val spacing = mc.options.chatLineSpacing.getValue().toDouble() - val mcScale = OmniResolution.scaleFactor.toFloat() - val chatScale = mc.inGameHud.chatHud.chatScale.toFloat() - val chatOpacity = mc.options.chatOpacity.getValue() * 0.9 + 0.1 - val mcX = x / mcScale - val mcY = y / mcScale - renderingLines.reversed().onEachIndexed { i, (visible, opacity) -> - val textOpacity = (opacity * chatOpacity).toInt() - val textX = 4 - val lineY = i * lineHeight - val textY = round(lineY + spacing * 5 + 1).toInt() // trust me - val messageIndicator = visible.indicator() - if (messageIndicator != null) { - val color = messageIndicator.comp_899() or (textOpacity shl 24) - renderer.rect(x, y + lineY.toFloat() * mcScale, 2 * mcScale, lineHeight * mcScale, argb(color)) - renderer. -// drawContext.fill(0, lineY, 2, lineY + lineHeight, color) - } - drawContext.matrices.push() - drawContext.matrices.translate(mcX, mcY, 0f) - drawContext.matrices.scale(chatScale, chatScale, 1f) - drawContext.drawTextWithShadow(mc.textRenderer, visible.comp_896(), textX, textY, ColorHelper.withAlpha(textOpacity, -1)) - drawContext.matrices.pop() - } - } - - } } \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/chatting/Chatting.kt b/src/main/kotlin/org/polyfrost/chatting/Chatting.kt index 5634a08..779c69c 100644 --- a/src/main/kotlin/org/polyfrost/chatting/Chatting.kt +++ b/src/main/kotlin/org/polyfrost/chatting/Chatting.kt @@ -2,7 +2,6 @@ package org.polyfrost.chatting import net.fabricmc.api.ClientModInitializer import org.polyfrost.oneconfig.api.commands.v1.CommandManager -import org.polyfrost.oneconfig.api.hud.v1.Hud import org.polyfrost.oneconfig.api.hud.v1.HudManager object Chatting : ClientModInitializer { @@ -10,7 +9,7 @@ object Chatting : ClientModInitializer { override fun onInitializeClient() { ModConfig.preload() CommandManager.register(ModCommand) - HudManager.register(ChatWindow()) + HudManager.register(ChatWindow(preview = true)) } } diff --git a/src/main/kotlin/org/polyfrost/chatting/ModConfig.kt b/src/main/kotlin/org/polyfrost/chatting/ModConfig.kt index fc09383..709388d 100644 --- a/src/main/kotlin/org/polyfrost/chatting/ModConfig.kt +++ b/src/main/kotlin/org/polyfrost/chatting/ModConfig.kt @@ -4,7 +4,6 @@ import dev.deftu.omnicore.client.OmniKeyboard import org.polyfrost.oneconfig.api.config.v1.Config import org.polyfrost.oneconfig.api.config.v1.annotations.* import org.polyfrost.oneconfig.api.hypixel.v1.HypixelUtils -import org.polyfrost.oneconfig.api.ui.v1.keybind.KeybindManager import org.polyfrost.polyui.color.rgba import org.polyfrost.polyui.input.KeybindHelper @@ -62,11 +61,10 @@ object ModConfig : Config("${ModConstants.ID}.json", ModConstants.NAME, Category var chatPeekBind = KeybindHelper.builder().keys(OmniKeyboard.KEY_Z).does { }.build() -// @DualOption( -// title = "Peek Mode", -// left = "Held", -// right = "Toggle" -// ) + @RadioButton( + title = "Peek Mode", + options = ["Helod", "Toggle"] + ) var peekMode = false @Switch( diff --git a/src/main/kotlin/org/polyfrost/chatting/Util.kt b/src/main/kotlin/org/polyfrost/chatting/Util.kt new file mode 100644 index 0000000..67f39a6 --- /dev/null +++ b/src/main/kotlin/org/polyfrost/chatting/Util.kt @@ -0,0 +1,12 @@ +@file:JvmName("Util") +package org.polyfrost.chatting + +import dev.deftu.omnicore.client.render.OmniResolution +import net.minecraft.client.gui.screen.ChatScreen +import org.polyfrost.oneconfig.utils.v1.dsl.mc + +val mcScale + get() = OmniResolution.scaleFactor.toFloat() + +val inChatScreen: Boolean + get() = mc.currentScreen != null && mc.currentScreen is ChatScreen diff --git a/src/main/kotlin/org/polyfrost/chatting/component/ChatComponent.kt b/src/main/kotlin/org/polyfrost/chatting/component/ChatComponent.kt new file mode 100644 index 0000000..5254f2a --- /dev/null +++ b/src/main/kotlin/org/polyfrost/chatting/component/ChatComponent.kt @@ -0,0 +1,93 @@ +package org.polyfrost.chatting.component + +import net.minecraft.client.gui.hud.ChatHudLine +import net.minecraft.client.util.ChatMessages +import org.polyfrost.chatting.event.HudEditorEvent +import org.polyfrost.chatting.event.NewMessageEvent +import org.polyfrost.chatting.mixin.ChatHudAccessor +import org.polyfrost.oneconfig.api.event.v1.eventHandler +import org.polyfrost.oneconfig.utils.v1.dsl.mc +import org.polyfrost.polyui.PolyUI +import org.polyfrost.polyui.color.PolyColor +import org.polyfrost.polyui.component.impl.Block +import org.polyfrost.polyui.unit.by + +class ChatComponent : Block(null, color = PolyColor.TRANSPARENT, size = 320f by 32f) { + + @Transient + val editorMessages = mutableListOf( + "§bChatting", + "", + "This is a movable chat", + "§eDrag me around!" + ) + + @Transient + var actualX = 0f + + @Transient + var actualY = 0f + + init { + eventHandler { event: NewMessageEvent -> + addMessage(event.message) + } + eventHandler { event: HudEditorEvent -> + swap(event.state) + } + } + + fun swap(editing: Boolean) { + removeAllMessages() + if (editing) { + editorMessages.forEach { message -> + val line = ChatHudLine(-1, net.minecraft.text.Text.literal(message), null, null) + addMessage(line) + } + } else { + addAllMessages() + } + } + + fun addAllMessages() { + (mc.inGameHud.chatHud as ChatHudAccessor).messages.forEach { + addMessage(it) + } + } + + fun removeAllMessages() { + for (i in 0.. 100) { + removeChild(0) + } + } + + } + + override fun setup(polyUI: PolyUI): Boolean { + return super.setup(polyUI).also { + addAllMessages() + } + } + + override fun preRender(delta: Long) { + actualX = x + actualY = y + super.preRender(delta) + } +} \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/chatting/component/ChatLineComponent.kt b/src/main/kotlin/org/polyfrost/chatting/component/ChatLineComponent.kt new file mode 100644 index 0000000..409a9cb --- /dev/null +++ b/src/main/kotlin/org/polyfrost/chatting/component/ChatLineComponent.kt @@ -0,0 +1,38 @@ +package org.polyfrost.chatting.component + +import dev.deftu.omnicore.client.OmniClient +import dev.deftu.omnicore.client.render.OmniMatrixStack +import net.minecraft.client.font.TextRenderer +import net.minecraft.client.gui.hud.ChatHudLine +import org.polyfrost.chatting.mcScale +import org.polyfrost.polyui.color.rgba +import org.polyfrost.polyui.component.Drawable +import org.polyfrost.polyui.unit.by + +class ChatLineComponent(val visible: ChatHudLine.Visible, val fullMessage: ChatHudLine, x: Float = 0f, y: Float = 0f): Drawable(at = x by y, size = (320 + 12) * mcScale by 9f * mcScale) { + + + init { + color = rgba(0, 0, 0, 0.5f) + } + + override fun preRender(delta: Long) { + size = (320 + 12) * mcScale by 9 * mcScale + super.preRender(delta) + } + + override fun render() { + val index = parent.children!!.indexOf(this) + val renderY = y + index * 9 * mcScale + renderer.rect(x, renderY, width, height, color) + + val matrixStack = OmniMatrixStack() + matrixStack.push() + val textY = (parent as ChatComponent).actualY + 9 * index * mcScale * (parent as Drawable).scaleY + matrixStack.translate((parent as ChatComponent).actualX / mcScale + 4, textY / mcScale + 1, 0f) + matrixStack.scale((parent as Drawable).scaleX, (parent as Drawable).scaleY, 1f) + OmniClient.fontRenderer.draw(visible.comp_896, 0f, 0f, -1, true, matrixStack.toVanillaStack().peek().positionMatrix, OmniClient.getInstance().bufferBuilders.entityVertexConsumers, TextRenderer.TextLayerType.NORMAL, 0, 15728880) + matrixStack.pop() + } + +} \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/chatting/event/HudEditorEvent.kt b/src/main/kotlin/org/polyfrost/chatting/event/HudEditorEvent.kt new file mode 100644 index 0000000..0fe5a53 --- /dev/null +++ b/src/main/kotlin/org/polyfrost/chatting/event/HudEditorEvent.kt @@ -0,0 +1,6 @@ +package org.polyfrost.chatting.event + +import org.polyfrost.oneconfig.api.event.v1.events.Event + +class HudEditorEvent(val state: Boolean) : Event { +} \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/chatting/event/NewMessageEvent.kt b/src/main/kotlin/org/polyfrost/chatting/event/NewMessageEvent.kt new file mode 100644 index 0000000..56c08db --- /dev/null +++ b/src/main/kotlin/org/polyfrost/chatting/event/NewMessageEvent.kt @@ -0,0 +1,7 @@ +package org.polyfrost.chatting.event + +import net.minecraft.client.gui.hud.ChatHudLine +import org.polyfrost.oneconfig.api.event.v1.events.Event + +class NewMessageEvent(val message: ChatHudLine) : Event { +} \ No newline at end of file diff --git a/src/main/resources/mixins.chatting.json b/src/main/resources/mixins.chatting.json index 6232be2..762ee3b 100644 --- a/src/main/resources/mixins.chatting.json +++ b/src/main/resources/mixins.chatting.json @@ -10,5 +10,8 @@ "ChatHudAccessor", "ChatHudMixin" ], - "verbose": true + "verbose": true, + "mixins": [ + "HudManagerMixin" + ] } From eb87d57b865483c1bbd24c08b861e8c6ea938bca Mon Sep 17 00:00:00 2001 From: ImToggle Date: Wed, 10 Sep 2025 00:59:07 +0800 Subject: [PATCH 03/30] text rendering, fading --- .../mixin/ScreenPlatformImplMixin.java | 22 ++++++++ .../org/polyfrost/chatting/ChatWindow.kt | 22 ++++++-- .../org/polyfrost/chatting/ModConfig.kt | 4 +- .../kotlin/org/polyfrost/chatting/Util.kt | 20 ++++++-- .../chatting/component/ChatComponent.kt | 51 ++++++++++++------- .../chatting/component/ChatLineComponent.kt | 44 +++++++++++----- .../chatting/component/LegacyComponent.kt | 11 ++++ src/main/resources/mixins.chatting.json | 3 +- 8 files changed, 136 insertions(+), 41 deletions(-) create mode 100644 src/main/java/org/polyfrost/chatting/mixin/ScreenPlatformImplMixin.java create mode 100644 src/main/kotlin/org/polyfrost/chatting/component/LegacyComponent.kt diff --git a/src/main/java/org/polyfrost/chatting/mixin/ScreenPlatformImplMixin.java b/src/main/java/org/polyfrost/chatting/mixin/ScreenPlatformImplMixin.java new file mode 100644 index 0000000..cf1b3b0 --- /dev/null +++ b/src/main/java/org/polyfrost/chatting/mixin/ScreenPlatformImplMixin.java @@ -0,0 +1,22 @@ +package org.polyfrost.chatting.mixin; + +import dev.deftu.omnicore.client.render.OmniMatrixStack; +import org.polyfrost.chatting.Util; +import org.polyfrost.oneconfig.api.platform.v1.internal.ScreenPlatformImpl; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(value = ScreenPlatformImpl.class, remap = false) +public class ScreenPlatformImplMixin { + + @Shadow + private OmniMatrixStack smuggled; + + @Inject(method = "renderLegacyHuds", at = @At("HEAD")) + private void renderLegacy(CallbackInfo ci) { + Util.renderLegacy(smuggled); + } +} \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/chatting/ChatWindow.kt b/src/main/kotlin/org/polyfrost/chatting/ChatWindow.kt index b5e28b3..78ae918 100644 --- a/src/main/kotlin/org/polyfrost/chatting/ChatWindow.kt +++ b/src/main/kotlin/org/polyfrost/chatting/ChatWindow.kt @@ -1,13 +1,16 @@ package org.polyfrost.chatting +import net.minecraft.client.gui.screen.ChatScreen import org.polyfrost.chatting.component.ChatComponent import org.polyfrost.chatting.component.ChatLineComponent import org.polyfrost.oneconfig.api.hud.v1.Hud +import org.polyfrost.oneconfig.utils.v1.dsl.mc import org.polyfrost.polyui.component.Drawable import org.polyfrost.polyui.component.impl.Text import org.polyfrost.polyui.unit.milliseconds +import kotlin.math.pow -class ChatWindow(preview: Boolean) : Hud(id = "chat.yml", title = "Chat", category = Category.INFO) { +class ChatWindow(preview: Boolean = false) : Hud(id = "chat.yml", title = "Chat", category = Category.INFO) { var isPreview = preview @@ -16,7 +19,7 @@ class ChatWindow(preview: Boolean) : Hud(id = "chat.yml", title = "Cha } override fun create(): Drawable { - return if (isPreview) Text("Chat", fontSize = 32f) else ChatComponent() + return if (isPreview) Text("Chat", fontSize = 32f) else ChatComponent(this) } override fun updateFrequency(): Long { @@ -26,10 +29,23 @@ class ChatWindow(preview: Boolean) : Hud(id = "chat.yml", title = "Cha override fun update(): Boolean { if (get() is Text) return false get().width = (320 + 12) * mcScale + var index = 0 + val inChatScreen = mc.currentScreen != null && mc.currentScreen is ChatScreen val size = get().children!!.count { val creationTick = (it as ChatLineComponent).visible.comp_895 - val canRender = inChatScreen || creationTick == -1 || creationTick >= 200 + val fullOpacity = inChatScreen || creationTick == -1 + (mc.inGameHud.ticks - creationTick) / 200f + val canRender = fullOpacity || mc.inGameHud.ticks - creationTick <= 200 it.renders = canRender + if (canRender) { + it.opacity = if (fullOpacity) { + 1f + } else { + Math.clamp(10 - (mc.inGameHud.ticks - creationTick) / 20f, 0f, 1f).pow(2) + } + it.index = index + index++ + } return@count canRender } get().height = size * 9 * mcScale diff --git a/src/main/kotlin/org/polyfrost/chatting/ModConfig.kt b/src/main/kotlin/org/polyfrost/chatting/ModConfig.kt index 709388d..9211248 100644 --- a/src/main/kotlin/org/polyfrost/chatting/ModConfig.kt +++ b/src/main/kotlin/org/polyfrost/chatting/ModConfig.kt @@ -63,9 +63,9 @@ object ModConfig : Config("${ModConstants.ID}.json", ModConstants.NAME, Category @RadioButton( title = "Peek Mode", - options = ["Helod", "Toggle"] + options = ["Held", "Toggle"] ) - var peekMode = false + var peekMode = 0 @Switch( title = "Underlined Links", category = "General", diff --git a/src/main/kotlin/org/polyfrost/chatting/Util.kt b/src/main/kotlin/org/polyfrost/chatting/Util.kt index 67f39a6..c2186cc 100644 --- a/src/main/kotlin/org/polyfrost/chatting/Util.kt +++ b/src/main/kotlin/org/polyfrost/chatting/Util.kt @@ -1,12 +1,24 @@ @file:JvmName("Util") package org.polyfrost.chatting +import dev.deftu.omnicore.client.render.OmniMatrixStack import dev.deftu.omnicore.client.render.OmniResolution -import net.minecraft.client.gui.screen.ChatScreen -import org.polyfrost.oneconfig.utils.v1.dsl.mc +import org.polyfrost.chatting.component.LegacyComponent val mcScale get() = OmniResolution.scaleFactor.toFloat() -val inChatScreen: Boolean - get() = mc.currentScreen != null && mc.currentScreen is ChatScreen +var legacyComponents = ArrayList() + +fun renderLegacy(matrixStack: OmniMatrixStack) { + val removeQueue = mutableListOf() + for (component in legacyComponents) { + component.render(matrixStack) + if (component.remove) { + removeQueue.add(component) + } + } + removeQueue.forEach { + legacyComponents.remove(it) + } +} \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/chatting/component/ChatComponent.kt b/src/main/kotlin/org/polyfrost/chatting/component/ChatComponent.kt index 5254f2a..011b5eb 100644 --- a/src/main/kotlin/org/polyfrost/chatting/component/ChatComponent.kt +++ b/src/main/kotlin/org/polyfrost/chatting/component/ChatComponent.kt @@ -2,17 +2,18 @@ package org.polyfrost.chatting.component import net.minecraft.client.gui.hud.ChatHudLine import net.minecraft.client.util.ChatMessages +import org.polyfrost.chatting.ChatWindow import org.polyfrost.chatting.event.HudEditorEvent import org.polyfrost.chatting.event.NewMessageEvent import org.polyfrost.chatting.mixin.ChatHudAccessor import org.polyfrost.oneconfig.api.event.v1.eventHandler +import org.polyfrost.oneconfig.api.hud.v1.HudManager import org.polyfrost.oneconfig.utils.v1.dsl.mc import org.polyfrost.polyui.PolyUI -import org.polyfrost.polyui.color.PolyColor -import org.polyfrost.polyui.component.impl.Block -import org.polyfrost.polyui.unit.by +import org.polyfrost.polyui.component.Drawable +import kotlin.math.floor -class ChatComponent : Block(null, color = PolyColor.TRANSPARENT, size = 320f by 32f) { +class ChatComponent(val window: ChatWindow) : Drawable(null) { @Transient val editorMessages = mutableListOf( @@ -22,12 +23,6 @@ class ChatComponent : Block(null, color = PolyColor.TRANSPARENT, size = 320f by "§eDrag me around!" ) - @Transient - var actualX = 0f - - @Transient - var actualY = 0f - init { eventHandler { event: NewMessageEvent -> addMessage(event.message) @@ -40,22 +35,27 @@ class ChatComponent : Block(null, color = PolyColor.TRANSPARENT, size = 320f by fun swap(editing: Boolean) { removeAllMessages() if (editing) { - editorMessages.forEach { message -> - val line = ChatHudLine(-1, net.minecraft.text.Text.literal(message), null, null) - addMessage(line) - } + addExampleText() } else { addAllMessages() } } + fun addExampleText() { + editorMessages.forEach { message -> + val line = ChatHudLine(-1, net.minecraft.text.Text.literal(message), null, null) + addMessage(line) + } + } + fun addAllMessages() { - (mc.inGameHud.chatHud as ChatHudAccessor).messages.forEach { + (mc.inGameHud.chatHud as ChatHudAccessor).messages.reversed().forEach { addMessage(it) } } fun removeAllMessages() { + if (children!!.isEmpty()) return for (i in 0.. Date: Fri, 12 Sep 2025 12:02:15 +0800 Subject: [PATCH 04/30] lunch time --- build.gradle.kts | 2 +- .../mixin/ScreenPlatformImplMixin.java | 22 +++++--- .../org/polyfrost/chatting/ChatWindow.kt | 1 + .../kotlin/org/polyfrost/chatting/Util.kt | 33 +++++++----- .../chatting/component/ChatButton.kt | 13 +++++ .../chatting/component/ChatComponent.kt | 14 +++-- .../chatting/component/ChatLineComponent.kt | 51 +++++++++---------- 7 files changed, 84 insertions(+), 52 deletions(-) create mode 100644 src/main/kotlin/org/polyfrost/chatting/component/ChatButton.kt diff --git a/build.gradle.kts b/build.gradle.kts index 2b0180d..e98331c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -20,7 +20,7 @@ plugins { toolkitLoomHelper { useOneConfig { - version = "1.0.0-alpha.140" + version = "1.0.0-alpha.146" loaderVersion = "1.1.0-alpha.49" for (module in arrayOf("commands", "config", "config-impl", "events", "internal", "ui", "utils")) { diff --git a/src/main/java/org/polyfrost/chatting/mixin/ScreenPlatformImplMixin.java b/src/main/java/org/polyfrost/chatting/mixin/ScreenPlatformImplMixin.java index cf1b3b0..d9fc1ff 100644 --- a/src/main/java/org/polyfrost/chatting/mixin/ScreenPlatformImplMixin.java +++ b/src/main/java/org/polyfrost/chatting/mixin/ScreenPlatformImplMixin.java @@ -1,13 +1,14 @@ package org.polyfrost.chatting.mixin; import dev.deftu.omnicore.client.render.OmniMatrixStack; -import org.polyfrost.chatting.Util; +import org.polyfrost.chatting.component.ChatComponent; +import org.polyfrost.chatting.component.ChatLineComponent; import org.polyfrost.oneconfig.api.platform.v1.internal.ScreenPlatformImpl; +import org.polyfrost.polyui.component.Component; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.ModifyVariable; @Mixin(value = ScreenPlatformImpl.class, remap = false) public class ScreenPlatformImplMixin { @@ -15,8 +16,17 @@ public class ScreenPlatformImplMixin { @Shadow private OmniMatrixStack smuggled; - @Inject(method = "renderLegacyHuds", at = @At("HEAD")) - private void renderLegacy(CallbackInfo ci) { - Util.renderLegacy(smuggled); +@ModifyVariable(method = "renderLegacyHuds", at = @At(value = "STORE", ordinal = 0)) + private Component renderLegacy(Component component) { + if (component instanceof ChatComponent chatComponent) { + if (chatComponent.getChildren() != null) { + for (Component child : chatComponent.getChildren()) { + if (child instanceof ChatLineComponent chatLineComponent) { + chatLineComponent.renderLegacy(smuggled); + } + } + } + } + return component; } } \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/chatting/ChatWindow.kt b/src/main/kotlin/org/polyfrost/chatting/ChatWindow.kt index 78ae918..69aa230 100644 --- a/src/main/kotlin/org/polyfrost/chatting/ChatWindow.kt +++ b/src/main/kotlin/org/polyfrost/chatting/ChatWindow.kt @@ -44,6 +44,7 @@ class ChatWindow(preview: Boolean = false) : Hud(id = "chat.yml", titl Math.clamp(10 - (mc.inGameHud.ticks - creationTick) / 20f, 0f, 1f).pow(2) } it.index = index + it.y = get().y + it.index * 9 * mcScale index++ } return@count canRender diff --git a/src/main/kotlin/org/polyfrost/chatting/Util.kt b/src/main/kotlin/org/polyfrost/chatting/Util.kt index c2186cc..63daa85 100644 --- a/src/main/kotlin/org/polyfrost/chatting/Util.kt +++ b/src/main/kotlin/org/polyfrost/chatting/Util.kt @@ -1,24 +1,29 @@ @file:JvmName("Util") + package org.polyfrost.chatting import dev.deftu.omnicore.client.render.OmniMatrixStack import dev.deftu.omnicore.client.render.OmniResolution -import org.polyfrost.chatting.component.LegacyComponent +import net.minecraft.client.render.RenderLayer +import net.minecraft.util.Identifier +import org.polyfrost.oneconfig.utils.v1.dsl.mc +import java.util.function.Function val mcScale get() = OmniResolution.scaleFactor.toFloat() -var legacyComponents = ArrayList() - -fun renderLegacy(matrixStack: OmniMatrixStack) { - val removeQueue = mutableListOf() - for (component in legacyComponents) { - component.render(matrixStack) - if (component.remove) { - removeQueue.add(component) - } - } - removeQueue.forEach { - legacyComponents.remove(it) - } +private fun OmniMatrixStack.drawTexture(function: Function, identifier: Identifier, x: Int, y: Int, width: Int, height: Int, u: Float, uWidth: Float, v: Float, vHeight: Float, texWidth: Float, texHeight: Float, color: Int) { + val renderLayer = function.apply(identifier) + val matrix4f = this.toVanillaStack().peek().positionMatrix + val vertexConsumer = mc.bufferBuilders.entityVertexConsumers.getBuffer(renderLayer) + val xEnd = (x + width).toFloat() + val yEnd = (y + height).toFloat() + val uStart = u / texWidth + val vStart = v / texHeight + val uEnd = (u + uWidth) / texWidth + val vEnd = (v + vHeight) / texHeight + vertexConsumer.vertex(matrix4f, x.toFloat(), y.toFloat(), 0.0F).texture(uStart, vStart).color(color) + vertexConsumer.vertex(matrix4f, x.toFloat(), yEnd, 0.0F).texture(uStart, vEnd).color(color) + vertexConsumer.vertex(matrix4f, xEnd, yEnd, 0.0F).texture(uEnd, vEnd).color(color) + vertexConsumer.vertex(matrix4f, xEnd, y.toFloat(), 0.0F).texture(uEnd, vStart).color(color) } \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/chatting/component/ChatButton.kt b/src/main/kotlin/org/polyfrost/chatting/component/ChatButton.kt new file mode 100644 index 0000000..119fed1 --- /dev/null +++ b/src/main/kotlin/org/polyfrost/chatting/component/ChatButton.kt @@ -0,0 +1,13 @@ +package org.polyfrost.chatting.component + +import org.polyfrost.chatting.mcScale +import org.polyfrost.polyui.color.rgba +import org.polyfrost.polyui.component.impl.Block +import org.polyfrost.polyui.component.impl.Image +import org.polyfrost.polyui.data.PolyImage +import org.polyfrost.polyui.unit.Vec2 +import org.polyfrost.polyui.unit.by + +class ChatButton(image: PolyImage, at: Vec2): Block(Image(image, at = at.x + mcScale by at.y + mcScale), at = at, size = 9 * mcScale by 9 * mcScale, color = rgba(0, 0, 0, 0.25f)) { + +} \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/chatting/component/ChatComponent.kt b/src/main/kotlin/org/polyfrost/chatting/component/ChatComponent.kt index 011b5eb..7c6aa0a 100644 --- a/src/main/kotlin/org/polyfrost/chatting/component/ChatComponent.kt +++ b/src/main/kotlin/org/polyfrost/chatting/component/ChatComponent.kt @@ -11,9 +11,10 @@ import org.polyfrost.oneconfig.api.hud.v1.HudManager import org.polyfrost.oneconfig.utils.v1.dsl.mc import org.polyfrost.polyui.PolyUI import org.polyfrost.polyui.component.Drawable +import org.polyfrost.polyui.unit.by import kotlin.math.floor -class ChatComponent(val window: ChatWindow) : Drawable(null) { +class ChatComponent(val window: ChatWindow) : Drawable(null, size = 1f by 1f) { @Transient val editorMessages = mutableListOf( @@ -67,10 +68,17 @@ class ChatComponent(val window: ChatWindow) : Drawable(null) { if (icon != null) { i -= icon.width + 4 + 2 } - val lines = ChatMessages.breakRenderedChatMessageLines(message.comp_893(), i, mc.textRenderer) + + val hasHead = false + + if (hasHead) { + i -= 10 + } + + val lines = ChatMessages.breakRenderedChatMessageLines(message.comp_893, i, mc.textRenderer) lines.forEach { - val component = ChatLineComponent(ChatHudLine.Visible(message.creationTick(), it, message.indicator(), it == lines.last()), message) + val component = ChatLineComponent(ChatHudLine.Visible(message.creationTick(), it, message.indicator(), it == lines.last()), message, hasHead) addChild(component, recalculate = false) while(children!!.size > 100) { removeChild(0) diff --git a/src/main/kotlin/org/polyfrost/chatting/component/ChatLineComponent.kt b/src/main/kotlin/org/polyfrost/chatting/component/ChatLineComponent.kt index 361c0cf..eee6539 100644 --- a/src/main/kotlin/org/polyfrost/chatting/component/ChatLineComponent.kt +++ b/src/main/kotlin/org/polyfrost/chatting/component/ChatLineComponent.kt @@ -5,44 +5,40 @@ import dev.deftu.omnicore.client.render.OmniMatrixStack import net.minecraft.client.font.TextRenderer import net.minecraft.client.gui.hud.ChatHudLine import net.minecraft.util.math.ColorHelper -import org.polyfrost.chatting.legacyComponents import org.polyfrost.chatting.mcScale +import org.polyfrost.oneconfig.utils.v1.dsl.mc import org.polyfrost.polyui.color.rgba import org.polyfrost.polyui.component.Drawable import org.polyfrost.polyui.unit.by -import kotlin.math.* +import kotlin.math.ceil +import kotlin.math.roundToInt -class ChatLineComponent(val visible: ChatHudLine.Visible, val fullMessage: ChatHudLine): Drawable(size = (320 + 12) * mcScale by ceil(9 * mcScale)) { +class ChatLineComponent(val visible: ChatHudLine.Visible, val fullMessage: ChatHudLine, val hasHead: Boolean = false): Drawable(size = (320 + 12) * mcScale by ceil(9 * mcScale)) { var index = -1 var opacity = 1f - val textComponent = object : LegacyComponent() { - override fun render(matrixStack: OmniMatrixStack) { - if (this@ChatLineComponent._parent?._parent == null) { - remove = true - return - } - if (!this@ChatLineComponent.renders) return - - val chatComponent = this@ChatLineComponent.parent as Drawable - val textY = chatComponent.y + (9 * index + 1) * mcScale * chatComponent.scaleY - val alpha = (255 * opacity).roundToInt() - - if (alpha <= 3) return - - matrixStack.push() - matrixStack.translate(chatComponent.x / mcScale + 4 * chatComponent.scaleY, textY / mcScale, 0f) - matrixStack.scale(chatComponent.scaleX, chatComponent.scaleY, 1f) - OmniClient.fontRenderer.draw(visible.comp_896, 0f, 0f, ColorHelper.withAlpha(alpha, -1), true, matrixStack.toVanillaStack().peek().positionMatrix, OmniClient.getInstance().bufferBuilders.entityVertexConsumers, TextRenderer.TextLayerType.NORMAL, 0, 15728880) - matrixStack.pop() - } - } - init { color = rgba(0, 0, 0, 0.5f) - legacyComponents.add(textComponent) + } + + fun renderLegacy(matrixStack: OmniMatrixStack) { + if (!renders) return + val chatComponent = this.parent as Drawable + val textY = chatComponent.y + (9 * index + 1) * mcScale * chatComponent.scaleY + val alpha = (255 * opacity).roundToInt() + + if (alpha <= 3) return + matrixStack.push() + matrixStack.translate(x / mcScale + 4 * chatComponent.scaleX, textY / mcScale, 0f) + matrixStack.scale(chatComponent.scaleX, chatComponent.scaleY, 1f) + if (hasHead) { + + matrixStack.translate(10f, 0f, 0f) + } + OmniClient.fontRenderer.draw(visible.comp_896, 0f, 0f, ColorHelper.withAlpha(alpha, -1), true, matrixStack.toVanillaStack().peek().positionMatrix, mc.bufferBuilders.entityVertexConsumers, TextRenderer.TextLayerType.NORMAL, 0, 15728880) + matrixStack.pop() } override fun preRender(delta: Long) { @@ -51,8 +47,7 @@ class ChatLineComponent(val visible: ChatHudLine.Visible, val fullMessage: ChatH } override fun render() { - val renderY = y + index * 9 * mcScale - renderer.rect(x, renderY, width, height, rgba(0, 0, 0, 0.5f * opacity)) + renderer.rect(x, y, width, height, rgba(0, 0, 0, 0.5f * opacity)) } } \ No newline at end of file From af8a71fa74d5c8018c5a5e32086360644c89a34e Mon Sep 17 00:00:00 2001 From: ImToggle Date: Fri, 12 Sep 2025 22:21:34 +0800 Subject: [PATCH 05/30] push cuz im switching to my pc --- .gitignore | 1 - .../chatting/mixin/HudManagerMixin.java | 22 ------------------- .../org/polyfrost/chatting/ChatWindow.kt | 6 ++--- .../chatting/component/ChatComponent.kt | 22 ++++++++++++++----- .../chatting/component/ChatLineComponent.kt | 18 +++++++++++---- .../chatting/event/HudEditorEvent.kt | 6 ----- .../resources/assets/chatting/icon/copy.svg | 4 ++++ src/main/resources/mixins.chatting.json | 1 - 8 files changed, 37 insertions(+), 43 deletions(-) delete mode 100644 src/main/java/org/polyfrost/chatting/mixin/HudManagerMixin.java delete mode 100644 src/main/kotlin/org/polyfrost/chatting/event/HudEditorEvent.kt create mode 100644 src/main/resources/assets/chatting/icon/copy.svg diff --git a/.gitignore b/.gitignore index 6de7fc5..83a75d9 100644 --- a/.gitignore +++ b/.gitignore @@ -316,7 +316,6 @@ replay_pid* .LSOverride # Icon must end with two \r -Icon # Thumbnails diff --git a/src/main/java/org/polyfrost/chatting/mixin/HudManagerMixin.java b/src/main/java/org/polyfrost/chatting/mixin/HudManagerMixin.java deleted file mode 100644 index febed2c..0000000 --- a/src/main/java/org/polyfrost/chatting/mixin/HudManagerMixin.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.polyfrost.chatting.mixin; - -import org.polyfrost.chatting.event.HudEditorEvent; -import org.polyfrost.oneconfig.api.event.v1.EventManager; -import org.polyfrost.oneconfig.api.hud.v1.HudManager; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(value = HudManager.class, remap = false) -public class HudManagerMixin { - - @Shadow - private static boolean panelExists; - - @Inject(method = "toggleHudPicker", at = @At("TAIL")) - private void editor(CallbackInfo ci) { - EventManager.INSTANCE.post(new HudEditorEvent(panelExists)); - } -} diff --git a/src/main/kotlin/org/polyfrost/chatting/ChatWindow.kt b/src/main/kotlin/org/polyfrost/chatting/ChatWindow.kt index 69aa230..6b32564 100644 --- a/src/main/kotlin/org/polyfrost/chatting/ChatWindow.kt +++ b/src/main/kotlin/org/polyfrost/chatting/ChatWindow.kt @@ -7,6 +7,7 @@ import org.polyfrost.oneconfig.api.hud.v1.Hud import org.polyfrost.oneconfig.utils.v1.dsl.mc import org.polyfrost.polyui.component.Drawable import org.polyfrost.polyui.component.impl.Text +import org.polyfrost.polyui.unit.by import org.polyfrost.polyui.unit.milliseconds import kotlin.math.pow @@ -28,7 +29,6 @@ class ChatWindow(preview: Boolean = false) : Hud(id = "chat.yml", titl override fun update(): Boolean { if (get() is Text) return false - get().width = (320 + 12) * mcScale var index = 0 val inChatScreen = mc.currentScreen != null && mc.currentScreen is ChatScreen val size = get().children!!.count { @@ -44,12 +44,12 @@ class ChatWindow(preview: Boolean = false) : Hud(id = "chat.yml", titl Math.clamp(10 - (mc.inGameHud.ticks - creationTick) / 20f, 0f, 1f).pow(2) } it.index = index - it.y = get().y + it.index * 9 * mcScale + it.at = it.x by get().y + it.index * 9 * mcScale * get().scaleY index++ } return@count canRender } - get().height = size * 9 * mcScale + get().size = (320 + 12) * mcScale by size * 9 * mcScale return true } diff --git a/src/main/kotlin/org/polyfrost/chatting/component/ChatComponent.kt b/src/main/kotlin/org/polyfrost/chatting/component/ChatComponent.kt index 7c6aa0a..c1ff2c5 100644 --- a/src/main/kotlin/org/polyfrost/chatting/component/ChatComponent.kt +++ b/src/main/kotlin/org/polyfrost/chatting/component/ChatComponent.kt @@ -1,17 +1,21 @@ package org.polyfrost.chatting.component import net.minecraft.client.gui.hud.ChatHudLine +import net.minecraft.client.gui.screen.ChatScreen import net.minecraft.client.util.ChatMessages import org.polyfrost.chatting.ChatWindow -import org.polyfrost.chatting.event.HudEditorEvent import org.polyfrost.chatting.event.NewMessageEvent import org.polyfrost.chatting.mixin.ChatHudAccessor import org.polyfrost.oneconfig.api.event.v1.eventHandler +import org.polyfrost.oneconfig.api.event.v1.events.MouseInputEvent import org.polyfrost.oneconfig.api.hud.v1.HudManager +import org.polyfrost.oneconfig.api.hud.v1.events.HudEditorToggleEvent +import org.polyfrost.oneconfig.api.ui.v1.UIManager import org.polyfrost.oneconfig.utils.v1.dsl.mc import org.polyfrost.polyui.PolyUI import org.polyfrost.polyui.component.Drawable import org.polyfrost.polyui.unit.by +import org.polyfrost.polyui.utils.fastEach import kotlin.math.floor class ChatComponent(val window: ChatWindow) : Drawable(null, size = 1f by 1f) { @@ -28,8 +32,13 @@ class ChatComponent(val window: ChatWindow) : Drawable(null, size = 1f by 1f) { eventHandler { event: NewMessageEvent -> addMessage(event.message) } - eventHandler { event: HudEditorEvent -> - swap(event.state) + eventHandler { event: HudEditorToggleEvent -> + swap(event.open) + } + eventHandler { event: MouseInputEvent.Moved -> + if (mc.currentScreen != null && mc.currentScreen is ChatScreen) { + UIManager.INSTANCE.defaultInstance.inputManager.mouseMoved(event.x, event.y) + } } } @@ -98,9 +107,10 @@ class ChatComponent(val window: ChatWindow) : Drawable(null, size = 1f by 1f) { } override fun preRender(delta: Long) { - x = floor(x) - y = floor(y) - super.preRender(delta) + children!!.fastEach { + (it as Drawable).scaleX = scaleX + (it as Drawable).scaleY = scaleY + } } override var renders: Boolean diff --git a/src/main/kotlin/org/polyfrost/chatting/component/ChatLineComponent.kt b/src/main/kotlin/org/polyfrost/chatting/component/ChatLineComponent.kt index eee6539..46a830d 100644 --- a/src/main/kotlin/org/polyfrost/chatting/component/ChatLineComponent.kt +++ b/src/main/kotlin/org/polyfrost/chatting/component/ChatLineComponent.kt @@ -9,6 +9,9 @@ import org.polyfrost.chatting.mcScale import org.polyfrost.oneconfig.utils.v1.dsl.mc import org.polyfrost.polyui.color.rgba import org.polyfrost.polyui.component.Drawable +import org.polyfrost.polyui.component.extensions.onHover +import org.polyfrost.polyui.component.extensions.onHoverExit +import org.polyfrost.polyui.operations.Recolor import org.polyfrost.polyui.unit.by import kotlin.math.ceil import kotlin.math.roundToInt @@ -20,19 +23,26 @@ class ChatLineComponent(val visible: ChatHudLine.Visible, val fullMessage: ChatH var opacity = 1f init { + acceptsInput = true color = rgba(0, 0, 0, 0.5f) + onHover { + Recolor(this, rgba(255, 255, 255, 0.5f)) + } + onHoverExit { + Recolor(this, rgba(0, 0, 0, 0.5f)) + } } fun renderLegacy(matrixStack: OmniMatrixStack) { if (!renders) return val chatComponent = this.parent as Drawable - val textY = chatComponent.y + (9 * index + 1) * mcScale * chatComponent.scaleY + val textY = chatComponent.y + (9 * index + 1) * mcScale * scaleY val alpha = (255 * opacity).roundToInt() if (alpha <= 3) return matrixStack.push() - matrixStack.translate(x / mcScale + 4 * chatComponent.scaleX, textY / mcScale, 0f) - matrixStack.scale(chatComponent.scaleX, chatComponent.scaleY, 1f) + matrixStack.translate(x / mcScale + 4 * scaleX, textY / mcScale, 0f) + matrixStack.scale(scaleX, scaleY, 1f) if (hasHead) { matrixStack.translate(10f, 0f, 0f) @@ -47,7 +57,7 @@ class ChatLineComponent(val visible: ChatHudLine.Visible, val fullMessage: ChatH } override fun render() { - renderer.rect(x, y, width, height, rgba(0, 0, 0, 0.5f * opacity)) + renderer.rect(x, y, width, height, color) } } \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/chatting/event/HudEditorEvent.kt b/src/main/kotlin/org/polyfrost/chatting/event/HudEditorEvent.kt deleted file mode 100644 index 0fe5a53..0000000 --- a/src/main/kotlin/org/polyfrost/chatting/event/HudEditorEvent.kt +++ /dev/null @@ -1,6 +0,0 @@ -package org.polyfrost.chatting.event - -import org.polyfrost.oneconfig.api.event.v1.events.Event - -class HudEditorEvent(val state: Boolean) : Event { -} \ No newline at end of file diff --git a/src/main/resources/assets/chatting/icon/copy.svg b/src/main/resources/assets/chatting/icon/copy.svg new file mode 100644 index 0000000..7d517ce --- /dev/null +++ b/src/main/resources/assets/chatting/icon/copy.svg @@ -0,0 +1,4 @@ + + + + diff --git a/src/main/resources/mixins.chatting.json b/src/main/resources/mixins.chatting.json index d1f94ff..2bd970b 100644 --- a/src/main/resources/mixins.chatting.json +++ b/src/main/resources/mixins.chatting.json @@ -12,7 +12,6 @@ ], "verbose": true, "mixins": [ - "HudManagerMixin", "ScreenPlatformImplMixin" ] } From 7b7bd0e333d324660662acc7d034ef1013677a34 Mon Sep 17 00:00:00 2001 From: ImToggle <98242902+ImToggle@users.noreply.github.com> Date: Sun, 14 Sep 2025 17:59:43 +0800 Subject: [PATCH 06/30] enough work for today --- .../chatting/mixin/ChatHudMixin.java | 8 ++ .../mixin/ScreenPlatformImplMixin.java | 32 ------- .../org/polyfrost/chatting/ChatWindow.kt | 86 +++++++++++++++---- .../kotlin/org/polyfrost/chatting/Util.kt | 37 ++++---- .../chatting/component/ChatComponent.kt | 80 ++++++++++++++--- .../chatting/component/ChatLineComponent.kt | 84 +++++++++++++----- .../component/ChatPendingComponent.kt | 18 ++++ src/main/resources/mixins.chatting.json | 5 +- 8 files changed, 241 insertions(+), 109 deletions(-) delete mode 100644 src/main/java/org/polyfrost/chatting/mixin/ScreenPlatformImplMixin.java create mode 100644 src/main/kotlin/org/polyfrost/chatting/component/ChatPendingComponent.kt diff --git a/src/main/java/org/polyfrost/chatting/mixin/ChatHudMixin.java b/src/main/java/org/polyfrost/chatting/mixin/ChatHudMixin.java index a5e7563..2d07a3d 100644 --- a/src/main/java/org/polyfrost/chatting/mixin/ChatHudMixin.java +++ b/src/main/java/org/polyfrost/chatting/mixin/ChatHudMixin.java @@ -1,11 +1,13 @@ package org.polyfrost.chatting.mixin; import com.llamalad7.mixinextras.sugar.Local; +import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.hud.ChatHud; import net.minecraft.client.gui.hud.ChatHudLine; import net.minecraft.client.gui.hud.MessageIndicator; import net.minecraft.network.message.MessageSignatureData; import net.minecraft.text.Text; +import org.polyfrost.chatting.Util; import org.polyfrost.chatting.event.NewMessageEvent; import org.polyfrost.oneconfig.api.event.v1.EventManager; import org.spongepowered.asm.mixin.Mixin; @@ -16,6 +18,12 @@ @Mixin(ChatHud.class) public class ChatHudMixin { + @Inject(method = "render", at = @At("HEAD"), cancellable = true) + private void onRender(DrawContext drawContext, int i, int j, int k, boolean bl, CallbackInfo ci) { + Util.renderLegacy(drawContext); +// ci.cancel(); + } + @Inject(method = "addMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignatureData;Lnet/minecraft/client/gui/hud/MessageIndicator;)V", at = @At("TAIL")) private void createMessage(Text text, MessageSignatureData messageSignatureData, MessageIndicator messageIndicator, CallbackInfo ci, @Local(ordinal = 0) ChatHudLine chatHudLine) { EventManager.INSTANCE.post(new NewMessageEvent(chatHudLine)); diff --git a/src/main/java/org/polyfrost/chatting/mixin/ScreenPlatformImplMixin.java b/src/main/java/org/polyfrost/chatting/mixin/ScreenPlatformImplMixin.java deleted file mode 100644 index d9fc1ff..0000000 --- a/src/main/java/org/polyfrost/chatting/mixin/ScreenPlatformImplMixin.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.polyfrost.chatting.mixin; - -import dev.deftu.omnicore.client.render.OmniMatrixStack; -import org.polyfrost.chatting.component.ChatComponent; -import org.polyfrost.chatting.component.ChatLineComponent; -import org.polyfrost.oneconfig.api.platform.v1.internal.ScreenPlatformImpl; -import org.polyfrost.polyui.component.Component; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.ModifyVariable; - -@Mixin(value = ScreenPlatformImpl.class, remap = false) -public class ScreenPlatformImplMixin { - - @Shadow - private OmniMatrixStack smuggled; - -@ModifyVariable(method = "renderLegacyHuds", at = @At(value = "STORE", ordinal = 0)) - private Component renderLegacy(Component component) { - if (component instanceof ChatComponent chatComponent) { - if (chatComponent.getChildren() != null) { - for (Component child : chatComponent.getChildren()) { - if (child instanceof ChatLineComponent chatLineComponent) { - chatLineComponent.renderLegacy(smuggled); - } - } - } - } - return component; - } -} \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/chatting/ChatWindow.kt b/src/main/kotlin/org/polyfrost/chatting/ChatWindow.kt index 6b32564..11037c3 100644 --- a/src/main/kotlin/org/polyfrost/chatting/ChatWindow.kt +++ b/src/main/kotlin/org/polyfrost/chatting/ChatWindow.kt @@ -3,18 +3,53 @@ package org.polyfrost.chatting import net.minecraft.client.gui.screen.ChatScreen import org.polyfrost.chatting.component.ChatComponent import org.polyfrost.chatting.component.ChatLineComponent +import org.polyfrost.oneconfig.api.config.v1.Tree +import org.polyfrost.oneconfig.api.config.v1.annotations.Color import org.polyfrost.oneconfig.api.hud.v1.Hud +import org.polyfrost.oneconfig.api.hud.v1.HudManager import org.polyfrost.oneconfig.utils.v1.dsl.mc +import org.polyfrost.polyui.color.asMutable +import org.polyfrost.polyui.color.rgba import org.polyfrost.polyui.component.Drawable import org.polyfrost.polyui.component.impl.Text import org.polyfrost.polyui.unit.by import org.polyfrost.polyui.unit.milliseconds +import org.polyfrost.polyui.utils.fastEach import kotlin.math.pow class ChatWindow(preview: Boolean = false) : Hud(id = "chat.yml", title = "Chat", category = Category.INFO) { + @Color( + title = "Background Color" + ) + var bgColor = rgba(0, 0, 0, 0.5f).asMutable() + + @Color( + title = "Hovered Background Color" + ) + var bgColor_hovered = rgba(255, 255, 255, 0.5f).asMutable() + var isPreview = preview + override fun addCallbacks(tree: Tree) { + super.addCallbacks(tree) + tree.getProp("bgColor")?.addCallback { + refreshColor() + false + } + tree.getProp("bgColor_hovered")?.addCallback { + refreshColor() + false + } + } + + fun refreshColor() { + if (isPreview) return + get().children!!.fastEach { + (it as ChatLineComponent).refreshColor() + } + } + override fun clone(): Hud { return (super.clone() as ChatWindow).apply { isPreview = false } } @@ -29,27 +64,42 @@ class ChatWindow(preview: Boolean = false) : Hud(id = "chat.yml", titl override fun update(): Boolean { if (get() is Text) return false - var index = 0 - val inChatScreen = mc.currentScreen != null && mc.currentScreen is ChatScreen - val size = get().children!!.count { - val creationTick = (it as ChatLineComponent).visible.comp_895 - val fullOpacity = inChatScreen || creationTick == -1 - (mc.inGameHud.ticks - creationTick) / 200f - val canRender = fullOpacity || mc.inGameHud.ticks - creationTick <= 200 - it.renders = canRender - if (canRender) { - it.opacity = if (fullOpacity) { - 1f - } else { - Math.clamp(10 - (mc.inGameHud.ticks - creationTick) / 20f, 0f, 1f).pow(2) + with(get() as ChatComponent) { + var index = 0 + val inChatScreen = mc.currentScreen != null && mc.currentScreen is ChatScreen + val pendingCount = mc.messageHandler.unprocessedMessageCount + val hasPending = pendingCount > 0L && !HudManager.panelExists + if (hasPending != this.hasPending) { + handleDelay(hasPending) + } + if (hasPending) { + + } + val size = children!!.count { + val creationTick = (it as ChatLineComponent).visible?.comp_895 ?: -1 + val fullOpacity = inChatScreen || creationTick == -1 + (mc.inGameHud.ticks - creationTick) / 200f + val canRender = fullOpacity || mc.inGameHud.ticks - creationTick <= 200 + if (it.selected && !inChatScreen && !HudManager.panelExists) { + it.selected = false + it.refreshColor() + } + it.renders = canRender + if (canRender) { + it.opacity = if (fullOpacity) { + 1f + } else { + Math.clamp(10 - (mc.inGameHud.ticks - creationTick) / 20f, 0f, 1f).pow(2) + } + it.index = index + it.update(true) + index++ } - it.index = index - it.at = it.x by get().y + it.index * 9 * mcScale * get().scaleY - index++ + return@count canRender } - return@count canRender + this.size = (320 + 12) * mcScale by size * 9 * mcScale } - get().size = (320 + 12) * mcScale by size * 9 * mcScale + return true } diff --git a/src/main/kotlin/org/polyfrost/chatting/Util.kt b/src/main/kotlin/org/polyfrost/chatting/Util.kt index 63daa85..5a6dab2 100644 --- a/src/main/kotlin/org/polyfrost/chatting/Util.kt +++ b/src/main/kotlin/org/polyfrost/chatting/Util.kt @@ -2,28 +2,27 @@ package org.polyfrost.chatting -import dev.deftu.omnicore.client.render.OmniMatrixStack import dev.deftu.omnicore.client.render.OmniResolution -import net.minecraft.client.render.RenderLayer -import net.minecraft.util.Identifier -import org.polyfrost.oneconfig.utils.v1.dsl.mc -import java.util.function.Function +import net.minecraft.client.gui.DrawContext +import org.polyfrost.chatting.component.ChatComponent +import org.polyfrost.chatting.component.ChatLineComponent +import org.polyfrost.oneconfig.api.ui.v1.UIManager +import org.polyfrost.polyui.component.Component +import org.polyfrost.polyui.utils.fastEach val mcScale get() = OmniResolution.scaleFactor.toFloat() -private fun OmniMatrixStack.drawTexture(function: Function, identifier: Identifier, x: Int, y: Int, width: Int, height: Int, u: Float, uWidth: Float, v: Float, vHeight: Float, texWidth: Float, texHeight: Float, color: Int) { - val renderLayer = function.apply(identifier) - val matrix4f = this.toVanillaStack().peek().positionMatrix - val vertexConsumer = mc.bufferBuilders.entityVertexConsumers.getBuffer(renderLayer) - val xEnd = (x + width).toFloat() - val yEnd = (y + height).toFloat() - val uStart = u / texWidth - val vStart = v / texHeight - val uEnd = (u + uWidth) / texWidth - val vEnd = (v + vHeight) / texHeight - vertexConsumer.vertex(matrix4f, x.toFloat(), y.toFloat(), 0.0F).texture(uStart, vStart).color(color) - vertexConsumer.vertex(matrix4f, x.toFloat(), yEnd, 0.0F).texture(uStart, vEnd).color(color) - vertexConsumer.vertex(matrix4f, xEnd, yEnd, 0.0F).texture(uEnd, vEnd).color(color) - vertexConsumer.vertex(matrix4f, xEnd, y.toFloat(), 0.0F).texture(uEnd, vStart).color(color) +fun renderLegacy(drawContext: DrawContext) { + val master = UIManager.INSTANCE.defaultInstance.master + val children: ArrayList? = master.children + if (children == null || children.isEmpty()) return + + children.fastEach { child -> + if (child is ChatComponent) { + child.children!!.fastEach { + (it as ChatLineComponent).renderLegacy(drawContext) + } + } + } } \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/chatting/component/ChatComponent.kt b/src/main/kotlin/org/polyfrost/chatting/component/ChatComponent.kt index c1ff2c5..0e72bff 100644 --- a/src/main/kotlin/org/polyfrost/chatting/component/ChatComponent.kt +++ b/src/main/kotlin/org/polyfrost/chatting/component/ChatComponent.kt @@ -3,8 +3,10 @@ package org.polyfrost.chatting.component import net.minecraft.client.gui.hud.ChatHudLine import net.minecraft.client.gui.screen.ChatScreen import net.minecraft.client.util.ChatMessages +import net.minecraft.text.Text import org.polyfrost.chatting.ChatWindow import org.polyfrost.chatting.event.NewMessageEvent +import org.polyfrost.chatting.mcScale import org.polyfrost.chatting.mixin.ChatHudAccessor import org.polyfrost.oneconfig.api.event.v1.eventHandler import org.polyfrost.oneconfig.api.event.v1.events.MouseInputEvent @@ -16,7 +18,8 @@ import org.polyfrost.polyui.PolyUI import org.polyfrost.polyui.component.Drawable import org.polyfrost.polyui.unit.by import org.polyfrost.polyui.utils.fastEach -import kotlin.math.floor +import kotlin.math.round +import kotlin.math.roundToInt class ChatComponent(val window: ChatWindow) : Drawable(null, size = 1f by 1f) { @@ -28,6 +31,18 @@ class ChatComponent(val window: ChatWindow) : Drawable(null, size = 1f by 1f) { "§eDrag me around!" ) + var lastX = -1f + + var lastY = -1f + + var lastScaleX = -1f + + var lastScaleY = -1f + + var lineHeight = 0 + + var hasPending = false + init { eventHandler { event: NewMessageEvent -> addMessage(event.message) @@ -42,6 +57,15 @@ class ChatComponent(val window: ChatWindow) : Drawable(null, size = 1f by 1f) { } } + fun handleDelay(pending: Boolean) { + if (pending) { + addChild(ChatPendingComponent(window)) + } else { + removeChild(children!!.size - 1) + } + hasPending = pending + } + fun swap(editing: Boolean) { removeAllMessages() if (editing) { @@ -53,7 +77,7 @@ class ChatComponent(val window: ChatWindow) : Drawable(null, size = 1f by 1f) { fun addExampleText() { editorMessages.forEach { message -> - val line = ChatHudLine(-1, net.minecraft.text.Text.literal(message), null, null) + val line = ChatHudLine(-1, Text.literal(message), null, null) addMessage(line) } } @@ -69,6 +93,7 @@ class ChatComponent(val window: ChatWindow) : Drawable(null, size = 1f by 1f) { for (i in 0.. 100) { - removeChild(0) + removeChild(0, recalculate = false) } } + + pendingComponent?.let { addChild(it, recalculate = false) } + window.update() } + override var renders: Boolean + get() = super.renders && !children.isNullOrEmpty() + set(value) { + super.renders = value + } + override fun setup(polyUI: PolyUI): Boolean { return super.setup(polyUI).also { if (HudManager.panelExists) { @@ -107,17 +145,33 @@ class ChatComponent(val window: ChatWindow) : Drawable(null, size = 1f by 1f) { } override fun preRender(delta: Long) { - children!!.fastEach { - (it as Drawable).scaleX = scaleX - (it as Drawable).scaleY = scaleY + var updateSize = false + var update = false + if (x != lastX || y != lastY) { + x = round(x) + y = round(y) + lastX = x + lastY = y + update = true } - } - - override var renders: Boolean - get() = super.renders && !children.isNullOrEmpty() - set(value) { - super.renders = value + if (scaleX != lastScaleX || scaleY != lastScaleY) { + lastScaleX = scaleX + lastScaleY = scaleY + lineHeight = (9 * mcScale * scaleY).roundToInt() + update = true + updateSize = true } + if (update) { + children!!.fastEach { + (it as ChatLineComponent).update(updateSize) + } + } + scaleX = 1f + scaleY = 1f + super.preRender(delta) + scaleX = lastScaleX + scaleY = lastScaleY + } override fun render() { } diff --git a/src/main/kotlin/org/polyfrost/chatting/component/ChatLineComponent.kt b/src/main/kotlin/org/polyfrost/chatting/component/ChatLineComponent.kt index 46a830d..7c2145f 100644 --- a/src/main/kotlin/org/polyfrost/chatting/component/ChatLineComponent.kt +++ b/src/main/kotlin/org/polyfrost/chatting/component/ChatLineComponent.kt @@ -1,63 +1,101 @@ package org.polyfrost.chatting.component -import dev.deftu.omnicore.client.OmniClient -import dev.deftu.omnicore.client.render.OmniMatrixStack -import net.minecraft.client.font.TextRenderer +import net.minecraft.client.gui.DrawContext import net.minecraft.client.gui.hud.ChatHudLine +import net.minecraft.text.OrderedText import net.minecraft.util.math.ColorHelper +import org.polyfrost.chatting.ChatWindow import org.polyfrost.chatting.mcScale import org.polyfrost.oneconfig.utils.v1.dsl.mc -import org.polyfrost.polyui.color.rgba import org.polyfrost.polyui.component.Drawable import org.polyfrost.polyui.component.extensions.onHover import org.polyfrost.polyui.component.extensions.onHoverExit -import org.polyfrost.polyui.operations.Recolor import org.polyfrost.polyui.unit.by import kotlin.math.ceil import kotlin.math.roundToInt -class ChatLineComponent(val visible: ChatHudLine.Visible, val fullMessage: ChatHudLine, val hasHead: Boolean = false): Drawable(size = (320 + 12) * mcScale by ceil(9 * mcScale)) { +open class ChatLineComponent(val window: ChatWindow, val visible: ChatHudLine.Visible? = null, val fullMessage: ChatHudLine? = null, val hasHead: Boolean = false): Drawable(size = (320 + 12) * mcScale by ceil(9 * mcScale)) { var index = -1 var opacity = 1f + var mAlpha = 0 + + var bgColor = window.bgColor + + var selected = false + init { acceptsInput = true - color = rgba(0, 0, 0, 0.5f) + onHover { - Recolor(this, rgba(255, 255, 255, 0.5f)) + selected = true + bgColor = window.bgColor_hovered } onHoverExit { - Recolor(this, rgba(0, 0, 0, 0.5f)) + selected = false + bgColor = window.bgColor } } - fun renderLegacy(matrixStack: OmniMatrixStack) { + fun refreshColor() { + bgColor = if (selected) { + window.bgColor_hovered + } else { + window.bgColor + } + } + + fun renderLegacy(drawContext: DrawContext) { if (!renders) return + val text = getText() ?: return val chatComponent = this.parent as Drawable - val textY = chatComponent.y + (9 * index + 1) * mcScale * scaleY - val alpha = (255 * opacity).roundToInt() - if (alpha <= 3) return - matrixStack.push() - matrixStack.translate(x / mcScale + 4 * scaleX, textY / mcScale, 0f) - matrixStack.scale(scaleX, scaleY, 1f) + if (mAlpha <= 3) return + val matrices = drawContext.matrices + matrices.push() + matrices.translate(x / mcScale, y / mcScale, 0f) + matrices.scale(chatComponent.scaleX, chatComponent.scaleY, 1f) if (hasHead) { + matrices.translate(10f, 0f, 0f) + } - matrixStack.translate(10f, 0f, 0f) + val indicator = visible?.indicator + if (indicator != null) { + val c = indicator.comp_899() or (mAlpha shl 24) + drawContext.fill(0, 0, 2, 9, c) } - OmniClient.fontRenderer.draw(visible.comp_896, 0f, 0f, ColorHelper.withAlpha(alpha, -1), true, matrixStack.toVanillaStack().peek().positionMatrix, mc.bufferBuilders.entityVertexConsumers, TextRenderer.TextLayerType.NORMAL, 0, 15728880) - matrixStack.pop() + + drawContext.drawTextWithShadow(mc.textRenderer, text, 4, 1, getTextColor()) + + matrices.pop() + } + + open fun getText(): OrderedText? { + return visible?.comp_896 } - override fun preRender(delta: Long) { - size = (320 + 12) * mcScale by ceil(9 * mcScale) - super.preRender(delta) + open fun getTextColor(): Int { + return ColorHelper.withAlpha(mAlpha, -1) + } + + fun update(size: Boolean) { + val parent = parent as ChatComponent + at = parent.x by parent.y + parent.lineHeight * index + if (size) { + width = parent.width * parent.scaleX + height = parent.lineHeight.toFloat() + } } override fun render() { - renderer.rect(x, y, width, height, color) + mAlpha = (opacity * 255).roundToInt() + if (mAlpha <= 3) return + val alphaTemp = bgColor.alpha + bgColor.alpha *= opacity + renderer.rect(x, y, width, height, bgColor) + bgColor.alpha = alphaTemp } } \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/chatting/component/ChatPendingComponent.kt b/src/main/kotlin/org/polyfrost/chatting/component/ChatPendingComponent.kt new file mode 100644 index 0000000..cbb4978 --- /dev/null +++ b/src/main/kotlin/org/polyfrost/chatting/component/ChatPendingComponent.kt @@ -0,0 +1,18 @@ +package org.polyfrost.chatting.component + +import net.minecraft.text.OrderedText +import net.minecraft.text.Text +import org.polyfrost.chatting.ChatWindow +import org.polyfrost.oneconfig.utils.v1.dsl.mc + +class ChatPendingComponent(window: ChatWindow): ChatLineComponent(window) { + + override fun getText(): OrderedText? { + return Text.translatable("chat.queue", mc.messageHandler.unprocessedMessageCount).asOrderedText() + } + + override fun getTextColor(): Int { + return 16777215 + (128 shl 24) + } + +} \ No newline at end of file diff --git a/src/main/resources/mixins.chatting.json b/src/main/resources/mixins.chatting.json index 2bd970b..6232be2 100644 --- a/src/main/resources/mixins.chatting.json +++ b/src/main/resources/mixins.chatting.json @@ -10,8 +10,5 @@ "ChatHudAccessor", "ChatHudMixin" ], - "verbose": true, - "mixins": [ - "ScreenPlatformImplMixin" - ] + "verbose": true } From 2794f5808484a878401ccbe1d77eb50145ad47c7 Mon Sep 17 00:00:00 2001 From: ImToggle <98242902+ImToggle@users.noreply.github.com> Date: Sun, 14 Sep 2025 20:34:31 +0800 Subject: [PATCH 07/30] rounded --- .../org/polyfrost/chatting/ChatWindow.kt | 15 +++++++++----- .../chatting/component/ChatComponent.kt | 9 +++++---- .../chatting/component/ChatLineComponent.kt | 20 ++++++++++++------- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/main/kotlin/org/polyfrost/chatting/ChatWindow.kt b/src/main/kotlin/org/polyfrost/chatting/ChatWindow.kt index 11037c3..1c12420 100644 --- a/src/main/kotlin/org/polyfrost/chatting/ChatWindow.kt +++ b/src/main/kotlin/org/polyfrost/chatting/ChatWindow.kt @@ -5,6 +5,7 @@ import org.polyfrost.chatting.component.ChatComponent import org.polyfrost.chatting.component.ChatLineComponent import org.polyfrost.oneconfig.api.config.v1.Tree import org.polyfrost.oneconfig.api.config.v1.annotations.Color +import org.polyfrost.oneconfig.api.config.v1.annotations.Slider import org.polyfrost.oneconfig.api.hud.v1.Hud import org.polyfrost.oneconfig.api.hud.v1.HudManager import org.polyfrost.oneconfig.utils.v1.dsl.mc @@ -22,12 +23,19 @@ class ChatWindow(preview: Boolean = false) : Hud(id = "chat.yml", titl @Color( title = "Background Color" ) - var bgColor = rgba(0, 0, 0, 0.5f).asMutable() + var bgColor = rgba(0, 0, 0, 0.5f) @Color( title = "Hovered Background Color" ) - var bgColor_hovered = rgba(255, 255, 255, 0.5f).asMutable() + var bgColor_hovered = rgba(255, 255, 255, 0.5f) + + @Slider( + title = "Corner Radius", + min = 0f, + max = 10f, + ) + var cornerRadius = 4f var isPreview = preview @@ -71,9 +79,6 @@ class ChatWindow(preview: Boolean = false) : Hud(id = "chat.yml", titl val hasPending = pendingCount > 0L && !HudManager.panelExists if (hasPending != this.hasPending) { handleDelay(hasPending) - } - if (hasPending) { - } val size = children!!.count { val creationTick = (it as ChatLineComponent).visible?.comp_895 ?: -1 diff --git a/src/main/kotlin/org/polyfrost/chatting/component/ChatComponent.kt b/src/main/kotlin/org/polyfrost/chatting/component/ChatComponent.kt index 0e72bff..30bfbea 100644 --- a/src/main/kotlin/org/polyfrost/chatting/component/ChatComponent.kt +++ b/src/main/kotlin/org/polyfrost/chatting/component/ChatComponent.kt @@ -45,6 +45,7 @@ class ChatComponent(val window: ChatWindow) : Drawable(null, size = 1f by 1f) { init { eventHandler { event: NewMessageEvent -> + if (HudManager.panelExists) return@eventHandler addMessage(event.message) } eventHandler { event: HudEditorToggleEvent -> @@ -113,17 +114,17 @@ class ChatComponent(val window: ChatWindow) : Drawable(null, size = 1f by 1f) { val pendingComponent = if (hasPending) children!!.last() else null - pendingComponent?.let { removeChild(it, recalculate = false) } + pendingComponent?.let { removeChild(it) } lines.forEach { val component = ChatLineComponent(window, ChatHudLine.Visible(message.creationTick(), it, message.indicator(), it == lines.last()), message, hasHead) - addChild(component, recalculate = false) + addChild(component) while(children!!.size > 100) { - removeChild(0, recalculate = false) + removeChild(0) } } - pendingComponent?.let { addChild(it, recalculate = false) } + pendingComponent?.let { addChild(it) } window.update() } diff --git a/src/main/kotlin/org/polyfrost/chatting/component/ChatLineComponent.kt b/src/main/kotlin/org/polyfrost/chatting/component/ChatLineComponent.kt index 7c2145f..2c13db9 100644 --- a/src/main/kotlin/org/polyfrost/chatting/component/ChatLineComponent.kt +++ b/src/main/kotlin/org/polyfrost/chatting/component/ChatLineComponent.kt @@ -7,11 +7,13 @@ import net.minecraft.util.math.ColorHelper import org.polyfrost.chatting.ChatWindow import org.polyfrost.chatting.mcScale import org.polyfrost.oneconfig.utils.v1.dsl.mc +import org.polyfrost.polyui.color.asMutable import org.polyfrost.polyui.component.Drawable import org.polyfrost.polyui.component.extensions.onHover import org.polyfrost.polyui.component.extensions.onHoverExit import org.polyfrost.polyui.unit.by import kotlin.math.ceil +import kotlin.math.min import kotlin.math.roundToInt open class ChatLineComponent(val window: ChatWindow, val visible: ChatHudLine.Visible? = null, val fullMessage: ChatHudLine? = null, val hasHead: Boolean = false): Drawable(size = (320 + 12) * mcScale by ceil(9 * mcScale)) { @@ -22,28 +24,27 @@ open class ChatLineComponent(val window: ChatWindow, val visible: ChatHudLine.Vi var mAlpha = 0 - var bgColor = window.bgColor + var bgColor = window.bgColor.asMutable() var selected = false init { acceptsInput = true - onHover { selected = true - bgColor = window.bgColor_hovered + bgColor = window.bgColor_hovered.asMutable() } onHoverExit { selected = false - bgColor = window.bgColor + bgColor = window.bgColor.asMutable() } } fun refreshColor() { bgColor = if (selected) { - window.bgColor_hovered + window.bgColor_hovered.asMutable() } else { - window.bgColor + window.bgColor.asMutable() } } @@ -94,7 +95,12 @@ open class ChatLineComponent(val window: ChatWindow, val visible: ChatHudLine.Vi if (mAlpha <= 3) return val alphaTemp = bgColor.alpha bgColor.alpha *= opacity - renderer.rect(x, y, width, height, bgColor) + val parent = parent as ChatComponent + val hudScale = min(parent.scaleX, parent.scaleY) + val topRadius = if (this.index == 0) window.cornerRadius * hudScale else 0f + val bottomRadius = if (this.index == parent.children!!.size - 1) window.cornerRadius * hudScale else 0f + val radii = floatArrayOf(topRadius, topRadius, bottomRadius, bottomRadius) + renderer.rect(x, y, width, height, bgColor, radii) bgColor.alpha = alphaTemp } From 3ebc6e04ef54ae1d1e3ba97b448e0affa514503e Mon Sep 17 00:00:00 2001 From: ImToggle <98242902+ImToggle@users.noreply.github.com> Date: Sun, 14 Sep 2025 21:06:14 +0800 Subject: [PATCH 08/30] lines limit --- .../org/polyfrost/chatting/ChatWindow.kt | 27 ++++++++++++++----- .../chatting/component/ChatLineComponent.kt | 2 +- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/org/polyfrost/chatting/ChatWindow.kt b/src/main/kotlin/org/polyfrost/chatting/ChatWindow.kt index 1c12420..72d9d9e 100644 --- a/src/main/kotlin/org/polyfrost/chatting/ChatWindow.kt +++ b/src/main/kotlin/org/polyfrost/chatting/ChatWindow.kt @@ -9,13 +9,13 @@ import org.polyfrost.oneconfig.api.config.v1.annotations.Slider import org.polyfrost.oneconfig.api.hud.v1.Hud import org.polyfrost.oneconfig.api.hud.v1.HudManager import org.polyfrost.oneconfig.utils.v1.dsl.mc -import org.polyfrost.polyui.color.asMutable import org.polyfrost.polyui.color.rgba import org.polyfrost.polyui.component.Drawable import org.polyfrost.polyui.component.impl.Text import org.polyfrost.polyui.unit.by import org.polyfrost.polyui.unit.milliseconds import org.polyfrost.polyui.utils.fastEach +import kotlin.math.min import kotlin.math.pow class ChatWindow(preview: Boolean = false) : Hud(id = "chat.yml", title = "Chat", category = Category.INFO) { @@ -39,6 +39,10 @@ class ChatWindow(preview: Boolean = false) : Hud(id = "chat.yml", titl var isPreview = preview + var indexShifting = 0 + + var length = 0 + override fun addCallbacks(tree: Tree) { super.addCallbacks(tree) tree.getProp("bgColor")?.addCallback { @@ -80,7 +84,7 @@ class ChatWindow(preview: Boolean = false) : Hud(id = "chat.yml", titl if (hasPending != this.hasPending) { handleDelay(hasPending) } - val size = children!!.count { + length = children!!.count { val creationTick = (it as ChatLineComponent).visible?.comp_895 ?: -1 val fullOpacity = inChatScreen || creationTick == -1 (mc.inGameHud.ticks - creationTick) / 200f @@ -96,13 +100,24 @@ class ChatWindow(preview: Boolean = false) : Hud(id = "chat.yml", titl } else { Math.clamp(10 - (mc.inGameHud.ticks - creationTick) / 20f, 0f, 1f).pow(2) } - it.index = index - it.update(true) - index++ } return@count canRender } - this.size = (320 + 12) * mcScale by size * 9 * mcScale + this.size = (320 + 12) * mcScale by min(length, 10) * 9 * mcScale + indexShifting = if (length > 10) length - 10 else 0 + children!!.fastEach { + if (it.renders) { + it as ChatLineComponent + val newIndex = index - indexShifting + if (newIndex < 0) { + it.renders = false + } else { + it.index = newIndex + it.update(true) + } + index++ + } + } } return true diff --git a/src/main/kotlin/org/polyfrost/chatting/component/ChatLineComponent.kt b/src/main/kotlin/org/polyfrost/chatting/component/ChatLineComponent.kt index 2c13db9..33925fc 100644 --- a/src/main/kotlin/org/polyfrost/chatting/component/ChatLineComponent.kt +++ b/src/main/kotlin/org/polyfrost/chatting/component/ChatLineComponent.kt @@ -98,7 +98,7 @@ open class ChatLineComponent(val window: ChatWindow, val visible: ChatHudLine.Vi val parent = parent as ChatComponent val hudScale = min(parent.scaleX, parent.scaleY) val topRadius = if (this.index == 0) window.cornerRadius * hudScale else 0f - val bottomRadius = if (this.index == parent.children!!.size - 1) window.cornerRadius * hudScale else 0f + val bottomRadius = if (this.index == window.length - 1) window.cornerRadius * hudScale else 0f val radii = floatArrayOf(topRadius, topRadius, bottomRadius, bottomRadius) renderer.rect(x, y, width, height, bgColor, radii) bgColor.alpha = alphaTemp From 3ab8ff8c7698489f6c1b32977e14f7b8ffcf5be1 Mon Sep 17 00:00:00 2001 From: ImToggle Date: Fri, 19 Sep 2025 21:51:10 +0800 Subject: [PATCH 09/30] trying new stuff --- .../org/polyfrost/chatting/ChatWindow.kt | 75 ++------- .../kotlin/org/polyfrost/chatting/Chatting.kt | 18 ++ .../kotlin/org/polyfrost/chatting/Util.kt | 5 +- .../chatting/component/ChatComponent.kt | 159 +++++++++--------- .../chatting/component/ChatLineComponent.kt | 107 ------------ .../chatting/component/ChatLineElement.kt | 20 +++ .../component/ChatPendingComponent.kt | 18 -- 7 files changed, 137 insertions(+), 265 deletions(-) delete mode 100644 src/main/kotlin/org/polyfrost/chatting/component/ChatLineComponent.kt create mode 100644 src/main/kotlin/org/polyfrost/chatting/component/ChatLineElement.kt delete mode 100644 src/main/kotlin/org/polyfrost/chatting/component/ChatPendingComponent.kt diff --git a/src/main/kotlin/org/polyfrost/chatting/ChatWindow.kt b/src/main/kotlin/org/polyfrost/chatting/ChatWindow.kt index 72d9d9e..20210b1 100644 --- a/src/main/kotlin/org/polyfrost/chatting/ChatWindow.kt +++ b/src/main/kotlin/org/polyfrost/chatting/ChatWindow.kt @@ -1,21 +1,16 @@ package org.polyfrost.chatting -import net.minecraft.client.gui.screen.ChatScreen +import dev.deftu.omnicore.client.OmniScreen import org.polyfrost.chatting.component.ChatComponent -import org.polyfrost.chatting.component.ChatLineComponent -import org.polyfrost.oneconfig.api.config.v1.Tree import org.polyfrost.oneconfig.api.config.v1.annotations.Color import org.polyfrost.oneconfig.api.config.v1.annotations.Slider import org.polyfrost.oneconfig.api.hud.v1.Hud -import org.polyfrost.oneconfig.api.hud.v1.HudManager import org.polyfrost.oneconfig.utils.v1.dsl.mc import org.polyfrost.polyui.color.rgba import org.polyfrost.polyui.component.Drawable import org.polyfrost.polyui.component.impl.Text import org.polyfrost.polyui.unit.by import org.polyfrost.polyui.unit.milliseconds -import org.polyfrost.polyui.utils.fastEach -import kotlin.math.min import kotlin.math.pow class ChatWindow(preview: Boolean = false) : Hud(id = "chat.yml", title = "Chat", category = Category.INFO) { @@ -28,40 +23,24 @@ class ChatWindow(preview: Boolean = false) : Hud(id = "chat.yml", titl @Color( title = "Hovered Background Color" ) - var bgColor_hovered = rgba(255, 255, 255, 0.5f) + var bgcolorHovered = rgba(255, 255, 255, 0.5f) + + @Color( + title = "Selected Background Color" + ) + var bgColorSelected = rgba(255, 255, 255, 0.75f) @Slider( title = "Corner Radius", min = 0f, max = 10f, ) - var cornerRadius = 4f + var cornerRadius = 0f var isPreview = preview - var indexShifting = 0 - var length = 0 - override fun addCallbacks(tree: Tree) { - super.addCallbacks(tree) - tree.getProp("bgColor")?.addCallback { - refreshColor() - false - } - tree.getProp("bgColor_hovered")?.addCallback { - refreshColor() - false - } - } - - fun refreshColor() { - if (isPreview) return - get().children!!.fastEach { - (it as ChatLineComponent).refreshColor() - } - } - override fun clone(): Hud { return (super.clone() as ChatWindow).apply { isPreview = false } } @@ -77,47 +56,23 @@ class ChatWindow(preview: Boolean = false) : Hud(id = "chat.yml", titl override fun update(): Boolean { if (get() is Text) return false with(get() as ChatComponent) { - var index = 0 - val inChatScreen = mc.currentScreen != null && mc.currentScreen is ChatScreen - val pendingCount = mc.messageHandler.unprocessedMessageCount - val hasPending = pendingCount > 0L && !HudManager.panelExists - if (hasPending != this.hasPending) { - handleDelay(hasPending) - } - length = children!!.count { - val creationTick = (it as ChatLineComponent).visible?.comp_895 ?: -1 - val fullOpacity = inChatScreen || creationTick == -1 + val inChat = OmniScreen.isInScreen && OmniScreen.isInChat + length = elements.count { + val creationTick = it.visible.comp_895 + val fullOpacity = inChat || creationTick == -1 (mc.inGameHud.ticks - creationTick) / 200f val canRender = fullOpacity || mc.inGameHud.ticks - creationTick <= 200 - if (it.selected && !inChatScreen && !HudManager.panelExists) { - it.selected = false - it.refreshColor() - } it.renders = canRender if (canRender) { it.opacity = if (fullOpacity) { - 1f + 1.0 } else { - Math.clamp(10 - (mc.inGameHud.ticks - creationTick) / 20f, 0f, 1f).pow(2) + Math.clamp(10 - (mc.inGameHud.ticks - creationTick) / 20.0, 0.0, 1.0).pow(2) } } return@count canRender } - this.size = (320 + 12) * mcScale by min(length, 10) * 9 * mcScale - indexShifting = if (length > 10) length - 10 else 0 - children!!.fastEach { - if (it.renders) { - it as ChatLineComponent - val newIndex = index - indexShifting - if (newIndex < 0) { - it.renders = false - } else { - it.index = newIndex - it.update(true) - } - index++ - } - } + this.size = (320 + 12) * mcScale by length * 9 * mcScale } return true diff --git a/src/main/kotlin/org/polyfrost/chatting/Chatting.kt b/src/main/kotlin/org/polyfrost/chatting/Chatting.kt index 779c69c..bfb1ae4 100644 --- a/src/main/kotlin/org/polyfrost/chatting/Chatting.kt +++ b/src/main/kotlin/org/polyfrost/chatting/Chatting.kt @@ -1,8 +1,12 @@ package org.polyfrost.chatting +import dev.deftu.omnicore.client.OmniScreen import net.fabricmc.api.ClientModInitializer import org.polyfrost.oneconfig.api.commands.v1.CommandManager +import org.polyfrost.oneconfig.api.event.v1.eventHandler +import org.polyfrost.oneconfig.api.event.v1.events.MouseInputEvent import org.polyfrost.oneconfig.api.hud.v1.HudManager +import org.polyfrost.oneconfig.api.ui.v1.UIManager object Chatting : ClientModInitializer { @@ -10,6 +14,20 @@ object Chatting : ClientModInitializer { ModConfig.preload() CommandManager.register(ModCommand) HudManager.register(ChatWindow(preview = true)) + eventHandler { event: MouseInputEvent.Moved -> + if (!OmniScreen.isInScreen || !OmniScreen.isInChat) return@eventHandler + UIManager.INSTANCE.defaultInstance.inputManager.mouseMoved(event.x, event.y) + } + eventHandler { event: MouseInputEvent -> + if (!OmniScreen.isInScreen || !OmniScreen.isInChat) return@eventHandler + if (event.state == 0) { + println("released ${event.button}") + UIManager.INSTANCE.defaultInstance.inputManager.mouseReleased(event.button) + } else { + println("pressed ${event.button}") + UIManager.INSTANCE.defaultInstance.inputManager.mousePressed(event.button) + } + } } } diff --git a/src/main/kotlin/org/polyfrost/chatting/Util.kt b/src/main/kotlin/org/polyfrost/chatting/Util.kt index 5a6dab2..84285c5 100644 --- a/src/main/kotlin/org/polyfrost/chatting/Util.kt +++ b/src/main/kotlin/org/polyfrost/chatting/Util.kt @@ -5,7 +5,6 @@ package org.polyfrost.chatting import dev.deftu.omnicore.client.render.OmniResolution import net.minecraft.client.gui.DrawContext import org.polyfrost.chatting.component.ChatComponent -import org.polyfrost.chatting.component.ChatLineComponent import org.polyfrost.oneconfig.api.ui.v1.UIManager import org.polyfrost.polyui.component.Component import org.polyfrost.polyui.utils.fastEach @@ -20,9 +19,7 @@ fun renderLegacy(drawContext: DrawContext) { children.fastEach { child -> if (child is ChatComponent) { - child.children!!.fastEach { - (it as ChatLineComponent).renderLegacy(drawContext) - } + child.renderLegacy(drawContext) } } } \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/chatting/component/ChatComponent.kt b/src/main/kotlin/org/polyfrost/chatting/component/ChatComponent.kt index 30bfbea..d08a9f7 100644 --- a/src/main/kotlin/org/polyfrost/chatting/component/ChatComponent.kt +++ b/src/main/kotlin/org/polyfrost/chatting/component/ChatComponent.kt @@ -1,7 +1,8 @@ package org.polyfrost.chatting.component +import dev.deftu.omnicore.client.OmniMouse +import net.minecraft.client.gui.DrawContext import net.minecraft.client.gui.hud.ChatHudLine -import net.minecraft.client.gui.screen.ChatScreen import net.minecraft.client.util.ChatMessages import net.minecraft.text.Text import org.polyfrost.chatting.ChatWindow @@ -12,14 +13,14 @@ import org.polyfrost.oneconfig.api.event.v1.eventHandler import org.polyfrost.oneconfig.api.event.v1.events.MouseInputEvent import org.polyfrost.oneconfig.api.hud.v1.HudManager import org.polyfrost.oneconfig.api.hud.v1.events.HudEditorToggleEvent -import org.polyfrost.oneconfig.api.ui.v1.UIManager import org.polyfrost.oneconfig.utils.v1.dsl.mc import org.polyfrost.polyui.PolyUI import org.polyfrost.polyui.component.Drawable +import org.polyfrost.polyui.component.extensions.onClick +import org.polyfrost.polyui.component.extensions.onHover +import org.polyfrost.polyui.component.extensions.onHoverExit import org.polyfrost.polyui.unit.by -import org.polyfrost.polyui.utils.fastEach -import kotlin.math.round -import kotlin.math.roundToInt +import kotlin.math.floor class ChatComponent(val window: ChatWindow) : Drawable(null, size = 1f by 1f) { @@ -31,44 +32,54 @@ class ChatComponent(val window: ChatWindow) : Drawable(null, size = 1f by 1f) { "§eDrag me around!" ) - var lastX = -1f + var elements = ArrayList() - var lastY = -1f + var selectedElements = ArrayList() - var lastScaleX = -1f + var currentHovered: ChatLineElement? = null - var lastScaleY = -1f - - var lineHeight = 0 - - var hasPending = false + var hovered = false init { eventHandler { event: NewMessageEvent -> if (HudManager.panelExists) return@eventHandler - addMessage(event.message) + addMessage(event.message, true) } eventHandler { event: HudEditorToggleEvent -> swap(event.open) } eventHandler { event: MouseInputEvent.Moved -> - if (mc.currentScreen != null && mc.currentScreen is ChatScreen) { - UIManager.INSTANCE.defaultInstance.inputManager.mouseMoved(event.x, event.y) - } + if (!hovered) return@eventHandler + getCurrentElement(event.x, event.y) + } + onHover { + getCurrentElement() + hovered = true + } + onHoverExit { + hoverExit() + } + onClick { + if (currentHovered == null) return@onClick + println("select $currentHovered") + selectedElements.add(currentHovered!!) } } - fun handleDelay(pending: Boolean) { - if (pending) { - addChild(ChatPendingComponent(window)) - } else { - removeChild(children!!.size - 1) - } - hasPending = pending + fun hoverExit() { + hovered = false + currentHovered = null + } + + fun getCurrentElement(mouseX: Float = OmniMouse.rawX.toFloat(), mouseY: Float = OmniMouse.rawY.toFloat()) { + if (elements.isEmpty()) return + val index = floor((mouseY - y) / (9 * mcScale * scaleY)).toInt() + if (index < elements.size - 1) return + currentHovered = elements[index] } fun swap(editing: Boolean) { - removeAllMessages() + removeAllMessages(false) if (editing) { addExampleText() } else { @@ -81,23 +92,24 @@ class ChatComponent(val window: ChatWindow) : Drawable(null, size = 1f by 1f) { val line = ChatHudLine(-1, Text.literal(message), null, null) addMessage(line) } + window.update() } fun addAllMessages() { (mc.inGameHud.chatHud as ChatHudAccessor).messages.reversed().forEach { addMessage(it) } + window.update() } - fun removeAllMessages() { - if (children!!.isEmpty()) return - for (i in 0.. 100) { - removeChild(0) - } + val visible = ChatHudLine.Visible(message.creationTick(), it, message.indicator(), it == lines.last()) + val element = ChatLineElement(visible) + elements.add(element) } - pendingComponent?.let { addChild(it) } - - window.update() + if (update) window.update() } - override var renders: Boolean - get() = super.renders && !children.isNullOrEmpty() - set(value) { - super.renders = value - } - override fun setup(polyUI: PolyUI): Boolean { return super.setup(polyUI).also { if (HudManager.panelExists) { @@ -145,35 +143,44 @@ class ChatComponent(val window: ChatWindow) : Drawable(null, size = 1f by 1f) { } } - override fun preRender(delta: Long) { - var updateSize = false - var update = false - if (x != lastX || y != lastY) { - x = round(x) - y = round(y) - lastX = x - lastY = y - update = true - } - if (scaleX != lastScaleX || scaleY != lastScaleY) { - lastScaleX = scaleX - lastScaleY = scaleY - lineHeight = (9 * mcScale * scaleY).roundToInt() - update = true - updateSize = true - } - if (update) { - children!!.fastEach { - (it as ChatLineComponent).update(updateSize) - } - } - scaleX = 1f - scaleY = 1f - super.preRender(delta) - scaleX = lastScaleX - scaleY = lastScaleY + fun renderLegacy(drawContext: DrawContext) { + if (elements.isEmpty()) return + val matrices = drawContext.matrices + matrices.push() + matrices.translate(x / mcScale, y / mcScale, 0f) + matrices.scale(scaleX, scaleY, 1f) + matrices.translate(4f, 1f, 0f) + for (element in elements) { + if (!element.renders) continue + element.render(drawContext) + matrices.translate(0f, 9f, 0f) + } + matrices.pop() } override fun render() { + val radius = window.cornerRadius * (scaleX + scaleY) / 2f + val lineHeight = 9 * mcScale + + if (radius > 0f) { + renderer.rect(x, y, width, height, window.bgColor, radius) + } else { + for (element in elements) { + if (!element.renders) continue + val color = when (element) { + currentHovered -> { + window.bgcolorHovered + } + in selectedElements -> { + window.bgColorSelected + } + else -> { + window.bgColor + } + } + renderer.rect(x, y, width, lineHeight, color) + renderer.translate(0f, lineHeight) + } + } } } \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/chatting/component/ChatLineComponent.kt b/src/main/kotlin/org/polyfrost/chatting/component/ChatLineComponent.kt deleted file mode 100644 index 33925fc..0000000 --- a/src/main/kotlin/org/polyfrost/chatting/component/ChatLineComponent.kt +++ /dev/null @@ -1,107 +0,0 @@ -package org.polyfrost.chatting.component - -import net.minecraft.client.gui.DrawContext -import net.minecraft.client.gui.hud.ChatHudLine -import net.minecraft.text.OrderedText -import net.minecraft.util.math.ColorHelper -import org.polyfrost.chatting.ChatWindow -import org.polyfrost.chatting.mcScale -import org.polyfrost.oneconfig.utils.v1.dsl.mc -import org.polyfrost.polyui.color.asMutable -import org.polyfrost.polyui.component.Drawable -import org.polyfrost.polyui.component.extensions.onHover -import org.polyfrost.polyui.component.extensions.onHoverExit -import org.polyfrost.polyui.unit.by -import kotlin.math.ceil -import kotlin.math.min -import kotlin.math.roundToInt - -open class ChatLineComponent(val window: ChatWindow, val visible: ChatHudLine.Visible? = null, val fullMessage: ChatHudLine? = null, val hasHead: Boolean = false): Drawable(size = (320 + 12) * mcScale by ceil(9 * mcScale)) { - - var index = -1 - - var opacity = 1f - - var mAlpha = 0 - - var bgColor = window.bgColor.asMutable() - - var selected = false - - init { - acceptsInput = true - onHover { - selected = true - bgColor = window.bgColor_hovered.asMutable() - } - onHoverExit { - selected = false - bgColor = window.bgColor.asMutable() - } - } - - fun refreshColor() { - bgColor = if (selected) { - window.bgColor_hovered.asMutable() - } else { - window.bgColor.asMutable() - } - } - - fun renderLegacy(drawContext: DrawContext) { - if (!renders) return - val text = getText() ?: return - val chatComponent = this.parent as Drawable - - if (mAlpha <= 3) return - val matrices = drawContext.matrices - matrices.push() - matrices.translate(x / mcScale, y / mcScale, 0f) - matrices.scale(chatComponent.scaleX, chatComponent.scaleY, 1f) - if (hasHead) { - matrices.translate(10f, 0f, 0f) - } - - val indicator = visible?.indicator - if (indicator != null) { - val c = indicator.comp_899() or (mAlpha shl 24) - drawContext.fill(0, 0, 2, 9, c) - } - - drawContext.drawTextWithShadow(mc.textRenderer, text, 4, 1, getTextColor()) - - matrices.pop() - } - - open fun getText(): OrderedText? { - return visible?.comp_896 - } - - open fun getTextColor(): Int { - return ColorHelper.withAlpha(mAlpha, -1) - } - - fun update(size: Boolean) { - val parent = parent as ChatComponent - at = parent.x by parent.y + parent.lineHeight * index - if (size) { - width = parent.width * parent.scaleX - height = parent.lineHeight.toFloat() - } - } - - override fun render() { - mAlpha = (opacity * 255).roundToInt() - if (mAlpha <= 3) return - val alphaTemp = bgColor.alpha - bgColor.alpha *= opacity - val parent = parent as ChatComponent - val hudScale = min(parent.scaleX, parent.scaleY) - val topRadius = if (this.index == 0) window.cornerRadius * hudScale else 0f - val bottomRadius = if (this.index == window.length - 1) window.cornerRadius * hudScale else 0f - val radii = floatArrayOf(topRadius, topRadius, bottomRadius, bottomRadius) - renderer.rect(x, y, width, height, bgColor, radii) - bgColor.alpha = alphaTemp - } - -} \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/chatting/component/ChatLineElement.kt b/src/main/kotlin/org/polyfrost/chatting/component/ChatLineElement.kt new file mode 100644 index 0000000..42e3e9b --- /dev/null +++ b/src/main/kotlin/org/polyfrost/chatting/component/ChatLineElement.kt @@ -0,0 +1,20 @@ +package org.polyfrost.chatting.component + +import net.minecraft.client.gui.DrawContext +import net.minecraft.client.gui.hud.ChatHudLine +import net.minecraft.util.math.ColorHelper +import org.polyfrost.oneconfig.utils.v1.dsl.mc +import kotlin.math.roundToInt + +class ChatLineElement(val visible: ChatHudLine.Visible) { + + var opacity = 0.0 + + var renders = false + + fun render(drawContext: DrawContext) { + val alpha = (255 * opacity).roundToInt() + if (alpha <= 3) return + drawContext.drawTextWithShadow(mc.textRenderer, visible.comp_896, 0, 0, ColorHelper.withAlpha(alpha, -1)) + } +} \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/chatting/component/ChatPendingComponent.kt b/src/main/kotlin/org/polyfrost/chatting/component/ChatPendingComponent.kt deleted file mode 100644 index cbb4978..0000000 --- a/src/main/kotlin/org/polyfrost/chatting/component/ChatPendingComponent.kt +++ /dev/null @@ -1,18 +0,0 @@ -package org.polyfrost.chatting.component - -import net.minecraft.text.OrderedText -import net.minecraft.text.Text -import org.polyfrost.chatting.ChatWindow -import org.polyfrost.oneconfig.utils.v1.dsl.mc - -class ChatPendingComponent(window: ChatWindow): ChatLineComponent(window) { - - override fun getText(): OrderedText? { - return Text.translatable("chat.queue", mc.messageHandler.unprocessedMessageCount).asOrderedText() - } - - override fun getTextColor(): Int { - return 16777215 + (128 shl 24) - } - -} \ No newline at end of file From 382ce9a7c8b497a5e1af5ab0997ee9d7ca7f558f Mon Sep 17 00:00:00 2001 From: ImToggle <98242902+ImToggle@users.noreply.github.com> Date: Sat, 20 Sep 2025 01:24:17 +0800 Subject: [PATCH 10/30] multiline selecting --- build.gradle.kts | 4 +- .../chatting/mixin/ChatHudMixin.java | 5 +- .../org/polyfrost/chatting/ChatWindow.kt | 19 ++- .../kotlin/org/polyfrost/chatting/Chatting.kt | 19 ++- .../kotlin/org/polyfrost/chatting/Util.kt | 67 ++++++-- .../chatting/component/ChatComponent.kt | 143 +++++++++++++----- .../chatting/component/ChatLineElement.kt | 18 ++- .../chatting/component/LegacyComponent.kt | 11 -- .../chatting/event/MouseActionEvent.kt | 12 ++ 9 files changed, 221 insertions(+), 77 deletions(-) delete mode 100644 src/main/kotlin/org/polyfrost/chatting/component/LegacyComponent.kt create mode 100644 src/main/kotlin/org/polyfrost/chatting/event/MouseActionEvent.kt diff --git a/build.gradle.kts b/build.gradle.kts index e98331c..67d97da 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,7 +5,7 @@ import dev.deftu.gradle.utils.GameSide plugins { java kotlin("jvm") version("2.1.0") - val dgtVersion = "2.51.0" + val dgtVersion = "2.52.0" id("dev.deftu.gradle.tools") version(dgtVersion) // Applies several configurations to things such as the Java version, project name/version, etc. id("dev.deftu.gradle.tools.resources") version(dgtVersion) // Applies resource processing so that we can replace tokens, such as our mod name/version, in our resources. id("dev.deftu.gradle.tools.bloom") version(dgtVersion) // Applies the Bloom plugin, which allows us to replace tokens in our source files, such as being able to use `@MOD_VERSION` in our source files. @@ -20,7 +20,7 @@ plugins { toolkitLoomHelper { useOneConfig { - version = "1.0.0-alpha.146" + version = "1.0.0-alpha.149" loaderVersion = "1.1.0-alpha.49" for (module in arrayOf("commands", "config", "config-impl", "events", "internal", "ui", "utils")) { diff --git a/src/main/java/org/polyfrost/chatting/mixin/ChatHudMixin.java b/src/main/java/org/polyfrost/chatting/mixin/ChatHudMixin.java index 2d07a3d..37cb96a 100644 --- a/src/main/java/org/polyfrost/chatting/mixin/ChatHudMixin.java +++ b/src/main/java/org/polyfrost/chatting/mixin/ChatHudMixin.java @@ -19,9 +19,8 @@ public class ChatHudMixin { @Inject(method = "render", at = @At("HEAD"), cancellable = true) - private void onRender(DrawContext drawContext, int i, int j, int k, boolean bl, CallbackInfo ci) { - Util.renderLegacy(drawContext); -// ci.cancel(); + private void onRender(CallbackInfo ci) { + ci.cancel(); } @Inject(method = "addMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignatureData;Lnet/minecraft/client/gui/hud/MessageIndicator;)V", at = @At("TAIL")) diff --git a/src/main/kotlin/org/polyfrost/chatting/ChatWindow.kt b/src/main/kotlin/org/polyfrost/chatting/ChatWindow.kt index 20210b1..c9e6f0f 100644 --- a/src/main/kotlin/org/polyfrost/chatting/ChatWindow.kt +++ b/src/main/kotlin/org/polyfrost/chatting/ChatWindow.kt @@ -1,10 +1,12 @@ package org.polyfrost.chatting import dev.deftu.omnicore.client.OmniScreen +import dev.deftu.omnicore.client.render.OmniMatrixStack import org.polyfrost.chatting.component.ChatComponent import org.polyfrost.oneconfig.api.config.v1.annotations.Color import org.polyfrost.oneconfig.api.config.v1.annotations.Slider import org.polyfrost.oneconfig.api.hud.v1.Hud +import org.polyfrost.oneconfig.api.hud.v1.LegacyHud import org.polyfrost.oneconfig.utils.v1.dsl.mc import org.polyfrost.polyui.color.rgba import org.polyfrost.polyui.component.Drawable @@ -12,8 +14,9 @@ import org.polyfrost.polyui.component.impl.Text import org.polyfrost.polyui.unit.by import org.polyfrost.polyui.unit.milliseconds import kotlin.math.pow +import kotlin.math.roundToInt -class ChatWindow(preview: Boolean = false) : Hud(id = "chat.yml", title = "Chat", category = Category.INFO) { +class ChatWindow(preview: Boolean = false) : LegacyHud(id = "chat.yml", title = "Chat", category = Category.INFO) { @Color( title = "Background Color" @@ -42,7 +45,9 @@ class ChatWindow(preview: Boolean = false) : Hud(id = "chat.yml", titl var length = 0 override fun clone(): Hud { - return (super.clone() as ChatWindow).apply { isPreview = false } + return (super.clone() as ChatWindow).apply { + isPreview = false + } } override fun create(): Drawable { @@ -53,6 +58,15 @@ class ChatWindow(preview: Boolean = false) : Hud(id = "chat.yml", titl return 25.milliseconds } + override var width = 0f + + override var height = 0f + + override fun renderLegacy(stack: OmniMatrixStack, x: Float, y: Float, scaleX: Float, scaleY: Float) { + if (isPreview) return + (get() as ChatComponent).drawLegacy(stack) + } + override fun update(): Boolean { if (get() is Text) return false with(get() as ChatComponent) { @@ -72,6 +86,7 @@ class ChatWindow(preview: Boolean = false) : Hud(id = "chat.yml", titl } return@count canRender } + lineHeight = (9 * mcScale * scaleY).roundToInt() this.size = (320 + 12) * mcScale by length * 9 * mcScale } diff --git a/src/main/kotlin/org/polyfrost/chatting/Chatting.kt b/src/main/kotlin/org/polyfrost/chatting/Chatting.kt index bfb1ae4..e1b768a 100644 --- a/src/main/kotlin/org/polyfrost/chatting/Chatting.kt +++ b/src/main/kotlin/org/polyfrost/chatting/Chatting.kt @@ -2,7 +2,12 @@ package org.polyfrost.chatting import dev.deftu.omnicore.client.OmniScreen import net.fabricmc.api.ClientModInitializer +import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents +import net.fabricmc.fabric.api.client.screen.v1.ScreenMouseEvents +import net.minecraft.client.gui.screen.ChatScreen +import org.polyfrost.chatting.event.MouseActionEvent import org.polyfrost.oneconfig.api.commands.v1.CommandManager +import org.polyfrost.oneconfig.api.event.v1.EventManager import org.polyfrost.oneconfig.api.event.v1.eventHandler import org.polyfrost.oneconfig.api.event.v1.events.MouseInputEvent import org.polyfrost.oneconfig.api.hud.v1.HudManager @@ -18,14 +23,12 @@ object Chatting : ClientModInitializer { if (!OmniScreen.isInScreen || !OmniScreen.isInChat) return@eventHandler UIManager.INSTANCE.defaultInstance.inputManager.mouseMoved(event.x, event.y) } - eventHandler { event: MouseInputEvent -> - if (!OmniScreen.isInScreen || !OmniScreen.isInChat) return@eventHandler - if (event.state == 0) { - println("released ${event.button}") - UIManager.INSTANCE.defaultInstance.inputManager.mouseReleased(event.button) - } else { - println("pressed ${event.button}") - UIManager.INSTANCE.defaultInstance.inputManager.mousePressed(event.button) + ScreenEvents.BEFORE_INIT.register { _, screen, _, _ -> + if (screen !is ChatScreen) return@register + ScreenMouseEvents.afterMouseClick(screen).register { screen, mouseX, mouseY, button -> + UIManager.INSTANCE.defaultInstance.inputManager.mouseOver.let { + EventManager.INSTANCE.post(MouseActionEvent.Companion.Click(it, button)) + } } } } diff --git a/src/main/kotlin/org/polyfrost/chatting/Util.kt b/src/main/kotlin/org/polyfrost/chatting/Util.kt index 84285c5..fb7f4df 100644 --- a/src/main/kotlin/org/polyfrost/chatting/Util.kt +++ b/src/main/kotlin/org/polyfrost/chatting/Util.kt @@ -3,23 +3,66 @@ package org.polyfrost.chatting import dev.deftu.omnicore.client.render.OmniResolution -import net.minecraft.client.gui.DrawContext -import org.polyfrost.chatting.component.ChatComponent -import org.polyfrost.oneconfig.api.ui.v1.UIManager -import org.polyfrost.polyui.component.Component -import org.polyfrost.polyui.utils.fastEach +import net.minecraft.text.OrderedText +import net.minecraft.text.Style +import net.minecraft.util.Formatting +import org.polyfrost.oneconfig.api.ui.v1.Notifications +import org.polyfrost.oneconfig.utils.v1.dsl.mc +import org.polyfrost.polyui.unit.seconds val mcScale get() = OmniResolution.scaleFactor.toFloat() -fun renderLegacy(drawContext: DrawContext) { - val master = UIManager.INSTANCE.defaultInstance.master - val children: ArrayList? = master.children - if (children == null || children.isEmpty()) return +fun OrderedText.asString(): String { + val sb = StringBuilder() + var lastStyle = Style.EMPTY - children.fastEach { child -> - if (child is ChatComponent) { - child.renderLegacy(drawContext) + this.accept { _, style, codePoint -> + if (style != lastStyle) { + sb.append(getFormattingCodes(style, lastStyle)) + lastStyle = style } + sb.appendCodePoint(codePoint) + true } + + return sb.toString() +} + +private fun getFormattingCodes(style: Style, old: Style): String { + val stringBuilder = StringBuilder() + + if (!style.isBold && old.isBold || + !style.isItalic && old.isItalic || + !style.isUnderlined && old.isUnderlined || + !style.isStrikethrough && old.isStrikethrough || + !style.isObfuscated && old.isObfuscated || + (style.color != old.color && style.color == null)) { + stringBuilder.append("§r") + } + + val color = style.color + if (color != null) { + val format = Formatting.byName(color.name) + if (format != null) { + stringBuilder.append('§').append(format.code) + } else { + val hex = String.format("%06x", color.rgb) + stringBuilder.append("§x") + for (c in hex) stringBuilder.append('§').append(c) + } + } + + if (style.isBold) stringBuilder.append("§l") + if (style.isItalic) stringBuilder.append("§o") + if (style.isUnderlined) stringBuilder.append("§n") + if (style.isStrikethrough) stringBuilder.append("§m") + if (style.isObfuscated) stringBuilder.append("§k") + + return stringBuilder.toString() +} + +fun String.copyToClipboard() { + mc.keyboard.clipboard = this + Notifications.enqueue(Notifications.Type.Info, "Chatting", "Copied \"$this\" to clipboard.", 3.seconds) } \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/chatting/component/ChatComponent.kt b/src/main/kotlin/org/polyfrost/chatting/component/ChatComponent.kt index d08a9f7..ccab755 100644 --- a/src/main/kotlin/org/polyfrost/chatting/component/ChatComponent.kt +++ b/src/main/kotlin/org/polyfrost/chatting/component/ChatComponent.kt @@ -1,32 +1,40 @@ package org.polyfrost.chatting.component +import dev.deftu.omnicore.client.OmniKeyboard import dev.deftu.omnicore.client.OmniMouse -import net.minecraft.client.gui.DrawContext +import dev.deftu.omnicore.client.render.OmniMatrixStack import net.minecraft.client.gui.hud.ChatHudLine import net.minecraft.client.util.ChatMessages import net.minecraft.text.Text import org.polyfrost.chatting.ChatWindow +import org.polyfrost.chatting.copyToClipboard +import org.polyfrost.chatting.event.MouseActionEvent import org.polyfrost.chatting.event.NewMessageEvent import org.polyfrost.chatting.mcScale import org.polyfrost.chatting.mixin.ChatHudAccessor import org.polyfrost.oneconfig.api.event.v1.eventHandler import org.polyfrost.oneconfig.api.event.v1.events.MouseInputEvent import org.polyfrost.oneconfig.api.hud.v1.HudManager +import org.polyfrost.oneconfig.api.hud.v1.LegacyHud import org.polyfrost.oneconfig.api.hud.v1.events.HudEditorToggleEvent import org.polyfrost.oneconfig.utils.v1.dsl.mc import org.polyfrost.polyui.PolyUI -import org.polyfrost.polyui.component.Drawable -import org.polyfrost.polyui.component.extensions.onClick +import org.polyfrost.polyui.color.argb +import org.polyfrost.polyui.color.asMutable +import org.polyfrost.polyui.component.Component import org.polyfrost.polyui.component.extensions.onHover import org.polyfrost.polyui.component.extensions.onHoverExit import org.polyfrost.polyui.unit.by import kotlin.math.floor +import kotlin.math.max +import kotlin.math.min +import kotlin.math.round -class ChatComponent(val window: ChatWindow) : Drawable(null, size = 1f by 1f) { +class ChatComponent(val window: ChatWindow) : LegacyHud.LegacyHudComponent(window, null, size = 1f by 1f) { @Transient val editorMessages = mutableListOf( - "§bChatting", + "§b§lChatting", "", "This is a movable chat", "§eDrag me around!" @@ -34,15 +42,19 @@ class ChatComponent(val window: ChatWindow) : Drawable(null, size = 1f by 1f) { var elements = ArrayList() - var selectedElements = ArrayList() + var selectedElements = ArrayList() - var currentHovered: ChatLineElement? = null + var currentHovered = -1 + + var lastSelected = -1 var hovered = false + var lineHeight = 0 + init { eventHandler { event: NewMessageEvent -> - if (HudManager.panelExists) return@eventHandler + if (HudManager.isEditing) return@eventHandler addMessage(event.message, true) } eventHandler { event: HudEditorToggleEvent -> @@ -52,6 +64,18 @@ class ChatComponent(val window: ChatWindow) : Drawable(null, size = 1f by 1f) { if (!hovered) return@eventHandler getCurrentElement(event.x, event.y) } + eventHandler { event: MouseActionEvent.Companion.Click -> + if (event.mouseOver == null) { + selectedElements.clear() + } else { + if (event.mouseOver == this) { + when (event.button) { + 0 -> leftClick() + 1 -> rightClick() + } + } + } + } onHover { getCurrentElement() hovered = true @@ -59,23 +83,53 @@ class ChatComponent(val window: ChatWindow) : Drawable(null, size = 1f by 1f) { onHoverExit { hoverExit() } - onClick { - if (currentHovered == null) return@onClick - println("select $currentHovered") - selectedElements.add(currentHovered!!) + } + + fun leftClick() { + if (currentHovered == -1) return + if (OmniKeyboard.isShiftKeyPressed) { + selectedElements.clear() + val currentIndex = currentHovered + val lastIndex = if (lastSelected == -1) 0 else lastSelected + for (i in min(lastIndex, currentIndex)..max(lastIndex, currentIndex)) { + selectedElements.add(i) + } + } else { + if (!OmniKeyboard.isCtrlKeyPressed || !OmniKeyboard.isAltKeyPressed) { + selectedElements.clear() + } + selectedElements.add(currentHovered) + lastSelected = currentHovered + } + } + + fun rightClick() { + if (selectedElements.isEmpty()) { + if (currentHovered == -1) return + elements[currentHovered].message.copyToClipboard() + } else { + val stringBuilder = StringBuilder() + for (index in selectedElements) { + stringBuilder.append(elements[index].message) + if (index != selectedElements.last()) { + stringBuilder.append("\n") + } + } + stringBuilder.toString().copyToClipboard() + selectedElements.clear() } } fun hoverExit() { hovered = false - currentHovered = null + currentHovered = -1 } fun getCurrentElement(mouseX: Float = OmniMouse.rawX.toFloat(), mouseY: Float = OmniMouse.rawY.toFloat()) { if (elements.isEmpty()) return val index = floor((mouseY - y) / (9 * mcScale * scaleY)).toInt() - if (index < elements.size - 1) return - currentHovered = elements[index] + if (index < 0 || index >= elements.size) return + currentHovered = index } fun swap(editing: Boolean) { @@ -135,7 +189,7 @@ class ChatComponent(val window: ChatWindow) : Drawable(null, size = 1f by 1f) { override fun setup(polyUI: PolyUI): Boolean { return super.setup(polyUI).also { - if (HudManager.panelExists) { + if (HudManager.isEditing) { addExampleText() } else { addAllMessages() @@ -143,43 +197,64 @@ class ChatComponent(val window: ChatWindow) : Drawable(null, size = 1f by 1f) { } } - fun renderLegacy(drawContext: DrawContext) { + fun drawLegacy(stack: OmniMatrixStack) { if (elements.isEmpty()) return - val matrices = drawContext.matrices - matrices.push() - matrices.translate(x / mcScale, y / mcScale, 0f) - matrices.scale(scaleX, scaleY, 1f) - matrices.translate(4f, 1f, 0f) + stack.push() + stack.translate(x / mcScale, y / mcScale, 0f) + stack.scale(scaleX, scaleY, 1f) + stack.translate(4f, 1f, 0f) for (element in elements) { if (!element.renders) continue - element.render(drawContext) - matrices.translate(0f, 9f, 0f) + element.render(stack) + stack.translate(0f, 9f, 0f) } - matrices.pop() + stack.pop() + } + + override var width = (this as Component).width + + override var height = (this as Component).height + + override fun preRender(delta: Long) { + val tempScaleX = scaleX + val tempScaleY = scaleY + x = round(x) + y = round(y) + scaleX = 1f + scaleY = 1f + super.preRender(delta) + scaleX = tempScaleX + scaleY = tempScaleY } override fun render() { val radius = window.cornerRadius * (scaleX + scaleY) / 2f - val lineHeight = 9 * mcScale - if (radius > 0f) { renderer.rect(x, y, width, height, window.bgColor, radius) } else { - for (element in elements) { + for ((index, element) in elements.withIndex()) { if (!element.renders) continue - val color = when (element) { - currentHovered -> { - window.bgcolorHovered - } + val color = when ((index)) { in selectedElements -> { window.bgColorSelected } + currentHovered -> { + window.bgcolorHovered + } else -> { window.bgColor } + }.asMutable() +// val alpha = color.alpha +// color.alpha *= element.opacity.toFloat() + renderer.rect(x, y, width * scaleX, lineHeight.toFloat(), color) + val indicator = element.visible.indicator + if (indicator != null) { + val ac = indicator.comp_899 or (element.alpha shl 24) + renderer.rect(x, y, 2 * mcScale * scaleX, lineHeight.toFloat(), argb(ac)) } - renderer.rect(x, y, width, lineHeight, color) - renderer.translate(0f, lineHeight) + renderer.translate(0f, lineHeight.toFloat()) +// color.alpha = alpha } } } diff --git a/src/main/kotlin/org/polyfrost/chatting/component/ChatLineElement.kt b/src/main/kotlin/org/polyfrost/chatting/component/ChatLineElement.kt index 42e3e9b..26aafb9 100644 --- a/src/main/kotlin/org/polyfrost/chatting/component/ChatLineElement.kt +++ b/src/main/kotlin/org/polyfrost/chatting/component/ChatLineElement.kt @@ -1,20 +1,28 @@ package org.polyfrost.chatting.component -import net.minecraft.client.gui.DrawContext +import dev.deftu.omnicore.client.render.OmniGameRendering +import dev.deftu.omnicore.client.render.OmniMatrixStack import net.minecraft.client.gui.hud.ChatHudLine import net.minecraft.util.math.ColorHelper -import org.polyfrost.oneconfig.utils.v1.dsl.mc +import org.polyfrost.chatting.asString import kotlin.math.roundToInt class ChatLineElement(val visible: ChatHudLine.Visible) { + val message = visible.comp_896.asString() + var opacity = 0.0 + set(value) { + field = value + alpha = (255 * value).roundToInt() + } + + var alpha = 0 var renders = false - fun render(drawContext: DrawContext) { - val alpha = (255 * opacity).roundToInt() + fun render(stack: OmniMatrixStack) { if (alpha <= 3) return - drawContext.drawTextWithShadow(mc.textRenderer, visible.comp_896, 0, 0, ColorHelper.withAlpha(alpha, -1)) + OmniGameRendering.drawText(stack, message, 0f, 0f, ColorHelper.withAlpha(alpha, -1), true) } } \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/chatting/component/LegacyComponent.kt b/src/main/kotlin/org/polyfrost/chatting/component/LegacyComponent.kt deleted file mode 100644 index 117ff46..0000000 --- a/src/main/kotlin/org/polyfrost/chatting/component/LegacyComponent.kt +++ /dev/null @@ -1,11 +0,0 @@ -package org.polyfrost.chatting.component - -import dev.deftu.omnicore.client.render.OmniMatrixStack - -open class LegacyComponent { - - var remove = false - - open fun render(matrixStack: OmniMatrixStack) { - } -} \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/chatting/event/MouseActionEvent.kt b/src/main/kotlin/org/polyfrost/chatting/event/MouseActionEvent.kt new file mode 100644 index 0000000..87c5fa8 --- /dev/null +++ b/src/main/kotlin/org/polyfrost/chatting/event/MouseActionEvent.kt @@ -0,0 +1,12 @@ +package org.polyfrost.chatting.event + +import org.polyfrost.oneconfig.api.event.v1.events.Event +import org.polyfrost.polyui.component.Inputtable + +class MouseActionEvent : Event { + + companion object { + class Click(val mouseOver: Inputtable?, val button: Int) : Event + } + +} \ No newline at end of file From 51d1ada4d6582fdb45dabce5e0d5b97cb0a20de7 Mon Sep 17 00:00:00 2001 From: ImToggle Date: Sat, 20 Sep 2025 16:06:01 +0800 Subject: [PATCH 11/30] scrolling --- .../org/polyfrost/chatting/ChatWindow.kt | 12 +- .../kotlin/org/polyfrost/chatting/Chatting.kt | 10 +- .../kotlin/org/polyfrost/chatting/Util.kt | 7 ++ .../chatting/animation/DummyAnimation.kt | 10 ++ .../chatting/component/ChatComponent.kt | 110 +++++++++++------- 5 files changed, 105 insertions(+), 44 deletions(-) create mode 100644 src/main/kotlin/org/polyfrost/chatting/animation/DummyAnimation.kt diff --git a/src/main/kotlin/org/polyfrost/chatting/ChatWindow.kt b/src/main/kotlin/org/polyfrost/chatting/ChatWindow.kt index c9e6f0f..c7740f7 100644 --- a/src/main/kotlin/org/polyfrost/chatting/ChatWindow.kt +++ b/src/main/kotlin/org/polyfrost/chatting/ChatWindow.kt @@ -5,6 +5,7 @@ import dev.deftu.omnicore.client.render.OmniMatrixStack import org.polyfrost.chatting.component.ChatComponent import org.polyfrost.oneconfig.api.config.v1.annotations.Color import org.polyfrost.oneconfig.api.config.v1.annotations.Slider +import org.polyfrost.oneconfig.api.config.v1.annotations.Switch import org.polyfrost.oneconfig.api.hud.v1.Hud import org.polyfrost.oneconfig.api.hud.v1.LegacyHud import org.polyfrost.oneconfig.utils.v1.dsl.mc @@ -13,6 +14,7 @@ import org.polyfrost.polyui.component.Drawable import org.polyfrost.polyui.component.impl.Text import org.polyfrost.polyui.unit.by import org.polyfrost.polyui.unit.milliseconds +import kotlin.math.min import kotlin.math.pow import kotlin.math.roundToInt @@ -40,6 +42,13 @@ class ChatWindow(preview: Boolean = false) : LegacyHud(id = "chat.yml", title = ) var cornerRadius = 0f + @Switch( + title = "Smooth Scrolling" + ) + var smoothScrolling = false + + var lineLimit = 10 + var isPreview = preview var length = 0 @@ -87,9 +96,8 @@ class ChatWindow(preview: Boolean = false) : LegacyHud(id = "chat.yml", title = return@count canRender } lineHeight = (9 * mcScale * scaleY).roundToInt() - this.size = (320 + 12) * mcScale by length * 9 * mcScale + this.size = (320 + 12) * mcScale by min(length, lineLimit) * 9 * mcScale } - return true } diff --git a/src/main/kotlin/org/polyfrost/chatting/Chatting.kt b/src/main/kotlin/org/polyfrost/chatting/Chatting.kt index e1b768a..407bae4 100644 --- a/src/main/kotlin/org/polyfrost/chatting/Chatting.kt +++ b/src/main/kotlin/org/polyfrost/chatting/Chatting.kt @@ -5,6 +5,7 @@ import net.fabricmc.api.ClientModInitializer import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents import net.fabricmc.fabric.api.client.screen.v1.ScreenMouseEvents import net.minecraft.client.gui.screen.ChatScreen +import org.polyfrost.chatting.component.ChatComponent import org.polyfrost.chatting.event.MouseActionEvent import org.polyfrost.oneconfig.api.commands.v1.CommandManager import org.polyfrost.oneconfig.api.event.v1.EventManager @@ -25,11 +26,18 @@ object Chatting : ClientModInitializer { } ScreenEvents.BEFORE_INIT.register { _, screen, _, _ -> if (screen !is ChatScreen) return@register - ScreenMouseEvents.afterMouseClick(screen).register { screen, mouseX, mouseY, button -> + ScreenMouseEvents.afterMouseClick(screen).register { _, _, _, button -> UIManager.INSTANCE.defaultInstance.inputManager.mouseOver.let { EventManager.INSTANCE.post(MouseActionEvent.Companion.Click(it, button)) } } + ScreenMouseEvents.afterMouseScroll(screen).register { _, _, mouseY, horizontalAmount, verticalAmount -> + UIManager.INSTANCE.defaultInstance.inputManager.mouseOver?.let { + if (it is ChatComponent) { + it.scroll(verticalAmount.toFloat()) + } + } + } } } diff --git a/src/main/kotlin/org/polyfrost/chatting/Util.kt b/src/main/kotlin/org/polyfrost/chatting/Util.kt index fb7f4df..442abee 100644 --- a/src/main/kotlin/org/polyfrost/chatting/Util.kt +++ b/src/main/kotlin/org/polyfrost/chatting/Util.kt @@ -13,6 +13,13 @@ import org.polyfrost.polyui.unit.seconds val mcScale get() = OmniResolution.scaleFactor.toFloat() +val editorMessages = mutableListOf( + "§b§lChatting", + "", + "This is a movable chat", + "§eDrag me around!" +) + fun OrderedText.asString(): String { val sb = StringBuilder() var lastStyle = Style.EMPTY diff --git a/src/main/kotlin/org/polyfrost/chatting/animation/DummyAnimation.kt b/src/main/kotlin/org/polyfrost/chatting/animation/DummyAnimation.kt new file mode 100644 index 0000000..9124cba --- /dev/null +++ b/src/main/kotlin/org/polyfrost/chatting/animation/DummyAnimation.kt @@ -0,0 +1,10 @@ +package org.polyfrost.chatting.animation + +import org.polyfrost.polyui.animate.Animation + +class DummyAnimation(value: Float) : Animation(0L, value, value) { + + override fun getValue(percent: Float) = 1f + + override fun clone(): Animation = DummyAnimation(to) +} \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/chatting/component/ChatComponent.kt b/src/main/kotlin/org/polyfrost/chatting/component/ChatComponent.kt index ccab755..7326a25 100644 --- a/src/main/kotlin/org/polyfrost/chatting/component/ChatComponent.kt +++ b/src/main/kotlin/org/polyfrost/chatting/component/ChatComponent.kt @@ -7,7 +7,9 @@ import net.minecraft.client.gui.hud.ChatHudLine import net.minecraft.client.util.ChatMessages import net.minecraft.text.Text import org.polyfrost.chatting.ChatWindow +import org.polyfrost.chatting.animation.DummyAnimation import org.polyfrost.chatting.copyToClipboard +import org.polyfrost.chatting.editorMessages import org.polyfrost.chatting.event.MouseActionEvent import org.polyfrost.chatting.event.NewMessageEvent import org.polyfrost.chatting.mcScale @@ -19,26 +21,18 @@ import org.polyfrost.oneconfig.api.hud.v1.LegacyHud import org.polyfrost.oneconfig.api.hud.v1.events.HudEditorToggleEvent import org.polyfrost.oneconfig.utils.v1.dsl.mc import org.polyfrost.polyui.PolyUI +import org.polyfrost.polyui.animate.Animation +import org.polyfrost.polyui.animate.Linear import org.polyfrost.polyui.color.argb import org.polyfrost.polyui.color.asMutable import org.polyfrost.polyui.component.Component import org.polyfrost.polyui.component.extensions.onHover import org.polyfrost.polyui.component.extensions.onHoverExit import org.polyfrost.polyui.unit.by -import kotlin.math.floor -import kotlin.math.max -import kotlin.math.min -import kotlin.math.round +import org.polyfrost.polyui.unit.ms +import kotlin.math.* -class ChatComponent(val window: ChatWindow) : LegacyHud.LegacyHudComponent(window, null, size = 1f by 1f) { - - @Transient - val editorMessages = mutableListOf( - "§b§lChatting", - "", - "This is a movable chat", - "§eDrag me around!" - ) +class ChatComponent(val window: ChatWindow) : LegacyHud.LegacyHudComponent(window, null, size = 10f by 10f) { var elements = ArrayList() @@ -52,6 +46,14 @@ class ChatComponent(val window: ChatWindow) : LegacyHud.LegacyHudComponent(windo var lineHeight = 0 + var scrollAmount: Animation = DummyAnimation(0f) + + var translateAmount = 0f + + var drawingStart = 0 + + var drawingEnd = 0 + init { eventHandler { event: NewMessageEvent -> if (HudManager.isEditing) return@eventHandler @@ -120,6 +122,23 @@ class ChatComponent(val window: ChatWindow) : LegacyHud.LegacyHudComponent(windo } } + fun scroll(amount: Float) { + val maxAmount = if (elements.size <= window.lineLimit) { + 0f + } else { + (elements.size - window.lineLimit).toFloat() + } + val target = (scrollAmount.to + amount).coerceIn(0f..maxAmount) + if (target == scrollAmount.to) return + if (window.smoothScrolling) { + val distance = abs(target - scrollAmount.value) + scrollAmount = Linear((50 * distance).ms, scrollAmount.value, target) + } else { + scrollAmount = DummyAnimation(target) + } + getCurrentElement() + } + fun hoverExit() { hovered = false currentHovered = -1 @@ -127,7 +146,7 @@ class ChatComponent(val window: ChatWindow) : LegacyHud.LegacyHudComponent(windo fun getCurrentElement(mouseX: Float = OmniMouse.rawX.toFloat(), mouseY: Float = OmniMouse.rawY.toFloat()) { if (elements.isEmpty()) return - val index = floor((mouseY - y) / (9 * mcScale * scaleY)).toInt() + val index = elements.size - 1 - floor((y + height * scaleY + lineHeight * scrollAmount.value - mouseY) / lineHeight).toInt() if (index < 0 || index >= elements.size) return currentHovered = index } @@ -202,9 +221,11 @@ class ChatComponent(val window: ChatWindow) : LegacyHud.LegacyHudComponent(windo stack.push() stack.translate(x / mcScale, y / mcScale, 0f) stack.scale(scaleX, scaleY, 1f) + stack.translate(0f, -translateAmount * 9, 1f) stack.translate(4f, 1f, 0f) - for (element in elements) { + for ((index, element) in elements.withIndex()) { if (!element.renders) continue + if (index !in drawingStart..drawingEnd) continue element.render(stack) stack.translate(0f, 9f, 0f) } @@ -216,6 +237,17 @@ class ChatComponent(val window: ChatWindow) : LegacyHud.LegacyHudComponent(windo override var height = (this as Component).height override fun preRender(delta: Long) { + if (hovered && !scrollAmount.isFinished) getCurrentElement() + val scroll = scrollAmount.update(delta) + drawingStart = if (elements.size <= window.lineLimit) { + 0 + } else { + elements.size - window.lineLimit - ceil(scroll).toInt() + } + val full = scroll.toInt().toFloat() == scroll + drawingEnd = drawingStart + window.lineLimit + if (full) -1 else 0 + translateAmount = if (full) 0f else 1f - scroll + floor(scroll) + val tempScaleX = scaleX val tempScaleY = scaleY x = round(x) @@ -228,34 +260,30 @@ class ChatComponent(val window: ChatWindow) : LegacyHud.LegacyHudComponent(windo } override fun render() { - val radius = window.cornerRadius * (scaleX + scaleY) / 2f - if (radius > 0f) { - renderer.rect(x, y, width, height, window.bgColor, radius) - } else { - for ((index, element) in elements.withIndex()) { - if (!element.renders) continue - val color = when ((index)) { - in selectedElements -> { - window.bgColorSelected - } - currentHovered -> { - window.bgcolorHovered - } - else -> { - window.bgColor - } - }.asMutable() -// val alpha = color.alpha -// color.alpha *= element.opacity.toFloat() - renderer.rect(x, y, width * scaleX, lineHeight.toFloat(), color) - val indicator = element.visible.indicator - if (indicator != null) { - val ac = indicator.comp_899 or (element.alpha shl 24) - renderer.rect(x, y, 2 * mcScale * scaleX, lineHeight.toFloat(), argb(ac)) + renderer.pushScissor(x, y, width * scaleX, height * scaleY) + renderer.translate(0f, -translateAmount * lineHeight) + for ((index, element) in elements.withIndex()) { + if (!element.renders) continue + if (index !in drawingStart..drawingEnd) continue + val color = when ((index)) { + in selectedElements -> { + window.bgColorSelected + } + currentHovered -> { + window.bgcolorHovered + } + else -> { + window.bgColor } - renderer.translate(0f, lineHeight.toFloat()) -// color.alpha = alpha + }.asMutable() + renderer.rect(x, y, width * scaleX, lineHeight.toFloat(), color) + val indicator = element.visible.indicator + if (indicator != null) { + val ac = indicator.comp_899 or (element.alpha shl 24) + renderer.rect(x, y, 2 * mcScale * scaleX, lineHeight.toFloat(), argb(ac)) } + renderer.translate(0f, lineHeight.toFloat()) } + renderer.popScissor() } } \ No newline at end of file From 1fc8f0fa50d1212822aa0896460618775cb26a48 Mon Sep 17 00:00:00 2001 From: ImToggle <98242902+ImToggle@users.noreply.github.com> Date: Tue, 23 Sep 2025 00:41:58 +0800 Subject: [PATCH 12/30] idk --- build.gradle.kts | 20 ++++-- .../chatting/mixin/ChatHudLineMixin.java | 24 +++++++ .../chatting/mixin/ChatHudMixin.java | 3 +- .../chatting/mixin/MessageHandlerMixin.java | 28 ++++++++ .../chatting/mixin/RendererImplMixin.java | 16 +++++ .../org/polyfrost/chatting/ChatWindow.kt | 12 ++-- .../kotlin/org/polyfrost/chatting/Chatting.kt | 7 +- .../org/polyfrost/chatting/ModConfig.kt | 4 +- .../kotlin/org/polyfrost/chatting/Util.kt | 40 ++++++++++- .../chatting/component/ChatComponent.kt | 69 ++++++++++--------- .../chatting/component/ChatLineElement.kt | 14 ++-- .../chatting/hook/ChatHudLineHook.kt | 12 ++++ src/main/resources/mixins.chatting.json | 9 ++- 13 files changed, 200 insertions(+), 58 deletions(-) create mode 100644 src/main/java/org/polyfrost/chatting/mixin/ChatHudLineMixin.java create mode 100644 src/main/java/org/polyfrost/chatting/mixin/MessageHandlerMixin.java create mode 100644 src/main/java/org/polyfrost/chatting/mixin/RendererImplMixin.java create mode 100644 src/main/kotlin/org/polyfrost/chatting/hook/ChatHudLineHook.kt diff --git a/build.gradle.kts b/build.gradle.kts index 67d97da..dfde574 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -14,13 +14,25 @@ plugins { id("dev.deftu.gradle.tools.minecraft.releases") version(dgtVersion) // Applies the Minecraft auto-releasing plugin, which allows you to automatically release your mod to CurseForge and Modrinth. } -//dependencies { -// compileOnly("dev.deftu:omnicore-1.21.5-fabric:0.34.0") -//} +dependencies { + implementation("dev.deftu:copycat:0.1.3") + listOf( + "windows-x64", + "windows-x86", + "linux-x64", + "linux-x86", + "linux-arm", + "linux-arm64", + "osx-x64", + "osx-arm64" + ).forEach { target -> + runtimeOnly("dev.deftu:copycat-natives-$target:0.1.3") + } +} toolkitLoomHelper { useOneConfig { - version = "1.0.0-alpha.149" + version = "1.0.0-alpha.150" loaderVersion = "1.1.0-alpha.49" for (module in arrayOf("commands", "config", "config-impl", "events", "internal", "ui", "utils")) { diff --git a/src/main/java/org/polyfrost/chatting/mixin/ChatHudLineMixin.java b/src/main/java/org/polyfrost/chatting/mixin/ChatHudLineMixin.java new file mode 100644 index 0000000..873ec25 --- /dev/null +++ b/src/main/java/org/polyfrost/chatting/mixin/ChatHudLineMixin.java @@ -0,0 +1,24 @@ +package org.polyfrost.chatting.mixin; + +import net.minecraft.client.gui.hud.ChatHudLine; +import org.jetbrains.annotations.Nullable; +import org.polyfrost.chatting.hook.ChatHudLineHook; +import org.polyfrost.polyui.data.PolyImage; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; + +@Mixin(ChatHudLine.class) +public class ChatHudLineMixin implements ChatHudLineHook { + + @Unique private PolyImage chatting$head; + + @Override + public void chatting$setHead(@Nullable PolyImage head) { + this.chatting$head = head; + } + + @Override + public @Nullable PolyImage chatting$getHead() { + return chatting$head; + } +} \ No newline at end of file diff --git a/src/main/java/org/polyfrost/chatting/mixin/ChatHudMixin.java b/src/main/java/org/polyfrost/chatting/mixin/ChatHudMixin.java index 37cb96a..a475c59 100644 --- a/src/main/java/org/polyfrost/chatting/mixin/ChatHudMixin.java +++ b/src/main/java/org/polyfrost/chatting/mixin/ChatHudMixin.java @@ -1,7 +1,6 @@ package org.polyfrost.chatting.mixin; import com.llamalad7.mixinextras.sugar.Local; -import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.hud.ChatHud; import net.minecraft.client.gui.hud.ChatHudLine; import net.minecraft.client.gui.hud.MessageIndicator; @@ -9,6 +8,7 @@ import net.minecraft.text.Text; import org.polyfrost.chatting.Util; import org.polyfrost.chatting.event.NewMessageEvent; +import org.polyfrost.chatting.hook.ChatHudLineHook; import org.polyfrost.oneconfig.api.event.v1.EventManager; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -25,6 +25,7 @@ private void onRender(CallbackInfo ci) { @Inject(method = "addMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignatureData;Lnet/minecraft/client/gui/hud/MessageIndicator;)V", at = @At("TAIL")) private void createMessage(Text text, MessageSignatureData messageSignatureData, MessageIndicator messageIndicator, CallbackInfo ci, @Local(ordinal = 0) ChatHudLine chatHudLine) { + ((ChatHudLineHook) (Object) chatHudLine).chatting$setHead(Util.getSkinFromProfile(Util.currentSender)); EventManager.INSTANCE.post(new NewMessageEvent(chatHudLine)); } diff --git a/src/main/java/org/polyfrost/chatting/mixin/MessageHandlerMixin.java b/src/main/java/org/polyfrost/chatting/mixin/MessageHandlerMixin.java new file mode 100644 index 0000000..2cb0ba6 --- /dev/null +++ b/src/main/java/org/polyfrost/chatting/mixin/MessageHandlerMixin.java @@ -0,0 +1,28 @@ +package org.polyfrost.chatting.mixin; + +import com.mojang.authlib.GameProfile; +import net.minecraft.client.network.message.MessageHandler; +import net.minecraft.network.message.MessageType; +import net.minecraft.network.message.SignedMessage; +import net.minecraft.text.Text; +import org.polyfrost.chatting.Util; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.time.Instant; + +@Mixin(MessageHandler.class) +public class MessageHandlerMixin { + + @Inject(method = "processChatMessageInternal", at = @At("HEAD")) + private void captureSenderProfile(MessageType.Parameters parameters, SignedMessage signedMessage, Text text, GameProfile gameProfile, boolean bl, Instant instant, CallbackInfoReturnable cir) { + Util.currentSender = gameProfile; + } + + @Inject(method = "processChatMessageInternal", at = @At("RETURN")) + private void clearSender(MessageType.Parameters parameters, SignedMessage signedMessage, Text text, GameProfile gameProfile, boolean bl, Instant instant, CallbackInfoReturnable cir) { + Util.currentSender = null; + } +} \ No newline at end of file diff --git a/src/main/java/org/polyfrost/chatting/mixin/RendererImplMixin.java b/src/main/java/org/polyfrost/chatting/mixin/RendererImplMixin.java new file mode 100644 index 0000000..19d0d37 --- /dev/null +++ b/src/main/java/org/polyfrost/chatting/mixin/RendererImplMixin.java @@ -0,0 +1,16 @@ +package org.polyfrost.chatting.mixin; + +import org.lwjgl.nanovg.NanoVG; +import org.polyfrost.oneconfig.api.ui.v1.internal.RendererImpl; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyArg; + +@Mixin(value = RendererImpl.class, remap = false) +public class RendererImplMixin { + + @ModifyArg(method = "loadImage", at = @At(value = "INVOKE", target = "Lorg/polyfrost/oneconfig/api/ui/v1/api/NanoVgApi;createImage(FFLjava/nio/ByteBuffer;I)I"), index = 3) + private int createImage(int flags) { + return NanoVG.NVG_IMAGE_NEAREST; + } +} \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/chatting/ChatWindow.kt b/src/main/kotlin/org/polyfrost/chatting/ChatWindow.kt index c7740f7..8657cb2 100644 --- a/src/main/kotlin/org/polyfrost/chatting/ChatWindow.kt +++ b/src/main/kotlin/org/polyfrost/chatting/ChatWindow.kt @@ -1,7 +1,8 @@ package org.polyfrost.chatting -import dev.deftu.omnicore.client.OmniScreen -import dev.deftu.omnicore.client.render.OmniMatrixStack +import dev.deftu.omnicore.api.client.render.OmniRenderingContext +import dev.deftu.omnicore.api.client.screen.isInChatScreen +import dev.deftu.omnicore.api.client.screen.isInScreen import org.polyfrost.chatting.component.ChatComponent import org.polyfrost.oneconfig.api.config.v1.annotations.Color import org.polyfrost.oneconfig.api.config.v1.annotations.Slider @@ -71,15 +72,14 @@ class ChatWindow(preview: Boolean = false) : LegacyHud(id = "chat.yml", title = override var height = 0f - override fun renderLegacy(stack: OmniMatrixStack, x: Float, y: Float, scaleX: Float, scaleY: Float) { - if (isPreview) return - (get() as ChatComponent).drawLegacy(stack) + override fun renderLegacy(ctx: OmniRenderingContext, x: Float, y: Float, scaleX: Float, scaleY: Float) { + (get() as ChatComponent).drawLegacy(ctx) } override fun update(): Boolean { if (get() is Text) return false with(get() as ChatComponent) { - val inChat = OmniScreen.isInScreen && OmniScreen.isInChat + val inChat = isInScreen && isInChatScreen length = elements.count { val creationTick = it.visible.comp_895 val fullOpacity = inChat || creationTick == -1 diff --git a/src/main/kotlin/org/polyfrost/chatting/Chatting.kt b/src/main/kotlin/org/polyfrost/chatting/Chatting.kt index 407bae4..7b8f014 100644 --- a/src/main/kotlin/org/polyfrost/chatting/Chatting.kt +++ b/src/main/kotlin/org/polyfrost/chatting/Chatting.kt @@ -1,6 +1,7 @@ package org.polyfrost.chatting -import dev.deftu.omnicore.client.OmniScreen +import dev.deftu.omnicore.api.client.screen.isInChatScreen +import dev.deftu.omnicore.api.client.screen.isInScreen import net.fabricmc.api.ClientModInitializer import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents import net.fabricmc.fabric.api.client.screen.v1.ScreenMouseEvents @@ -20,10 +21,12 @@ object Chatting : ClientModInitializer { ModConfig.preload() CommandManager.register(ModCommand) HudManager.register(ChatWindow(preview = true)) + eventHandler { event: MouseInputEvent.Moved -> - if (!OmniScreen.isInScreen || !OmniScreen.isInChat) return@eventHandler + if (!isInScreen || !isInChatScreen) return@eventHandler UIManager.INSTANCE.defaultInstance.inputManager.mouseMoved(event.x, event.y) } + ScreenEvents.BEFORE_INIT.register { _, screen, _, _ -> if (screen !is ChatScreen) return@register ScreenMouseEvents.afterMouseClick(screen).register { _, _, _, button -> diff --git a/src/main/kotlin/org/polyfrost/chatting/ModConfig.kt b/src/main/kotlin/org/polyfrost/chatting/ModConfig.kt index 9211248..0da9a19 100644 --- a/src/main/kotlin/org/polyfrost/chatting/ModConfig.kt +++ b/src/main/kotlin/org/polyfrost/chatting/ModConfig.kt @@ -1,11 +1,11 @@ package org.polyfrost.chatting -import dev.deftu.omnicore.client.OmniKeyboard import org.polyfrost.oneconfig.api.config.v1.Config import org.polyfrost.oneconfig.api.config.v1.annotations.* import org.polyfrost.oneconfig.api.hypixel.v1.HypixelUtils import org.polyfrost.polyui.color.rgba import org.polyfrost.polyui.input.KeybindHelper +import org.polyfrost.polyui.input.Keys object ModConfig : Config("${ModConstants.ID}.json", ModConstants.NAME, Category.OTHER) { @@ -58,7 +58,7 @@ object ModConfig : Config("${ModConstants.ID}.json", ModConstants.NAME, Category @Keybind( title = "Peek KeyBind" ) - var chatPeekBind = KeybindHelper.builder().keys(OmniKeyboard.KEY_Z).does { + var chatPeekBind = KeybindHelper.builder().keys(Keys.Z).does { }.build() @RadioButton( diff --git a/src/main/kotlin/org/polyfrost/chatting/Util.kt b/src/main/kotlin/org/polyfrost/chatting/Util.kt index 442abee..f3fdd3c 100644 --- a/src/main/kotlin/org/polyfrost/chatting/Util.kt +++ b/src/main/kotlin/org/polyfrost/chatting/Util.kt @@ -2,13 +2,24 @@ package org.polyfrost.chatting -import dev.deftu.omnicore.client.render.OmniResolution +import com.mojang.authlib.GameProfile +import dev.deftu.clipboard.Clipboard +import dev.deftu.omnicore.api.client.render.OmniResolution +import dev.deftu.omnicore.api.client.resourceManager +import dev.deftu.omnicore.api.color.OmniColor import net.minecraft.text.OrderedText import net.minecraft.text.Style import net.minecraft.util.Formatting import org.polyfrost.oneconfig.api.ui.v1.Notifications +import org.polyfrost.oneconfig.internal.DynamicPolyImage import org.polyfrost.oneconfig.utils.v1.dsl.mc +import org.polyfrost.polyui.data.PolyImage import org.polyfrost.polyui.unit.seconds +import java.io.ByteArrayInputStream +import java.io.ByteArrayOutputStream +import java.io.IOException +import java.io.InputStream +import javax.imageio.ImageIO val mcScale get() = OmniResolution.scaleFactor.toFloat() @@ -20,6 +31,11 @@ val editorMessages = mutableListOf( "§eDrag me around!" ) +val WHITE = OmniColor(-1) + +@JvmField +var currentSender: GameProfile? = null + fun OrderedText.asString(): String { val sb = StringBuilder() var lastStyle = Style.EMPTY @@ -69,7 +85,27 @@ private fun getFormattingCodes(style: Style, old: Style): String { return stringBuilder.toString() } +// messy code +@Throws(IOException::class) +fun InputStream.cropToInputStream(x: Int, y: Int, width: Int, height: Int): InputStream { + ByteArrayOutputStream().use { stream -> + ImageIO.write(ImageIO.read(this).getSubimage(x, y, width, height), "png", stream) + stream.flush() + return ByteArrayInputStream(stream.toByteArray()) + } +} + +fun getSkinFromProfile(gameProfile: GameProfile?): PolyImage? { + val profile = gameProfile ?: return null + mc.networkHandler?.getPlayerListEntry(profile.id)?.let { + resourceManager.open(it.skinTextures.comp_1626).cropToInputStream(8, 8, 8, 8).let { stream -> + return DynamicPolyImage("chatHead_${gameProfile.name}", stream, PolyImage.Type.Raster) + } + } + return null +} + fun String.copyToClipboard() { - mc.keyboard.clipboard = this + Clipboard.getInstance().string = this Notifications.enqueue(Notifications.Type.Info, "Chatting", "Copied \"$this\" to clipboard.", 3.seconds) } \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/chatting/component/ChatComponent.kt b/src/main/kotlin/org/polyfrost/chatting/component/ChatComponent.kt index 7326a25..e6dcca2 100644 --- a/src/main/kotlin/org/polyfrost/chatting/component/ChatComponent.kt +++ b/src/main/kotlin/org/polyfrost/chatting/component/ChatComponent.kt @@ -1,8 +1,8 @@ package org.polyfrost.chatting.component -import dev.deftu.omnicore.client.OmniKeyboard -import dev.deftu.omnicore.client.OmniMouse -import dev.deftu.omnicore.client.render.OmniMatrixStack +import dev.deftu.omnicore.api.client.input.OmniKeyboard +import dev.deftu.omnicore.api.client.input.OmniMouse +import dev.deftu.omnicore.api.client.render.OmniRenderingContext import net.minecraft.client.gui.hud.ChatHudLine import net.minecraft.client.util.ChatMessages import net.minecraft.text.Text @@ -12,6 +12,7 @@ import org.polyfrost.chatting.copyToClipboard import org.polyfrost.chatting.editorMessages import org.polyfrost.chatting.event.MouseActionEvent import org.polyfrost.chatting.event.NewMessageEvent +import org.polyfrost.chatting.hook.ChatHudLineHook import org.polyfrost.chatting.mcScale import org.polyfrost.chatting.mixin.ChatHudAccessor import org.polyfrost.oneconfig.api.event.v1.eventHandler @@ -19,6 +20,7 @@ import org.polyfrost.oneconfig.api.event.v1.events.MouseInputEvent import org.polyfrost.oneconfig.api.hud.v1.HudManager import org.polyfrost.oneconfig.api.hud.v1.LegacyHud import org.polyfrost.oneconfig.api.hud.v1.events.HudEditorToggleEvent +import org.polyfrost.oneconfig.api.ui.v1.internal.GLRendererImpl import org.polyfrost.oneconfig.utils.v1.dsl.mc import org.polyfrost.polyui.PolyUI import org.polyfrost.polyui.animate.Animation @@ -128,11 +130,11 @@ class ChatComponent(val window: ChatWindow) : LegacyHud.LegacyHudComponent(windo } else { (elements.size - window.lineLimit).toFloat() } - val target = (scrollAmount.to + amount).coerceIn(0f..maxAmount) - if (target == scrollAmount.to) return + val target = round(scrollAmount.value + amount * if (OmniKeyboard.isShiftKeyPressed) 7f else 1f).coerceIn(0f..maxAmount) + if (target == scrollAmount.value) return if (window.smoothScrolling) { val distance = abs(target - scrollAmount.value) - scrollAmount = Linear((50 * distance).ms, scrollAmount.value, target) + scrollAmount = Linear((75 * distance).ms, scrollAmount.value, target) } else { scrollAmount = DummyAnimation(target) } @@ -188,18 +190,15 @@ class ChatComponent(val window: ChatWindow) : LegacyHud.LegacyHudComponent(windo if (icon != null) { i -= icon.width + 4 + 2 } - - val hasHead = false - + val head = (message as ChatHudLineHook).`chatting$getHead`() + val hasHead = head != null if (hasHead) { i -= 10 } - val lines = ChatMessages.breakRenderedChatMessageLines(message.comp_893, i, mc.textRenderer) - lines.forEach { val visible = ChatHudLine.Visible(message.creationTick(), it, message.indicator(), it == lines.last()) - val element = ChatLineElement(visible) + val element = ChatLineElement(visible, hasHead && it == lines.first(), head) elements.add(element) } @@ -216,22 +215,6 @@ class ChatComponent(val window: ChatWindow) : LegacyHud.LegacyHudComponent(windo } } - fun drawLegacy(stack: OmniMatrixStack) { - if (elements.isEmpty()) return - stack.push() - stack.translate(x / mcScale, y / mcScale, 0f) - stack.scale(scaleX, scaleY, 1f) - stack.translate(0f, -translateAmount * 9, 1f) - stack.translate(4f, 1f, 0f) - for ((index, element) in elements.withIndex()) { - if (!element.renders) continue - if (index !in drawingStart..drawingEnd) continue - element.render(stack) - stack.translate(0f, 9f, 0f) - } - stack.pop() - } - override var width = (this as Component).width override var height = (this as Component).height @@ -261,7 +244,7 @@ class ChatComponent(val window: ChatWindow) : LegacyHud.LegacyHudComponent(windo override fun render() { renderer.pushScissor(x, y, width * scaleX, height * scaleY) - renderer.translate(0f, -translateAmount * lineHeight) + renderer.translate(x, y -translateAmount * lineHeight) for ((index, element) in elements.withIndex()) { if (!element.renders) continue if (index !in drawingStart..drawingEnd) continue @@ -276,14 +259,34 @@ class ChatComponent(val window: ChatWindow) : LegacyHud.LegacyHudComponent(windo window.bgColor } }.asMutable() - renderer.rect(x, y, width * scaleX, lineHeight.toFloat(), color) - val indicator = element.visible.indicator - if (indicator != null) { + renderer.rect(0f, 0f, width * scaleX, lineHeight.toFloat(), color) + if (element.hasHead) { + renderer.image(element.head!!, 4 * mcScale, 1 * mcScale, 8f * mcScale * scaleX, 8f * mcScale * scaleY) + } + element.visible.indicator?.let { indicator -> val ac = indicator.comp_899 or (element.alpha shl 24) - renderer.rect(x, y, 2 * mcScale * scaleX, lineHeight.toFloat(), argb(ac)) + renderer.rect(0f, 0f, 2 * mcScale * scaleX, lineHeight.toFloat(), argb(ac)) } renderer.translate(0f, lineHeight.toFloat()) } renderer.popScissor() } + + fun drawLegacy(ctx: OmniRenderingContext) { + if (elements.isEmpty()) return + ctx.withScissor(20, 20, 20, 20) { + val matrices = ctx.matrices + matrices.push() + matrices.translate(x / mcScale, y / mcScale, 0f) + matrices.scale(scaleX, scaleY, 1f) + matrices.translate(4f, -translateAmount * 9 + 1f, 0f) + for ((index, element) in elements.withIndex()) { + if (!element.renders) continue + if (index !in drawingStart..drawingEnd) continue + element.render(ctx) + matrices.translate(0f, 9f, 0f) + } + matrices.pop() + } + } } \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/chatting/component/ChatLineElement.kt b/src/main/kotlin/org/polyfrost/chatting/component/ChatLineElement.kt index 26aafb9..c6767cb 100644 --- a/src/main/kotlin/org/polyfrost/chatting/component/ChatLineElement.kt +++ b/src/main/kotlin/org/polyfrost/chatting/component/ChatLineElement.kt @@ -1,17 +1,18 @@ package org.polyfrost.chatting.component -import dev.deftu.omnicore.client.render.OmniGameRendering -import dev.deftu.omnicore.client.render.OmniMatrixStack +import dev.deftu.omnicore.api.client.render.OmniRenderingContext import net.minecraft.client.gui.hud.ChatHudLine -import net.minecraft.util.math.ColorHelper +import org.polyfrost.chatting.WHITE import org.polyfrost.chatting.asString +import org.polyfrost.polyui.data.PolyImage import kotlin.math.roundToInt -class ChatLineElement(val visible: ChatHudLine.Visible) { +class ChatLineElement(val visible: ChatHudLine.Visible, val hasHead: Boolean, val head: PolyImage?) { val message = visible.comp_896.asString() var opacity = 0.0 + get() = field set(value) { field = value alpha = (255 * value).roundToInt() @@ -21,8 +22,9 @@ class ChatLineElement(val visible: ChatHudLine.Visible) { var renders = false - fun render(stack: OmniMatrixStack) { + fun render(ctx: OmniRenderingContext) { if (alpha <= 3) return - OmniGameRendering.drawText(stack, message, 0f, 0f, ColorHelper.withAlpha(alpha, -1), true) + val x = if (hasHead) 10f else 0f + ctx.renderText(message, x, 0f, WHITE.withAlpha(alpha), true) } } \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/chatting/hook/ChatHudLineHook.kt b/src/main/kotlin/org/polyfrost/chatting/hook/ChatHudLineHook.kt new file mode 100644 index 0000000..769adae --- /dev/null +++ b/src/main/kotlin/org/polyfrost/chatting/hook/ChatHudLineHook.kt @@ -0,0 +1,12 @@ +package org.polyfrost.chatting.hook + +import com.mojang.authlib.GameProfile +import org.polyfrost.polyui.data.PolyImage + +interface ChatHudLineHook { + + fun `chatting$setHead`(head: PolyImage?) + + fun `chatting$getHead`(): PolyImage? + +} \ No newline at end of file diff --git a/src/main/resources/mixins.chatting.json b/src/main/resources/mixins.chatting.json index 6232be2..8fd7cd5 100644 --- a/src/main/resources/mixins.chatting.json +++ b/src/main/resources/mixins.chatting.json @@ -8,7 +8,12 @@ }, "client": [ "ChatHudAccessor", - "ChatHudMixin" + "ChatHudLineMixin", + "ChatHudMixin", + "MessageHandlerMixin" ], - "verbose": true + "verbose": true, + "mixins": [ + "RendererImplMixin" + ] } From 42496c5fbf181c7eafdefb29fe75f7bb63e046df Mon Sep 17 00:00:00 2001 From: ImToggle <98242902+ImToggle@users.noreply.github.com> Date: Thu, 25 Sep 2025 20:36:36 +0800 Subject: [PATCH 13/30] message hover/click event --- build.gradle.kts | 20 +-------- .../chatting/mixin/ChatHudMixin.java | 26 ++++++++++-- .../kotlin/org/polyfrost/chatting/Chatting.kt | 4 +- .../kotlin/org/polyfrost/chatting/Util.kt | 23 +++++++++++ .../chatting/component/ChatComponent.kt | 41 ++++++++++++------- 5 files changed, 76 insertions(+), 38 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index dfde574..850caac 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -14,25 +14,9 @@ plugins { id("dev.deftu.gradle.tools.minecraft.releases") version(dgtVersion) // Applies the Minecraft auto-releasing plugin, which allows you to automatically release your mod to CurseForge and Modrinth. } -dependencies { - implementation("dev.deftu:copycat:0.1.3") - listOf( - "windows-x64", - "windows-x86", - "linux-x64", - "linux-x86", - "linux-arm", - "linux-arm64", - "osx-x64", - "osx-arm64" - ).forEach { target -> - runtimeOnly("dev.deftu:copycat-natives-$target:0.1.3") - } -} - toolkitLoomHelper { useOneConfig { - version = "1.0.0-alpha.150" + version = "1.0.0-alpha.151" loaderVersion = "1.1.0-alpha.49" for (module in arrayOf("commands", "config", "config-impl", "events", "internal", "ui", "utils")) { @@ -41,7 +25,7 @@ toolkitLoomHelper { } useDevAuth("1.2.1") - useMixinExtras("0.4.1") + useMixinExtras("0.5.0") // Turns off the server-side run configs, as we're building a client-sided mod. disableRunConfigs(GameSide.SERVER) diff --git a/src/main/java/org/polyfrost/chatting/mixin/ChatHudMixin.java b/src/main/java/org/polyfrost/chatting/mixin/ChatHudMixin.java index a475c59..d87bb57 100644 --- a/src/main/java/org/polyfrost/chatting/mixin/ChatHudMixin.java +++ b/src/main/java/org/polyfrost/chatting/mixin/ChatHudMixin.java @@ -5,6 +5,7 @@ import net.minecraft.client.gui.hud.ChatHudLine; import net.minecraft.client.gui.hud.MessageIndicator; import net.minecraft.network.message.MessageSignatureData; +import net.minecraft.text.Style; import net.minecraft.text.Text; import org.polyfrost.chatting.Util; import org.polyfrost.chatting.event.NewMessageEvent; @@ -14,14 +15,15 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(ChatHud.class) public class ChatHudMixin { - @Inject(method = "render", at = @At("HEAD"), cancellable = true) - private void onRender(CallbackInfo ci) { - ci.cancel(); - } +// @Inject(method = "render", at = @At("HEAD"), cancellable = true) +// private void onRender(CallbackInfo ci) { +// ci.cancel(); +// } @Inject(method = "addMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignatureData;Lnet/minecraft/client/gui/hud/MessageIndicator;)V", at = @At("TAIL")) private void createMessage(Text text, MessageSignatureData messageSignatureData, MessageIndicator messageIndicator, CallbackInfo ci, @Local(ordinal = 0) ChatHudLine chatHudLine) { @@ -29,4 +31,20 @@ private void createMessage(Text text, MessageSignatureData messageSignatureData, EventManager.INSTANCE.post(new NewMessageEvent(chatHudLine)); } + @Inject(method = "getTextStyleAt", at = @At("HEAD"), cancellable = true) + private void styleAt(double d, double e, CallbackInfoReturnable