Skip to content

Commit 97e4dbb

Browse files
committed
Port chat toggling
fix #44
1 parent 093b74c commit 97e4dbb

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

src/client/java/com/coflnet/CoflModClient.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ public class CoflModClient implements ClientModInitializer {
112112
public static CoflModClient instance;
113113
public static SignBlockEntity sign = null;
114114
public static String pendingBazaarSearch = null;
115+
public static boolean flipperChatOnlyMode = false;
115116

116117
// Staggered refresh tracking: inventory name -> last request time
117118
private static final Map<String, Long> lastRefreshTimePerInventory = new HashMap<>();
@@ -232,6 +233,17 @@ public void onInitializeClient() {
232233
CoflSkyCommand.processCommand(new String[]{"chat"}, username);
233234
return 1;
234235
})
236+
.then(ClientCommandManager.literal("toggle")
237+
.executes(context -> {
238+
// /fc toggle - toggles flipper chat only mode
239+
flipperChatOnlyMode = !flipperChatOnlyMode;
240+
String message = flipperChatOnlyMode ?
241+
"§aFlipper Chat Only Mode enabled. All messages will be sent to flipper chat." :
242+
"§cFlipper Chat Only Mode disabled.";
243+
sendChatMessage(message);
244+
return 1;
245+
})
246+
)
235247
.then(ClientCommandManager.argument("args", StringArgumentType.greedyString())
236248
.suggests((context, builder) -> {
237249
String[] suggestions = {":tableflip:", ":sad:", ":smile:", ":grin:", ":heart:", ":skull:", ":airplane:", ":check:", "<3",
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.coflnet.mixin;
2+
3+
import com.coflnet.CoflModClient;
4+
import CoflCore.CoflSkyCommand;
5+
import net.minecraft.client.MinecraftClient;
6+
import net.minecraft.client.gui.screen.ChatScreen;
7+
import org.spongepowered.asm.mixin.Mixin;
8+
import org.spongepowered.asm.mixin.injection.At;
9+
import org.spongepowered.asm.mixin.injection.Inject;
10+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
11+
12+
@Mixin(ChatScreen.class)
13+
public class ChatScreenMixin {
14+
15+
@Inject(method = "sendMessage", at = @At("HEAD"), cancellable = true)
16+
private void onSendMessage(String message, boolean addToHistory, CallbackInfo ci) {
17+
// If flipper chat only mode is enabled and the message is not a command
18+
if (CoflModClient.flipperChatOnlyMode && !message.startsWith("/")) {
19+
// Cancel the original message
20+
ci.cancel();
21+
22+
// Send it to flipper chat instead
23+
MinecraftClient client = MinecraftClient.getInstance();
24+
if (client.player != null) {
25+
String username = client.player.getName().getString();
26+
String[] args = new String[message.split(" ").length + 1];
27+
args[0] = "chat";
28+
System.arraycopy(message.split(" "), 0, args, 1, message.split(" ").length);
29+
CoflSkyCommand.processCommand(args, username);
30+
}
31+
}
32+
}
33+
}

src/client/resources/coflmod.client.mixins.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"package": "com.coflnet.mixin",
44
"compatibilityLevel": "JAVA_21",
55
"client": [
6+
"ChatScreenMixin",
67
"ClientPlayerEntityMixin",
78
"HandledScreenMixin",
89
"InventoryScreenMixin",

0 commit comments

Comments
 (0)