Migrate from Yarn to Mojang official mappings

This commit is contained in:
CPTProgrammer 2026-04-17 05:29:59 +08:00
parent a9e4fb14b8
commit 36a7c48531
11 changed files with 48 additions and 49 deletions

View File

@ -67,7 +67,7 @@ loom {
dependencies { dependencies {
// To change the versions see the gradle.properties file or the ./properties/${minecraftVersion}.properties file // To change the versions see the gradle.properties file or the ./properties/${minecraftVersion}.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}" minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" mappings loom.officialMojangMappings()
modImplementation "net.fabricmc:fabric-loader:${project.fabric_loader_version}" modImplementation "net.fabricmc:fabric-loader:${project.fabric_loader_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version}+${project.targetVersion}" modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version}+${project.targetVersion}"

View File

@ -2,7 +2,6 @@ java_version=17
# Fabric Properties # Fabric Properties
# check these on https://fabricmc.net/develop # check these on https://fabricmc.net/develop
yarn_mappings=1.19.1+build.6
fabric_loader_version=0.16.10 fabric_loader_version=0.16.10
min_fabric_loader_version= min_fabric_loader_version=
fabric_api_version=0.58.4 fabric_api_version=0.58.4

View File

@ -2,7 +2,6 @@ java_version=17
# Fabric Properties # Fabric Properties
# check these on https://fabricmc.net/develop # check these on https://fabricmc.net/develop
yarn_mappings=1.19.3+build.5
fabric_loader_version=0.16.10 fabric_loader_version=0.16.10
min_fabric_loader_version= min_fabric_loader_version=
fabric_api_version=0.68.1 fabric_api_version=0.68.1

View File

@ -2,7 +2,6 @@ java_version=17
# Fabric Properties # Fabric Properties
# check these on https://fabricmc.net/develop # check these on https://fabricmc.net/develop
yarn_mappings=1.19+build.4
fabric_loader_version=0.16.10 fabric_loader_version=0.16.10
min_fabric_loader_version= min_fabric_loader_version=
fabric_api_version=0.55.1 fabric_api_version=0.55.1

View File

@ -2,7 +2,6 @@ java_version=17
# Fabric Properties # Fabric Properties
# check these on https://fabricmc.net/develop # check these on https://fabricmc.net/develop
yarn_mappings=1.20.3+build.1
fabric_loader_version=0.16.10 fabric_loader_version=0.16.10
min_fabric_loader_version= min_fabric_loader_version=
fabric_api_version=0.91.1 fabric_api_version=0.91.1

View File

@ -2,7 +2,6 @@ java_version=17
# Fabric Properties # Fabric Properties
# check these on https://fabricmc.net/develop # check these on https://fabricmc.net/develop
yarn_mappings=1.20+build.1
fabric_loader_version=0.16.10 fabric_loader_version=0.16.10
min_fabric_loader_version= min_fabric_loader_version=
fabric_api_version=0.83.0 fabric_api_version=0.83.0

View File

@ -2,7 +2,6 @@ java_version=21
# Fabric Properties # Fabric Properties
# check these on https://fabricmc.net/develop # check these on https://fabricmc.net/develop
yarn_mappings=1.21+build.9
fabric_loader_version=0.16.10 fabric_loader_version=0.16.10
min_fabric_loader_version= min_fabric_loader_version=
fabric_api_version=0.100.1 fabric_api_version=0.100.1

View File

@ -1,16 +1,16 @@
package cn.revaria.chatplus.mixin; package cn.revaria.chatplus.mixin;
#if MC_VER <= MC_1_19 #if MC_VER <= MC_1_19
import net.minecraft.server.filter.FilteredMessage; import net.minecraft.resources.ResourceKey;
import net.minecraft.util.registry.RegistryKey; import net.minecraft.server.network.FilteredText;
#endif #endif
import cn.revaria.chatplus.plugin.annotation.DisableIfModsLoaded; import cn.revaria.chatplus.plugin.annotation.DisableIfModsLoaded;
import net.minecraft.network.message.MessageType; import net.minecraft.network.chat.ChatType;
import net.minecraft.network.message.SignedMessage; import net.minecraft.network.chat.PlayerChatMessage;
import net.minecraft.server.PlayerManager; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.network.ServerPlayNetworkHandler; import net.minecraft.server.network.ServerGamePacketListenerImpl;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.players.PlayerList;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.Redirect;
@ -18,26 +18,31 @@ import org.spongepowered.asm.mixin.injection.Redirect;
import static cn.revaria.chatplus.util.TextStyleFormatter.applyStyle; import static cn.revaria.chatplus.util.TextStyleFormatter.applyStyle;
@DisableIfModsLoaded("styledchat") @DisableIfModsLoaded("styledchat")
@Mixin(ServerPlayNetworkHandler.class) @Mixin(ServerGamePacketListenerImpl.class)
public abstract class ChatMixin { public abstract class ChatMixin {
@Redirect(method = "handleDecoratedMessage", at = @At(value = "INVOKE", target = @Redirect(method = "broadcastChatMessage", at = @At(value = "INVOKE", target =
#if MC_VER <= MC_1_19 #if MC_VER <= MC_1_19
"Lnet/minecraft/server/PlayerManager;broadcast(Lnet/minecraft/server/filter/FilteredMessage;Lnet/minecraft/server/network/ServerPlayerEntity;Lnet/minecraft/util/registry/RegistryKey;)V" "Lnet/minecraft/server/players/PlayerList;broadcastChatMessage(Lnet/minecraft/server/network/FilteredText;Lnet/minecraft/server/level/ServerPlayer;Lnet/minecraft/resources/ResourceKey;)V"
#else #else
"Lnet/minecraft/server/PlayerManager;broadcast(Lnet/minecraft/network/message/SignedMessage;Lnet/minecraft/server/network/ServerPlayerEntity;Lnet/minecraft/network/message/MessageType$Parameters;)V" "Lnet/minecraft/server/players/PlayerList;broadcastChatMessage(Lnet/minecraft/network/chat/PlayerChatMessage;Lnet/minecraft/server/level/ServerPlayer;Lnet/minecraft/network/chat/ChatType$Bound;)V"
#endif #endif
)) ))
#if MC_VER <= MC_1_19 #if MC_VER <= MC_1_19
private void replaceText(PlayerManager instance, FilteredMessage<SignedMessage> message, ServerPlayerEntity sender, RegistryKey<MessageType> typeKey) { private void replaceText(PlayerList instance, FilteredText<PlayerChatMessage> message, ServerPlayer sender, ResourceKey<ChatType> typeKey) {
var newMessage = new FilteredMessage<>( var newMessage = new FilteredText<>(
message.raw().withUnsigned(applyStyle(message.raw().getContent(), sender)), message.raw().withUnsignedContent(applyStyle(message.raw().serverContent(), sender)),
message.filtered() != null ? message.filtered().withUnsigned(applyStyle(message.filtered().getContent(), sender)) : null message.filtered() != null ? message.filtered().withUnsignedContent(applyStyle(message.filtered().serverContent(), sender)) : null
); );
instance.broadcast(newMessage, sender, typeKey); instance.broadcastChatMessage(newMessage, sender, typeKey);
} }
#else #else
private void replaceText(PlayerManager instance, SignedMessage message, ServerPlayerEntity sender, MessageType.Parameters params) { private void replaceText(PlayerList instance, PlayerChatMessage message, ServerPlayer sender, ChatType.Bound params) {
instance.broadcast(message.withUnsignedContent(applyStyle(message.getContent(), sender)), sender, params); instance.broadcastChatMessage(
message.withUnsignedContent(
applyStyle(message.#if MC_VER <= MC_1_19_1 serverContent() #else decoratedContent() #endif, sender)
),
sender, params
);
} }
#endif #endif
} }

View File

@ -2,8 +2,8 @@ package cn.revaria.chatplus.mixin.compat;
import com.llamalad7.mixinextras.sugar.Local; import com.llamalad7.mixinextras.sugar.Local;
import com.llamalad7.mixinextras.sugar.ref.LocalRef; import com.llamalad7.mixinextras.sugar.ref.LocalRef;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.network.chat.Component;
import net.minecraft.text.Text; import net.minecraft.server.level.ServerPlayer;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo; import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
@ -35,7 +35,7 @@ import static cn.revaria.chatplus.util.TextStyleFormatter.applyStyle;
) )
public abstract class DynmapMixin { public abstract class DynmapMixin {
@Inject(method = "handleChat", at = @At("HEAD"), remap = false) @Inject(method = "handleChat", at = @At("HEAD"), remap = false)
private void modifyMessage(ServerPlayerEntity player, String message, CallbackInfo ci, @Local(argsOnly = true) LocalRef<String> messageRef) { private void modifyMessage(ServerPlayer player, String message, CallbackInfo ci, @Local(argsOnly = true) LocalRef<String> messageRef) {
messageRef.set(applyStyle(Text.of(message), player).getString()); messageRef.set(applyStyle(Component.nullToEmpty(message), player).getString());
} }
} }

View File

@ -2,7 +2,7 @@ package cn.revaria.chatplus.mixin.compat;
import eu.pb4.placeholders.api.PlaceholderContext; import eu.pb4.placeholders.api.PlaceholderContext;
import eu.pb4.styledchat.StyledChatUtils; import eu.pb4.styledchat.StyledChatUtils;
import net.minecraft.text.Text; import net.minecraft.network.chat.Component;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo; import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
@ -14,8 +14,8 @@ import static cn.revaria.chatplus.util.TextStyleFormatter.applyStyle;
@Pseudo @Pseudo
@Mixin(StyledChatUtils.class) @Mixin(StyledChatUtils.class)
public abstract class StyledChatMixin { public abstract class StyledChatMixin {
@Inject(method = "formatFor(Leu/pb4/placeholders/api/PlaceholderContext;Ljava/lang/String;)Lnet/minecraft/text/Text;", at = @At("RETURN"), cancellable = true) @Inject(method = "formatFor(Leu/pb4/placeholders/api/PlaceholderContext;Ljava/lang/String;)Lnet/minecraft/network/chat/Component;", at = @At("RETURN"), cancellable = true)
private static void modifyText(PlaceholderContext context, String input, CallbackInfoReturnable<Text> cir) { private static void modifyText(PlaceholderContext context, String input, CallbackInfoReturnable<Component> cir) {
cir.setReturnValue(applyStyle(cir.getReturnValue(), context.player())); cir.setReturnValue(applyStyle(cir.getReturnValue(), context.player()));
} }
} }

View File

@ -1,15 +1,15 @@
package cn.revaria.chatplus.util; package cn.revaria.chatplus.util;
#if MC_VER <= MC_1_20 #if MC_VER <= MC_1_20
import net.minecraft.text.LiteralTextContent; import net.minecraft.network.chat.contents.LiteralContents;
#else #else
import net.minecraft.text.PlainTextContent.Literal; import net.minecraft.network.chat.contents.PlainTextContents;
#endif #endif
import net.minecraft.item.ItemStack; import net.minecraft.network.chat.Component;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.network.chat.MutableComponent;
import net.minecraft.text.MutableText; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.text.Text; import net.minecraft.world.item.ItemStack;
import java.util.ArrayDeque; import java.util.ArrayDeque;
import java.util.Deque; import java.util.Deque;
@ -32,13 +32,13 @@ public class TextStyleFormatter {
* @param sourcePlayer Player used for item stack references * @param sourcePlayer Player used for item stack references
* @return Processed text with styling and item hover elements * @return Processed text with styling and item hover elements
*/ */
public static MutableText applyStyle(Text sourceText, ServerPlayerEntity sourcePlayer) { public static MutableComponent applyStyle(Component sourceText, ServerPlayer sourcePlayer) {
MutableText sourceMutableText = sourceText.copy(); MutableComponent sourceMutableText = sourceText.copy();
MutableText finalText = Text.empty().setStyle(sourceMutableText.getStyle()); MutableComponent finalText = Component.empty().setStyle(sourceMutableText.getStyle());
if (sourceText.getContent() instanceof #if MC_VER <= MC_1_20 LiteralTextContent #else Literal #endif plainTextContent) { if (sourceText.getContents() instanceof #if MC_VER <= MC_1_20 LiteralContents #else PlainTextContents #endif plainTextContent) {
String changedMessage = plainTextContent.string() String changedMessage = plainTextContent.text()
.replace('&', '§') .replace('&', '§')
.replace("§§", "&"); .replace("§§", "&");
String regex = "\\[item(?:=([1-9]))?\\]"; String regex = "\\[item(?:=([1-9]))?\\]";
@ -56,22 +56,22 @@ public class TextStyleFormatter {
} }
for (String message : messages) { for (String message : messages) {
finalText.append(Text.literal(message)); finalText.append(Component.literal(message));
if (!itemDeque.isEmpty()) { if (!itemDeque.isEmpty()) {
ItemStack itemStack; ItemStack itemStack;
if (itemDeque.getFirst() == MAIN_HAND) { if (itemDeque.getFirst() == MAIN_HAND) {
itemStack = sourcePlayer.getMainHandStack(); itemStack = sourcePlayer.getMainHandItem();
} else { } else {
itemStack = sourcePlayer.getInventory().getStack(itemDeque.getFirst() - 1); itemStack = sourcePlayer.getInventory().getItem(itemDeque.getFirst() - 1);
} }
finalText.append(itemStack.toHoverableText()); finalText.append(itemStack.getDisplayName());
itemDeque.removeFirst(); itemDeque.removeFirst();
} }
} }
} }
List<Text> sourceTexts = sourceMutableText.getSiblings(); List<Component> sourceTexts = sourceMutableText.getSiblings();
for (Text text : sourceTexts) { for (Component text : sourceTexts) {
finalText.append(applyStyle(text, sourcePlayer)); finalText.append(applyStyle(text, sourcePlayer));
} }