From 7014ad0f6913d8f2421b0c38503256033a8dbd80 Mon Sep 17 00:00:00 2001 From: zml Date: Sat, 5 Oct 2024 23:16:52 -0700 Subject: [PATCH] 24w40a --- .../client/gui/screens/TitleScreenMixin.java | 6 ++--- gradle/libs.versions.toml | 8 +++--- .../modcommon/MinecraftServerAudiences.java | 12 +++++++++ .../server/MinecraftServerAudiencesImpl.java | 27 ++++++++++++------- .../commands/CommandSourceStackMixin.java | 5 +++- .../server/level/ServerPlayerMixin.java | 2 +- 6 files changed, 42 insertions(+), 18 deletions(-) diff --git a/fabric/src/testmodMixin/java/net/kyori/adventure/platform/test/fabric/mixin/minecraft/client/gui/screens/TitleScreenMixin.java b/fabric/src/testmodMixin/java/net/kyori/adventure/platform/test/fabric/mixin/minecraft/client/gui/screens/TitleScreenMixin.java index 51fcd564..65f35d52 100644 --- a/fabric/src/testmodMixin/java/net/kyori/adventure/platform/test/fabric/mixin/minecraft/client/gui/screens/TitleScreenMixin.java +++ b/fabric/src/testmodMixin/java/net/kyori/adventure/platform/test/fabric/mixin/minecraft/client/gui/screens/TitleScreenMixin.java @@ -33,7 +33,7 @@ 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.CallbackInfoReturnable; @Mixin(TitleScreen.class) abstract class TitleScreenMixin extends Screen { @@ -41,8 +41,8 @@ protected TitleScreenMixin(final Component title) { super(title); } - @Inject(method = "createNormalMenuOptions(II)V", at = @At("HEAD")) - void addMenuOptions(final int y, final int rowHeight, final CallbackInfo ci) { + @Inject(method = "createNormalMenuOptions(II)I", at = @At("HEAD")) + void addMenuOptions(final int y, final int rowHeight, final CallbackInfoReturnable cir) { final Component nativeText = MinecraftClientAudiences.of().asNative( net.kyori.adventure.text.Component.translatable("menu.singleplayer", TextColor.color(0x9A40D2)) ); diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 49e4ce26..6facec24 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -8,16 +8,16 @@ ansi = "1.1.0" autoService = "1.1.1" checkstyle = "10.18.2" examination = "1.3.0" -fabricApi = "0.103.2+1.21.2" -fabricLoader = "0.16.4" +fabricApi = "0.105.2+1.21.2" +fabricLoader = "0.16.5" indra = "3.1.3" junit = "5.11.2" -minecraft = "24w36a" +minecraft = "24w40a" parchment = "1.21:2024.07.28" vineflower = "1.10.1" spotless = "6.25.0" neoforge = "21.0.167" -neoform = "24w36a-20240904.161315" +neoform = "24w40a-20241003.090628" [libraries] adventure-api = { module = "net.kyori:adventure-api", version.ref = "adventure" } diff --git a/mod-shared/src/main/java/net/kyori/adventure/platform/modcommon/MinecraftServerAudiences.java b/mod-shared/src/main/java/net/kyori/adventure/platform/modcommon/MinecraftServerAudiences.java index 896e9ba5..f82db8dc 100644 --- a/mod-shared/src/main/java/net/kyori/adventure/platform/modcommon/MinecraftServerAudiences.java +++ b/mod-shared/src/main/java/net/kyori/adventure/platform/modcommon/MinecraftServerAudiences.java @@ -77,6 +77,18 @@ public interface MinecraftServerAudiences extends AudienceProvider, MinecraftAud */ @NotNull AdventureCommandSourceStack audience(@NotNull CommandSourceStack source); + /** + * Get an audience that will send to the provided {@link ServerPlayer}. + * + *

Depending on the specific source, the returned audience may only support + * a subset of abilities.

+ * + * @param source source to send to + * @return an audience for the source + * @since 6.1.0 + */ + @NotNull Audience audience(@NotNull ServerPlayer source); + /** * Get an audience that will send to the provided {@link CommandSource}. * diff --git a/mod-shared/src/main/java/net/kyori/adventure/platform/modcommon/impl/server/MinecraftServerAudiencesImpl.java b/mod-shared/src/main/java/net/kyori/adventure/platform/modcommon/impl/server/MinecraftServerAudiencesImpl.java index e539d614..1e8d59ce 100644 --- a/mod-shared/src/main/java/net/kyori/adventure/platform/modcommon/impl/server/MinecraftServerAudiencesImpl.java +++ b/mod-shared/src/main/java/net/kyori/adventure/platform/modcommon/impl/server/MinecraftServerAudiencesImpl.java @@ -148,19 +148,28 @@ private Iterable audiences(final Iterable play throw new IllegalArgumentException("The AdventureCommandSource mixin failed!"); } - return internal.adventure$audience(this.audience(internal.adventure$source()), this); + final Audience backingAudience = source.getEntity() instanceof final ServerPlayer ply && ply.commandSource() == internal.adventure$source() + ? this.audience(ply) + : this.audience(internal.adventure$source()); + return internal.adventure$audience(backingAudience, this); + } + + @Override + public @NotNull Audience audience(final @NotNull ServerPlayer source) { + return switch (source) { + case final RenderableAudience render -> render.renderUsing(this); + case final Audience audience -> audience; // todo: how to pass component renderer through + default -> new ServerPlayerAudience(source, this); + }; } @Override public @NotNull Audience audience(final @NotNull CommandSource source) { - if (source instanceof final RenderableAudience renderable) { - return renderable.renderUsing(this); - } else if (source instanceof final Audience audience) { - // TODO: How to pass component renderer through - return audience; - } else { - return new CommandSourceAudience(source, this); - } + return switch (source) { + case final RenderableAudience render -> render.renderUsing(this); + case final Audience audience -> audience; // todo: how to pass component renderer through + default -> new CommandSourceAudience(source, this); + }; } @Override diff --git a/mod-shared/src/mixin/java/net/kyori/adventure/platform/modcommon/impl/mixin/minecraft/commands/CommandSourceStackMixin.java b/mod-shared/src/mixin/java/net/kyori/adventure/platform/modcommon/impl/mixin/minecraft/commands/CommandSourceStackMixin.java index 50b9c70f..ca69c025 100644 --- a/mod-shared/src/mixin/java/net/kyori/adventure/platform/modcommon/impl/mixin/minecraft/commands/CommandSourceStackMixin.java +++ b/mod-shared/src/mixin/java/net/kyori/adventure/platform/modcommon/impl/mixin/minecraft/commands/CommandSourceStackMixin.java @@ -36,6 +36,8 @@ import net.minecraft.commands.CommandSource; import net.minecraft.commands.CommandSourceStack; import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.Entity; import org.jetbrains.annotations.NotNull; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -49,6 +51,7 @@ @Mixin(CommandSourceStack.class) public abstract class CommandSourceStackMixin implements AdventureCommandSourceStackInternal { // @formatter:off + @Shadow @Final private Entity entity; @Shadow @Final private CommandSource source; @Shadow @Final private boolean silent; @Shadow @Final private MinecraftServer server; @@ -88,7 +91,7 @@ public void sendFailure(final @NotNull Component text) { throw new IllegalStateException("Cannot use adventure operations without an available server!"); } this.adventure$controller = MinecraftServerAudiences.of(this.server); - this.adventure$out = this.adventure$controller.audience(this.source); + this.adventure$out = this.entity instanceof final ServerPlayer ply && ply.commandSource() == this.source ? this.adventure$controller.audience(ply) : this.adventure$controller.audience(this.source); } return this.adventure$out; } diff --git a/mod-shared/src/mixin/java/net/kyori/adventure/platform/modcommon/impl/mixin/minecraft/server/level/ServerPlayerMixin.java b/mod-shared/src/mixin/java/net/kyori/adventure/platform/modcommon/impl/mixin/minecraft/server/level/ServerPlayerMixin.java index 7d46e418..b12bafb0 100644 --- a/mod-shared/src/mixin/java/net/kyori/adventure/platform/modcommon/impl/mixin/minecraft/server/level/ServerPlayerMixin.java +++ b/mod-shared/src/mixin/java/net/kyori/adventure/platform/modcommon/impl/mixin/minecraft/server/level/ServerPlayerMixin.java @@ -78,7 +78,7 @@ protected ServerPlayerMixin(final EntityType entityType, // This is just setting it to the default en_us, to avoid event calls if it doesn't change (this is the reason for our target not being TAIL) this.adventure$locale = LocaleHolderBridge.toLocale(this.language); - this.adventure$backing = MinecraftServerAudiences.of(this.server).audience(this); + this.adventure$backing = MinecraftServerAudiences.of(this.server).audience((ServerPlayer) (Object) this); } @Override