Skip to content
This repository has been archived by the owner on Nov 20, 2023. It is now read-only.

Commit

Permalink
Improved mod compatibility.
Browse files Browse the repository at this point in the history
Instead of several precise mixins caching messages at each message source, I've switched to a single mixin which handles multiple sources (with no hardcoded assumptions) for improved compatibility with other chat mods.
  • Loading branch information
Giggitybyte committed Oct 1, 2021
1 parent 6183232 commit 336c459
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 145 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ minecraft_version=1.17.1
yarn_mappings=1.17.1+build.61
loader_version=0.11.7

mod_version=1.1.0
mod_version=1.2.0
maven_group=me.thegiggitybyte
archives_base_name=chathistory

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,45 +1,31 @@
package me.thegiggitybyte.chathistory.mixin;

import com.mojang.authlib.GameProfile;
import me.thegiggitybyte.chathistory.ChatHistory;
import me.thegiggitybyte.chathistory.ChatMessage;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.ClientConnection;
import net.minecraft.network.MessageType;
import net.minecraft.server.PlayerManager;
import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.MutableText;
import net.minecraft.util.UserCache;
import net.minecraft.util.Util;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.WorldProperties;
import net.minecraft.text.Text;
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;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

import java.util.Optional;
import java.util.UUID;
import java.util.function.Function;

@Environment(EnvType.SERVER)
@Mixin(PlayerManager.class)
public abstract class PlayerManagerMixin {
public class PlayerManagerMixin {

@Inject(
method = "onPlayerConnect",
locals = LocalCapture.CAPTURE_FAILHARD,
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/server/PlayerManager;broadcastChatMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/MessageType;Ljava/util/UUID;)V"
)
)
public void cacheJoinMessage(ClientConnection connection, ServerPlayerEntity player, CallbackInfo ci, GameProfile gameProfile, UserCache userCache, Optional optional, String string, NbtCompound nbtCompound, RegistryKey registryKey, ServerWorld serverWorld, ServerWorld serverWorld3, String string2, WorldProperties worldProperties, ServerPlayNetworkHandler serverPlayNetworkHandler, MutableText content) { // :(
var message = new ChatMessage(content, MessageType.SYSTEM, Util.NIL_UUID);
ChatHistory.MESSAGE_CACHE.add(message);
@Inject(method = "broadcast", at = @At("HEAD"))
public void cacheMessage(Text content, Function<ServerPlayerEntity, Text> messageFactory, MessageType type, UUID sender, CallbackInfo ci) {
ChatHistory.MESSAGE_CACHE.add(new ChatMessage(content, type, sender));
}

@Inject(method = "broadcastChatMessage", at = @At("HEAD"))
public void cacheMessage(Text content, MessageType type, UUID sender, CallbackInfo ci) {
ChatHistory.MESSAGE_CACHE.add(new ChatMessage(content, type, sender));
}

@Inject(
Expand Down

This file was deleted.

This file was deleted.

10 changes: 5 additions & 5 deletions src/main/resources/chathistory.mixins.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"required": true,
"minVersion": "0.8",
"package": "me.thegiggitybyte.chathistory.mixin",
"compatibilityLevel": "JAVA_16",

"package": "me.thegiggitybyte.chathistory.mixin",

"server": [
"PlayerManagerMixin",
"ServerPlayerEntityMixin",
"ServerPlayNetworkHandlerMixin",
"PlayerAdvancementTrackerMixin"
"PlayerManagerMixin"
],

"injectors": {
"defaultRequire": 1
}
Expand Down

0 comments on commit 336c459

Please sign in to comment.