diff --git a/fabric/build.gradle.kts b/fabric/build.gradle.kts index 5fe74f80..1bb2f256 100644 --- a/fabric/build.gradle.kts +++ b/fabric/build.gradle.kts @@ -7,7 +7,7 @@ plugins { alias(libs.plugins.loom) alias(libs.plugins.configurateTransformations) id("standard-conventions") - // id("publishing-conventions") // disable until 1.21.2 + id("publishing-conventions") } dependencies { @@ -225,8 +225,8 @@ tasks.withType(GenerateSourcesTask::class).configureEach { // Workaround for both loom and indra doing publication logic in an afterEvaluate :( indra.includeJavaSoftwareComponentInPublications(false) -/*publishing { +publishing { publications.named("maven", MavenPublication::class) { from(components["java"]) } -}*/ +} 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.properties b/gradle.properties index 588d8588..f23f635c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ group=net.kyori -version=6.0.2-SNAPSHOT +version=6.1.0-SNAPSHOT description=Integration between the adventure library and Minecraft: Java Edition, using the Fabric and NeoForge modding systems javadocPublishRoot=https://jd.advntr.dev/platform/ diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index fc2da40f..154f9395 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.100.1+1.21" -fabricLoader = "0.15.11" +fabricApi = "0.106.1+1.21.2" +fabricLoader = "0.16.7" indra = "3.1.3" junit = "5.11.2" -minecraft = "1.21" -parchment = "1.20.6:2024.06.02" +minecraft = "1.21.2" +parchment = "1.21:2024.07.28" vineflower = "1.10.1" spotless = "6.25.0" -neoforge = "21.0.167" -neoform = "1.21-20240613.152323" +neoforge = "21.2.0-beta" +neoform = "1.21.2-20241022.151510" [libraries] adventure-api = { module = "net.kyori:adventure-api", version.ref = "adventure" } @@ -33,11 +33,11 @@ adventure-textSerializerAnsi = { module = "net.kyori:adventure-text-serializer-a ansi = { module = "net.kyori:ansi", version.ref = "ansi" } examination-api = { module = "net.kyori:examination-api", version.ref = "examination" } examination-string = { module = "net.kyori:examination-string", version.ref = "examination" } -jetbrainsAnnotations = "org.jetbrains:annotations:25.0.0" +jetbrainsAnnotations = "org.jetbrains:annotations:26.0.0" option = { module = "net.kyori:option", version = "1.0.0" } # mod-shared -mixin = "net.fabricmc:sponge-mixin:0.13.4+mixin.0.8.5" +mixin = "net.fabricmc:sponge-mixin:0.15.3+mixin.0.8.7" mixinExtras = "io.github.llamalad7:mixinextras-common:0.4.1" # For Renovate, do not use directly zNeoform = { module = "net.neoforged:neoform", version.ref = "neoform" } @@ -81,7 +81,7 @@ zCheckstyle = { module = "com.puppycrawl.tools:checkstyle", version.ref = "check [plugins] configurateTransformations = { id = "ca.stellardrift.configurate-transformations" } eclipseApt = "com.diffplug.eclipse.apt:4.1.0" -loom = "fabric-loom:1.8.6" +loom = "fabric-loom:1.8.10" # ModDevGradle settings plugin is putting another version on the classpath, so we can't specify a version :( ideaExt = { id = "org.jetbrains.gradle.plugin.idea-ext" } indra = { id = "net.kyori.indra" } diff --git a/mod-shared/build.gradle b/mod-shared/build.gradle index 280aff03..502d7df6 100644 --- a/mod-shared/build.gradle +++ b/mod-shared/build.gradle @@ -11,7 +11,29 @@ neoForge { } } +@CacheableRule +abstract class RemoveAsmConstraint implements ComponentMetadataRule { + @Override + void execute(final ComponentMetadataContext ctx) { + ctx.details.allVariants { + it.withDependencies { deps -> + deps.forEach { dep -> + if (dep.group == 'org.ow2.asm') { + if (dep.versionConstraint.strictVersion != null) { + dep.version { it.require(it.strictVersion) } + } + } + } + } + } + } +} + dependencies { + components { + // Mojang ships an old version of ASM, which conflicts with our deps. Upstream will probably solve this better when an actual release happens. + withModule('net.neoforged:minecraft-dependencies', RemoveAsmConstraint) + } compileOnly(libs.mixin) compileOnly(libs.mixinExtras) } diff --git a/mod-shared/src/main/java/net/kyori/adventure/platform/modcommon/MinecraftAudiences.java b/mod-shared/src/main/java/net/kyori/adventure/platform/modcommon/MinecraftAudiences.java index f135261f..dbdb7462 100644 --- a/mod-shared/src/main/java/net/kyori/adventure/platform/modcommon/MinecraftAudiences.java +++ b/mod-shared/src/main/java/net/kyori/adventure/platform/modcommon/MinecraftAudiences.java @@ -244,7 +244,7 @@ static Identity identity(final GameProfile profile) { */ @Contract("null -> null; !null -> !null") static Sound.Type asSoundType(final SoundEvent soundEvent) { - return (Sound.Type) soundEvent; + return (Sound.Type) (Object) soundEvent; } /** 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/AdventureCommon.java b/mod-shared/src/main/java/net/kyori/adventure/platform/modcommon/impl/AdventureCommon.java index 9d045dea..0b4e6ea9 100644 --- a/mod-shared/src/main/java/net/kyori/adventure/platform/modcommon/impl/AdventureCommon.java +++ b/mod-shared/src/main/java/net/kyori/adventure/platform/modcommon/impl/AdventureCommon.java @@ -179,8 +179,8 @@ public static void scheduleClickCallbackCleanup() { final MinecraftAudiencesInternal rendererProvider ) { final Holder type = rendererProvider.registryAccess() - .registryOrThrow(Registries.CHAT_TYPE) - .getHolder(MinecraftAudiences.asNative(bound.type().key())) + .lookupOrThrow(Registries.CHAT_TYPE) + .get(MinecraftAudiences.asNative(bound.type().key())) .orElseThrow(() -> new IllegalArgumentException("Could not resolve chat type for key " + bound.type().key())); return new net.minecraft.network.chat.ChatType.Bound( 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/main/java/net/kyori/adventure/platform/modcommon/impl/server/ServerPlayerAudience.java b/mod-shared/src/main/java/net/kyori/adventure/platform/modcommon/impl/server/ServerPlayerAudience.java index d4a50f86..338ee51c 100644 --- a/mod-shared/src/main/java/net/kyori/adventure/platform/modcommon/impl/server/ServerPlayerAudience.java +++ b/mod-shared/src/main/java/net/kyori/adventure/platform/modcommon/impl/server/ServerPlayerAudience.java @@ -190,10 +190,10 @@ private long seed(final @NotNull Sound sound) { private Holder eventHolder(final @NotNull Sound sound) { final var soundEventRegistry = this.controller.registryAccess() - .registryOrThrow(Registries.SOUND_EVENT); + .lookupOrThrow(Registries.SOUND_EVENT); final var soundKey = MinecraftAudiences.asNative(sound.name()); - final var eventOptional = soundEventRegistry.getHolder(ResourceKey.create(Registries.SOUND_EVENT, soundKey)); + final var eventOptional = soundEventRegistry.get(ResourceKey.create(Registries.SOUND_EVENT, soundKey)); return eventOptional.isPresent() ? eventOptional.get() : Holder.direct(SoundEvent.createVariableRangeEvent(soundKey)); } diff --git a/mod-shared/src/main/java/net/kyori/adventure/platform/modcommon/impl/service/DataComponentValueConverterProvider.java b/mod-shared/src/main/java/net/kyori/adventure/platform/modcommon/impl/service/DataComponentValueConverterProvider.java index 1f1a091c..8ee6f0d9 100644 --- a/mod-shared/src/main/java/net/kyori/adventure/platform/modcommon/impl/service/DataComponentValueConverterProvider.java +++ b/mod-shared/src/main/java/net/kyori/adventure/platform/modcommon/impl/service/DataComponentValueConverterProvider.java @@ -91,7 +91,7 @@ public final class DataComponentValueConverterProvider implements DataComponentV } private static DataComponentType resolveComponentType(final Key key) { - final DataComponentType type = BuiltInRegistries.DATA_COMPONENT_TYPE.get(MinecraftAudiences.asNative(key)); + final DataComponentType type = BuiltInRegistries.DATA_COMPONENT_TYPE.getValue(MinecraftAudiences.asNative(key)); if (type == null) { throw new IllegalArgumentException("Unknown data component type " + key.asString()); } 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 diff --git a/mod-shared/src/mixin/java/net/kyori/adventure/platform/modcommon/impl/mixin/minecraft/world/entity/EntityMixin.java b/mod-shared/src/mixin/java/net/kyori/adventure/platform/modcommon/impl/mixin/minecraft/world/entity/EntityMixin.java index 64111c83..86bb9a23 100644 --- a/mod-shared/src/mixin/java/net/kyori/adventure/platform/modcommon/impl/mixin/minecraft/world/entity/EntityMixin.java +++ b/mod-shared/src/mixin/java/net/kyori/adventure/platform/modcommon/impl/mixin/minecraft/world/entity/EntityMixin.java @@ -51,7 +51,7 @@ public abstract class EntityMixin implements Sound.Emitter, EntityHoverEventSour @Override public @NotNull HoverEvent asHoverEvent(final @NotNull UnaryOperator op) { final Key entityType = (Key) (Object) this.level.registryAccess() - .registryOrThrow(Registries.ENTITY_TYPE) + .lookupOrThrow(Registries.ENTITY_TYPE) .getKey(this.shadow$getType()); final ShowEntity data = HoverEvent.ShowEntity.showEntity( diff --git a/neoforge/src/main/resources/META-INF/neoforge.mods.toml b/neoforge/src/main/resources/META-INF/neoforge.mods.toml index 6561b2d9..03d81555 100644 --- a/neoforge/src/main/resources/META-INF/neoforge.mods.toml +++ b/neoforge/src/main/resources/META-INF/neoforge.mods.toml @@ -47,13 +47,13 @@ config="adventure-platform-neoforge.mixins.json" [[dependencies.adventure_platform_neoforge]] modId="neoforge" type="required" -versionRange="[21.0.0-beta,)" +versionRange="[21.2.0-beta,)" ordering="NONE" side="BOTH" [[dependencies.adventure_platform_neoforge]] modId="minecraft" type="required" -versionRange="[1.21,1.21.1)" +versionRange="[1.21.2,1.22)" ordering="NONE" side="BOTH" diff --git a/neoforge/tester/src/main/java/net/kyori/adventure/platform/tester/neoforge/mixin/TitleScreenMixin.java b/neoforge/tester/src/main/java/net/kyori/adventure/platform/tester/neoforge/mixin/TitleScreenMixin.java index da0eb0a6..4713f564 100644 --- a/neoforge/tester/src/main/java/net/kyori/adventure/platform/tester/neoforge/mixin/TitleScreenMixin.java +++ b/neoforge/tester/src/main/java/net/kyori/adventure/platform/tester/neoforge/mixin/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/neoforge/tester/src/main/resources/META-INF/neoforge.mods.toml b/neoforge/tester/src/main/resources/META-INF/neoforge.mods.toml index 6b4fe224..e2bea948 100644 --- a/neoforge/tester/src/main/resources/META-INF/neoforge.mods.toml +++ b/neoforge/tester/src/main/resources/META-INF/neoforge.mods.toml @@ -38,14 +38,14 @@ config="adventure-platform-neoforge-tester.mixins.json" [[dependencies.adventure_platform_neoforge_tester]] modId="neoforge" type="required" -versionRange="[21.0.0-beta,)" +versionRange="[21.2.0-beta,)" ordering="NONE" side="BOTH" [[dependencies.adventure_platform_neoforge_tester]] modId="minecraft" type="required" -versionRange="[1.21,1.21.1)" +versionRange="[1.21.2,1.22)" ordering="NONE" side="BOTH" diff --git a/settings.gradle.kts b/settings.gradle.kts index 9404e6ff..d1b7e147 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -19,8 +19,8 @@ pluginManagement { plugins { id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0" - id("fabric-loom") version "1.8.6" - id("net.neoforged.moddev.repositories") version "1.0.20" + id("fabric-loom") version "1.8.10" + id("net.neoforged.moddev.repositories") version "1.0.21" } rootProject.name = "adventure-platform-mod-parent" @@ -46,19 +46,24 @@ dependencyResolutionManagement { } } -setOf("fabric", "neoforge", "mod-shared").forEach { - include(it) - findProject(":$it")?.name = "adventure-platform-$it" +fun includeAndRename(path: String, name: String? = null) { + include(path) + findProject(":$path")?.name = "adventure-platform-${name ?: path.replace(":", "-")}" } -include(":adventure-platform-fabric:mod-shared-repack") -findProject(":adventure-platform-fabric:mod-shared-repack")?.name = "adventure-platform-mod-shared-fabric-repack" - -include(":adventure-platform-neoforge:tester") -findProject(":adventure-platform-neoforge:tester")?.name = "adventure-platform-neoforge-tester" - -include(":adventure-platform-neoforge:services") -findProject(":adventure-platform-neoforge:services")?.name = "adventure-platform-neoforge-services" +// Common +includeAndRename("mod-shared") include(":test-resources") findProject(":test-resources")?.projectDir = file("mod-shared/test-resources") + +// Fabric +includeAndRename("fabric") +includeAndRename("adventure-platform-fabric:mod-shared-repack", "mod-shared-fabric-repack") + +// NeoForge + +includeAndRename("neoforge") +includeAndRename("adventure-platform-neoforge:tester", "neoforge-tester") +includeAndRename("adventure-platform-neoforge:services", "neoforge-services") +