Skip to content

Commit

Permalink
feat: Make Adventure's Component a Message
Browse files Browse the repository at this point in the history
  • Loading branch information
zml2008 committed Dec 15, 2022
1 parent b7ebe4a commit 9c1b616
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package net.kyori.adventure.platform.fabric.impl.mixin.api;

import com.mojang.brigadier.Message;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.spongepowered.asm.mixin.Mixin;

@Mixin(Component.class)
public interface ComponentMixin extends Message {
@Override
default String getString() {
return PlainTextComponentSerializer.plainText().serialize((Component) this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package net.kyori.adventure.platform.fabric.impl.mixin.minecraft.network.chat;

import com.mojang.brigadier.Message;
import net.kyori.adventure.platform.fabric.impl.AdventureCommon;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.translation.GlobalTranslator;
import net.minecraft.network.chat.ComponentUtils;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyVariable;

@Mixin(ComponentUtils.class)
public class ComponentUtilsMixin {
@ModifyVariable(method = "fromMessage(Lcom/mojang/brigadier/Message;)Lnet/minecraft/network/chat/Component;", at = @At("HEAD"), argsOnly = true)
private static Message adventure$wrapComponent(final Message source) {
if (source instanceof Component adv) {
return AdventureCommon.SIDE_PROXY.createWrappedComponent(
adv,
AdventureCommon.localePartition(),
GlobalTranslator.renderer().mapContext(AdventureCommon.localePartition())
);
}

return source;
}
}
4 changes: 3 additions & 1 deletion src/mixin/resources/adventure-platform-fabric.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
"package": "net.kyori.adventure.platform.fabric.impl.mixin",
"parent": "adventure-platform-fabric.parent.mixins.json",
"mixins": [
"api.ComponentMixin",
"api.KeyMixin",
"api.SignedMessageMixin",
"authlib.GameProfileMixin",
"brigadier.exceptions.CommandSyntaxExceptionMixin",
"minecraft.commands.CommandSourceStackMixin",
"minecraft.commands.CommandsMixin",
"minecraft.commands.CommandSourceStackMixin",
"minecraft.commands.synchronization.ArgumentTypeInfosMixin",
"minecraft.commands.synchronization.ArgumentUtilsMixin",
"minecraft.network.FriendlyByteBufMixin",
"minecraft.network.PacketEncoderMixin",
"minecraft.network.chat.ComponentMixin",
"minecraft.network.chat.ComponentMixin$SerializerMixin",
"minecraft.network.chat.ComponentUtilsMixin",
"minecraft.network.chat.MessageSignatureMixin",
"minecraft.network.chat.PlayerChatMessageMixin",
"minecraft.network.chat.Style_SerializerMixin",
Expand Down

0 comments on commit 9c1b616

Please sign in to comment.