-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add mixin for longer chat messages + Config Syncing (#252)
* Add mixin for longer chat messages * register GuiChat mixin on client only to prevent crash on server * both handlers in MixinC01PacketChatMessage_LongerMessages can be merged into one * hardcode max sent message length to 256 * add a separate setting for longer sent messages feature * Always have the packet size change on client and server The config option now just controls whether the client can send longer messages, which most people wont disable. * Spotless apply for branch sb-longer-chat-messages for #252 (#274) Co-authored-by: GitHub GTNH Actions <> * Add config syncing between server and client * fix spotless formatting --------- Co-authored-by: Alexdoru <[email protected]> Co-authored-by: Martin Robertz <[email protected]> Co-authored-by: Caedis <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
ccaf8b4
commit 727d0dc
Showing
8 changed files
with
122 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...itchej123/hodgepodge/mixins/early/minecraft/MixinC01PacketChatMessage_LongerMessages.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.mitchej123.hodgepodge.mixins.early.minecraft; | ||
|
||
import net.minecraft.network.play.client.C01PacketChatMessage; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.Constant; | ||
import org.spongepowered.asm.mixin.injection.ModifyConstant; | ||
|
||
import com.mitchej123.hodgepodge.Common; | ||
|
||
@Mixin(C01PacketChatMessage.class) | ||
public class MixinC01PacketChatMessage_LongerMessages { | ||
|
||
@ModifyConstant(method = { "<init>(Ljava/lang/String;)V", "readPacketData" }, constant = @Constant(intValue = 100)) | ||
public int hodgepodge$LongerMessages(int constant) { | ||
return Common.config.longerSentMessages ? 256 : constant; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...in/java/com/mitchej123/hodgepodge/mixins/early/minecraft/MixinGuiChat_LongerMessages.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.mitchej123.hodgepodge.mixins.early.minecraft; | ||
|
||
import net.minecraft.client.gui.GuiChat; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.Constant; | ||
import org.spongepowered.asm.mixin.injection.ModifyConstant; | ||
|
||
import com.mitchej123.hodgepodge.Common; | ||
|
||
@Mixin(GuiChat.class) | ||
public class MixinGuiChat_LongerMessages { | ||
|
||
@ModifyConstant(method = "initGui", constant = @Constant(intValue = 100)) | ||
public int hodgepodge$LongerMessages(int constant) { | ||
return Common.config.longerSentMessages ? 256 : constant; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/com/mitchej123/hodgepodge/net/MessageConfigSync.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.mitchej123.hodgepodge.net; | ||
|
||
import com.mitchej123.hodgepodge.Common; | ||
import com.mitchej123.hodgepodge.LoadingConfig; | ||
|
||
import cpw.mods.fml.common.network.simpleimpl.IMessage; | ||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; | ||
import cpw.mods.fml.common.network.simpleimpl.MessageContext; | ||
import io.netty.buffer.ByteBuf; | ||
|
||
public class MessageConfigSync implements IMessage, IMessageHandler<MessageConfigSync, IMessage> { | ||
|
||
private boolean longerSentMessages; | ||
|
||
public MessageConfigSync() {} | ||
|
||
public MessageConfigSync(LoadingConfig config) { | ||
longerSentMessages = config.longerSentMessages; | ||
} | ||
|
||
@Override | ||
public void fromBytes(ByteBuf buf) { | ||
longerSentMessages = buf.readBoolean(); | ||
} | ||
|
||
@Override | ||
public void toBytes(ByteBuf buf) { | ||
buf.writeBoolean(longerSentMessages); | ||
} | ||
|
||
public boolean isLongerSentMessages() { | ||
return longerSentMessages; | ||
} | ||
|
||
@Override | ||
public IMessage onMessage(MessageConfigSync message, MessageContext ctx) { | ||
Common.config.longerSentMessages = message.isLongerSentMessages(); | ||
|
||
return null; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/mitchej123/hodgepodge/net/NetworkHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.mitchej123.hodgepodge.net; | ||
|
||
import com.mitchej123.hodgepodge.Hodgepodge; | ||
|
||
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper; | ||
import cpw.mods.fml.relauncher.Side; | ||
|
||
public class NetworkHandler { | ||
|
||
public static final SimpleNetworkWrapper instance = new SimpleNetworkWrapper(Hodgepodge.MODID); | ||
|
||
public static void init() { | ||
instance.registerMessage(MessageConfigSync.class, MessageConfigSync.class, 0, Side.CLIENT); | ||
} | ||
} |