Skip to content

Commit

Permalink
Move API mixins to -fabric exclusive, bring back service loader worka…
Browse files Browse the repository at this point in the history
…round

Fixes non-game layer libs being unable to access adventure classes on NeoForge
  • Loading branch information
jpenilla committed Jul 29, 2024
1 parent 88fb813 commit 0d0deb1
Show file tree
Hide file tree
Showing 15 changed files with 314 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.kyori.adventure.platform.modcommon.impl.mixin.api;
package net.kyori.adventure.platform.fabric.impl.mixin.api;

import net.kyori.adventure.key.InvalidKeyException;
import net.kyori.adventure.key.Key;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.kyori.adventure.platform.modcommon.impl.mixin.api;
package net.kyori.adventure.platform.fabric.impl.mixin.api;

import net.kyori.adventure.chat.SignedMessage;
import net.minecraft.network.chat.MessageSignature;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"package": "net.kyori.adventure.platform.fabric.impl.mixin",
"parent": "adventure-platform-mod-shared.parent.mixins.json",
"mixins": [
"api.KeyMixin",
"api.SignedMessageMixin",
"minecraft.commands.CommandsMixin",
"minecraft.commands.synchronization.ArgumentTypeInfosMixin",
"minecraft.commands.synchronization.ArgumentUtilsMixin",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,21 +123,21 @@ static Key asAdventure(final ResourceLocation loc) {
/**
* Convert a Kyori {@link Key} instance to a MC ResourceLocation.
*
* <p>All {@link Key} instances created in an environment with this
* mod are implemented by {@link ResourceLocation},
* so this is effectively a cast.</p>
*
* @param key The Key to convert
* @return The equivalent data as an Identifier
* @return The equivalent data as a resource location
* @since 6.0.0
*/
@SuppressWarnings("ConstantValue")
@Contract("null -> null; !null -> !null")
static ResourceLocation toNative(final Key key) {
if (key == null) {
return null;
}

return (ResourceLocation) (Object) key;
if ((Object) key instanceof ResourceLocation loc) {
return loc;
}
return ResourceLocation.fromNamespaceAndPath(key.namespace(), key.value());
}

/**
Expand Down Expand Up @@ -254,6 +254,21 @@ static ResourceLocation toNative(final Key key) {
return (SignedMessage.Signature) (Object) signature;
}

/**
* Returns a native view of the provided {@link SignedMessage.Signature}.
*
* @param signature message signature
* @return native message signature
* @since 6.0.0
*/
@SuppressWarnings("ConstantValue")
static @NotNull MessageSignature toNative(final SignedMessage.@NotNull Signature signature) {
if ((Object) signature instanceof MessageSignature nativeSig) {
return nativeSig;
}
return new MessageSignature(signature.bytes());
}

/**
* Returns an adventure {@link SignedMessage} view of the provided {@link PlayerChatMessage}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
"package": "net.kyori.adventure.platform.modcommon.impl.mixin",
"parent": "adventure-platform-mod-shared.parent.mixins.json",
"mixins": [
"api.KeyMixin",
"api.SignedMessageMixin",
"authlib.GameProfileMixin",
"brigadier.exceptions.CommandSyntaxExceptionMixin",
"minecraft.commands.CommandSourceStackMixin",
Expand Down
26 changes: 3 additions & 23 deletions neoforge/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -49,34 +49,14 @@ tasks.withType<RunGameTask>().configureEach {
}
}

tasks {
// Force adventure libs to be GAMELIBRARY - fixes issues with service loaders and mixins to API
val injectMeta = register("injectGameLibraryMeta") {
dependsOn(jarJar)
doFirst {
val dir = jarJar.get().outputDirectory.get().asFile.toPath()
for (nestedJar in dir.resolve("META-INF/jarjar").listDirectoryEntries("*.jar")) {
FileSystems.newFileSystem(URI.create("jar:" + nestedJar.toUri()), emptyMap<String, Any>()).use { fs ->
val manifestPath = fs.rootDirectories.single().resolve("META-INF/MANIFEST.MF")
val manifest = manifestPath.inputStream().use { Manifest(it) }
if (manifest.mainAttributes.getValue("FMLModType") == null) {
manifest.mainAttributes.putValue("FMLModType", "GAMELIBRARY")
}
manifestPath.outputStream().use { manifest.write(it) }
}
}
}
}
jar {
dependsOn(injectMeta)
}
}

configurations.jarJar {
extendsFrom(configurations.jarInJar.get())
}

dependencies {
implementation(project(":adventure-platform-neoforge:adventure-platform-neoforge-services"))
jarJar(project(":adventure-platform-neoforge:adventure-platform-neoforge-services"))

compileOnlyApi(project(":adventure-platform-mod-shared"))
jarJar(project(":adventure-platform-mod-shared"))
}
Expand Down
3 changes: 3 additions & 0 deletions neoforge/services/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins {
id 'publishing-conventions'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* This file is part of adventure-platform-mod, licensed under the MIT License.
*
* Copyright (c) 2020-2024 KyoriPowered
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.kyori.adventure.platform.neoforge.impl.services;

import com.google.auto.service.AutoService;
import java.util.function.Consumer;
import net.kyori.adventure.text.serializer.ansi.ANSIComponentSerializer;
import org.jetbrains.annotations.NotNull;

@AutoService(ANSIComponentSerializer.Provider.class)
public final class ANSIComponentSerializerProviderImpl implements ANSIComponentSerializer.Provider {
public static ANSIComponentSerializer.Provider DELEGATE;

@Override
public @NotNull ANSIComponentSerializer ansi() {
return DELEGATE.ansi();
}

@Override
public @NotNull Consumer<ANSIComponentSerializer.Builder> builder() {
return DELEGATE.builder();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* This file is part of adventure-platform-mod, licensed under the MIT License.
*
* Copyright (c) 2023-2024 KyoriPowered
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.kyori.adventure.platform.neoforge.impl.services;

import com.google.auto.service.AutoService;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.event.ClickCallback;
import net.kyori.adventure.text.event.ClickEvent;
import org.jetbrains.annotations.NotNull;

@AutoService(ClickCallback.Provider.class)
public final class ClickCallbackProviderImpl implements ClickCallback.Provider {
public static ClickCallback.Provider DELEGATE;

@Override
public @NotNull ClickEvent create(final @NotNull ClickCallback<Audience> callback, final ClickCallback.@NotNull Options options) {
return DELEGATE.create(callback, options);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* This file is part of adventure-platform-mod, licensed under the MIT License.
*
* Copyright (c) 2020-2024 KyoriPowered
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.kyori.adventure.platform.neoforge.impl.services;

import com.google.auto.service.AutoService;
import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
import net.kyori.adventure.text.logger.slf4j.ComponentLoggerProvider;
import org.jetbrains.annotations.NotNull;

@AutoService(net.kyori.adventure.text.logger.slf4j.ComponentLoggerProvider.class)
public final class ComponentLoggerProviderImpl implements net.kyori.adventure.text.logger.slf4j.ComponentLoggerProvider {
public static ComponentLoggerProvider DELEGATE;

@Override
public @NotNull ComponentLogger logger(final @NotNull LoggerHelper helper, final @NotNull String name) {
return DELEGATE.logger(helper, name);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* This file is part of adventure-platform-mod, licensed under the MIT License.
*
* Copyright (c) 2024 KyoriPowered
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.kyori.adventure.platform.neoforge.impl.services;

import com.google.auto.service.AutoService;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.event.DataComponentValueConverterRegistry;
import org.jetbrains.annotations.NotNull;

@AutoService(DataComponentValueConverterRegistry.Provider.class)
public final class DataComponentValueConverterProvider implements DataComponentValueConverterRegistry.Provider {
public static DataComponentValueConverterRegistry.Provider DELEGATE;

@Override
public @NotNull Key id() {
return DELEGATE.id();
}

@Override
public @NotNull Iterable<DataComponentValueConverterRegistry.Conversion<?, ?>> conversions() {
return DELEGATE.conversions();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* This file is part of adventure-platform-mod, licensed under the MIT License.
*
* Copyright (c) 2020-2024 KyoriPowered
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.kyori.adventure.platform.neoforge.impl.services;

import com.google.auto.service.AutoService;
import java.util.function.Consumer;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import org.jetbrains.annotations.NotNull;

@AutoService(GsonComponentSerializer.Provider.class)
public final class GsonComponentSerializerProviderImpl implements GsonComponentSerializer.Provider {
public static GsonComponentSerializer.Provider DELEGATE;

@Override
public @NotNull GsonComponentSerializer gson() {
return DELEGATE.gson();
}

@Override
public @NotNull GsonComponentSerializer gsonLegacy() {
return DELEGATE.gsonLegacy();
}

@Override
public @NotNull Consumer<GsonComponentSerializer.Builder> builder() {
return DELEGATE.builder();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* This file is part of adventure-platform-mod, licensed under the MIT License.
*
* Copyright (c) 2020-2024 KyoriPowered
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.kyori.adventure.platform.neoforge.impl.services;

import com.google.auto.service.AutoService;
import java.util.function.Consumer;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.jetbrains.annotations.NotNull;

@AutoService(PlainTextComponentSerializer.Provider.class)
public final class PlainTextComponentSerializerProviderImpl implements PlainTextComponentSerializer.Provider {
public static PlainTextComponentSerializer.Provider DELEGATE;

@Override
public @NotNull PlainTextComponentSerializer plainTextSimple() {
return DELEGATE.plainTextSimple();
}

@Override
public @NotNull Consumer<PlainTextComponentSerializer.Builder> plainText() {
return DELEGATE.plainText();
}
}
Loading

0 comments on commit 0d0deb1

Please sign in to comment.