Skip to content

Commit

Permalink
24w40a
Browse files Browse the repository at this point in the history
  • Loading branch information
zml2008 committed Oct 6, 2024
1 parent 0bc4976 commit 7014ad0
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@
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 {
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<Integer> cir) {
final Component nativeText = MinecraftClientAudiences.of().asNative(
net.kyori.adventure.text.Component.translatable("menu.singleplayer", TextColor.color(0x9A40D2))
);
Expand Down
8 changes: 4 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
*
* <p>Depending on the specific source, the returned audience may only support
* a subset of abilities.</p>
*
* @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}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,19 +148,28 @@ private Iterable<Audience> audiences(final Iterable<? extends ServerPlayer> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected ServerPlayerMixin(final EntityType<? extends LivingEntity> 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
Expand Down

0 comments on commit 7014ad0

Please sign in to comment.