Skip to content

Commit

Permalink
修复各版本Mixin报错
Browse files Browse the repository at this point in the history
  • Loading branch information
Xujiayao committed Feb 10, 2024
1 parent 41df66e commit 3fd5fb3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public abstract class MixinPlayerAdvancements {
@Shadow
public abstract AdvancementProgress getOrStartProgress(AdvancementHolder advancementHolder);

@Inject(method = "award", at = @At(value = "INVOKE", target = "Lnet/minecraft/advancements/AdvancementRewards;grant(Lnet/minecraft/server/level/ServerPlayer;)V", shift = At.Shift.AFTER))
@Inject(method = "award(Lnet/minecraft/advancements/AdvancementHolder;Ljava/lang/String;)Z", at = @At(value = "INVOKE", target = "Lnet/minecraft/advancements/AdvancementRewards;grant(Lnet/minecraft/server/level/ServerPlayer;)V", shift = At.Shift.AFTER))
private void award(AdvancementHolder advancementHolder, String string, CallbackInfoReturnable<Boolean> cir) {
MinecraftEvents.PLAYER_ADVANCEMENT.invoker().advancement(player, advancementHolder, getOrStartProgress(advancementHolder).isDone());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,21 @@ private void broadcastChatMessage(PlayerChatMessage playerChatMessage, CommandSo
//$$ @Inject(method = "broadcastChatMessage(Lnet/minecraft/server/network/FilteredText;Lnet/minecraft/commands/CommandSourceStack;Lnet/minecraft/resources/ResourceKey;)V", at = @At("HEAD"))
//$$ private void broadcastChatMessage(FilteredText<PlayerChatMessage> filteredText, CommandSourceStack commandSourceStack, ResourceKey<ChatType> resourceKey, CallbackInfo ci) {
//$$ MinecraftEvents.SERVER_MESSAGE.invoker().message(filteredText.filtered().serverContent().getString(), commandSourceStack);
//$$ // TODO filtered() or raw() ?
//$$ }
//#endif
// TODO This feature has been removed in versions 1.18.2 and below due to compatibility issues (#197)

@Inject(method = "placeNewPlayer", at = @At("RETURN"))
//#if MC >= 12002
@Inject(method = "placeNewPlayer(Lnet/minecraft/network/Connection;Lnet/minecraft/server/level/ServerPlayer;Lnet/minecraft/server/network/CommonListenerCookie;)V", at = @At("RETURN"))
private void placeNewPlayer(Connection connection, ServerPlayer serverPlayer, CommonListenerCookie commonListenerCookie, CallbackInfo ci) {
//#else
//$$ @Inject(method = "placeNewPlayer(Lnet/minecraft/network/Connection;Lnet/minecraft/server/level/ServerPlayer;)V", at = @At("RETURN"))
//$$ private void placeNewPlayer(Connection connection, ServerPlayer serverPlayer, CallbackInfo ci) {
//#endif
MinecraftEvents.PLAYER_JOIN.invoker().join(serverPlayer);
}

@Inject(method = "remove", at = @At("HEAD"))
@Inject(method = "remove(Lnet/minecraft/server/level/ServerPlayer;)V", at = @At("HEAD"))
private void remove(ServerPlayer serverPlayer, CallbackInfo ci) {
MinecraftEvents.PLAYER_QUIT.invoker().quit(serverPlayer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

//#if MC == 11900
//$$ import java.util.Objects;
//#endif
import java.util.Optional;

import static com.xujiayao.mcdiscordchat.Main.SERVER;
Expand All @@ -43,21 +46,26 @@ public class MixinServerGamePacketListenerImpl {
@Shadow
private ServerPlayer player;

//#if MC > 11802
@Inject(method = "broadcastChatMessage", at = @At("HEAD"), cancellable = true)
//#if MC > 11900
@Inject(method = "broadcastChatMessage(Lnet/minecraft/network/chat/PlayerChatMessage;)V", at = @At("HEAD"), cancellable = true)
private void broadcastChatMessage(PlayerChatMessage playerChatMessage, CallbackInfo ci) {
Optional<Component> result = MinecraftEvents.PLAYER_MESSAGE.invoker().message(player, playerChatMessage.decoratedContent().getString());
if (result.isPresent()) {
//#if MC > 11900
SERVER.getPlayerList().broadcastChatMessage(playerChatMessage.withUnsignedContent(result.get()), this.player, ChatType.bind(ChatType.CHAT, player));
//#else
//$$ SERVER.getPlayerList().broadcastChatMessage(FilteredText.passThrough(playerChatMessage.withUnsignedContent(result.get())), this.player, ChatType.CHAT);
//#endif
ci.cancel();
}
}
//#elseif MC == 11900
//$$ @Inject(method = "broadcastChatMessage(Lnet/minecraft/server/network/FilteredText;)V", at = @At("HEAD"), cancellable = true)
//$$ private void broadcastChatMessage(FilteredText<PlayerChatMessage> filteredText, CallbackInfo ci) {
//$$ Optional<Component> result = MinecraftEvents.PLAYER_MESSAGE.invoker().message(player, Objects.requireNonNull(filteredText.filtered()).serverContent().getString());
//$$ if (result.isPresent()) {
//$$ SERVER.getPlayerList().broadcastChatMessage(FilteredText.passThrough(filteredText.filtered().withUnsignedContent(result.get())), this.player, ChatType.CHAT);
//$$ ci.cancel();
//$$ }
//$$ }
//#elseif MC > 11605
//$$ @Inject(method = "handleChat(Lnet/minecraft/server/network/TextFilter$FilteredText;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;broadcastMessage(Lnet/minecraft/network/chat/Component;Ljava/util/Function;Lnet/minecraft/network/chat/ChatType;Ljava/util/UUID;)V"), cancellable = true)
//$$ @Inject(method = "handleChat(Lnet/minecraft/server/network/TextFilter$FilteredText;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;broadcastMessage(Lnet/minecraft/network/chat/Component;Ljava/util/function/Function;Lnet/minecraft/network/chat/ChatType;Ljava/util/UUID;)V"), cancellable = true)
//$$ private void handleChat(TextFilter.FilteredText filteredText, CallbackInfo ci) {
//$$ Optional<Component> result = MinecraftEvents.PLAYER_MESSAGE.invoker().message(player, filteredText.getFiltered());
//$$ if (result.isPresent()) {
Expand Down Expand Up @@ -88,18 +96,23 @@ private void broadcastChatMessage(PlayerChatMessage playerChatMessage, CallbackI
//$$ }
//#endif

//#if MC > 11900
@Inject(method = "performChatCommand", at = @At("HEAD"))
//#if MC >= 11903
@Inject(method = "performChatCommand(Lnet/minecraft/network/protocol/game/ServerboundChatCommandPacket;Lnet/minecraft/network/chat/LastSeenMessages;)V", at = @At("HEAD"))
private void performChatCommand(ServerboundChatCommandPacket serverboundChatCommandPacket, LastSeenMessages lastSeenMessages, CallbackInfo ci) {
MinecraftEvents.PLAYER_COMMAND.invoker().command(player, "/" + serverboundChatCommandPacket.command());
}
//#elseif MC > 11802
//$$ @Inject(method = "handleChatCommand", at = @At(value = "INVOKE", target = "Lnet/minecraft/commands/Commands;performCommand(Lnet/minecraft/commands/CommandSourceStack;Ljava/lang/String;)V"))
//#elseif MC > 11900
//$$ @Inject(method = "performChatCommand(Lnet/minecraft/network/protocol/game/ServerboundChatCommandPacket;)V", at = @At("HEAD"))
//$$ private void performChatCommand(ServerboundChatCommandPacket serverboundChatCommandPacket, CallbackInfo ci) {
//$$ MinecraftEvents.PLAYER_COMMAND.invoker().command(player, "/" + serverboundChatCommandPacket.command());
//$$ }
//#elseif MC == 11900
//$$ @Inject(method = "handleChatCommand(Lnet/minecraft/network/protocol/game/ServerboundChatCommandPacket;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/commands/Commands;performCommand(Lnet/minecraft/commands/CommandSourceStack;Ljava/lang/String;)I"))
//$$ private void handleChatCommand(ServerboundChatCommandPacket serverboundChatCommandPacket, CallbackInfo ci) {
//$$ MinecraftEvents.PLAYER_COMMAND.invoker().command(player, "/" + serverboundChatCommandPacket.command());
//$$ }
//#else
//$$ @Inject(method = "handleCommand", at = @At("HEAD"))
//$$ @Inject(method = "handleCommand(Ljava/lang/String;)V", at = @At("HEAD"))
//$$ private void handleCommand(String string, CallbackInfo ci) {
//$$ MinecraftEvents.PLAYER_COMMAND.invoker().command(player, string);
//$$ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@Mixin(ServerPlayer.class)
public class MixinServerPlayer {

@Inject(method = "die", at = @At("HEAD"))
@Inject(method = "die(Lnet/minecraft/world/damagesource/DamageSource;)V", at = @At("HEAD"))
private void die(DamageSource damageSource, CallbackInfo ci) {
MinecraftEvents.PLAYER_DIE.invoker().die((ServerPlayer) (Object) this, damageSource);
}
Expand Down

0 comments on commit 3fd5fb3

Please sign in to comment.