Skip to content

Commit

Permalink
stop chat from being cleared when the client enters a configuration p…
Browse files Browse the repository at this point in the history
…hase
  • Loading branch information
derNiklaas committed Feb 16, 2024
1 parent 6ba719b commit a4a5c44
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ noxesium_version=1.1.1
adventure_version=5.10.0

org.gradle.jvmargs=-Xmx4000m
mod_version=1.8.0
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class BuildBugsClientEntrypoint : ClientModInitializer {
private const val MOD_ID = "build-bugs"
val config = BuildBugsConfig.fromFile()
val version: Version = FabricLoader.getInstance().getModContainer(MOD_ID).get().metadata.version
// id taken from https://github.com/AsoDesu/IslandUtils/blob/main/src/main/resources/fabric.mod.json
val hasIslandUtils = FabricLoader.getInstance().isModLoaded("islandutils")
}

override fun onInitializeClient() {
Expand Down
12 changes: 12 additions & 0 deletions src/main/kotlin/de/derniklaas/buildbugs/mixin/ChatMixin.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.derniklaas.buildbugs.mixin

import de.derniklaas.buildbugs.BugCreator
import de.derniklaas.buildbugs.BuildBugsClientEntrypoint
import de.derniklaas.buildbugs.Constants
import de.derniklaas.buildbugs.utils.Utils
import net.minecraft.client.MinecraftClient
Expand Down Expand Up @@ -34,4 +35,15 @@ abstract class ChatMixin {

}
}

// Remove chat clear when switching servers when entering the reconfigure screen
@Inject(at = [At("HEAD")], method = ["Lnet/minecraft/class_338;method_1808(Z)V"], cancellable = true)
fun onClear(clearHistory: Boolean, info: CallbackInfo) {
// ignore if IslandUtils is present as it will also prevent the chat from being cleared
if (BuildBugsClientEntrypoint.hasIslandUtils) return
if (!Utils.isOnMCCServer()) return
if (!clearHistory) return

info.cancel()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package de.derniklaas.buildbugs.mixin

import de.derniklaas.buildbugs.BuildBugsClientEntrypoint
import net.minecraft.client.MinecraftClient
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(MinecraftClient::class)
abstract class ClearChatOnDisconnectMixin {

// Clear the chat when disconnecting from a server
// This is done to prevent the chat from being filled with messages from the previous server
@Inject(at = [At("HEAD")], method = ["Lnet/minecraft/class_310;method_18096(Lnet/minecraft/class_437;)V"])
fun onDisconnect(info: CallbackInfo) {
// ignore if IslandUtils is present as it will also clear the chat
if(BuildBugsClientEntrypoint.hasIslandUtils) return
// Clear the chat when disconnecting from a server
MinecraftClient.getInstance().inGameHud.clear()
}

}
3 changes: 2 additions & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"minecraft": "~${minecraft_version}",
"java": ">=17",
"fabric-language-kotlin": ">=${fabric_kotlin_version}",
"noxesium": ">=1.1.1"
"noxesium": ">=${noxesium_version}",
"adventure-platform-fabric": ">=${adventure_version}"
}
}

0 comments on commit a4a5c44

Please sign in to comment.