diff --git a/src/main/java/net/fabricmc/loom/api/ForgeExtensionAPI.java b/src/main/java/net/fabricmc/loom/api/ForgeExtensionAPI.java index 307fb69ac..17f5b3a54 100644 --- a/src/main/java/net/fabricmc/loom/api/ForgeExtensionAPI.java +++ b/src/main/java/net/fabricmc/loom/api/ForgeExtensionAPI.java @@ -33,7 +33,7 @@ import org.jetbrains.annotations.ApiStatus; /** - * This is the forge extension api available exposed to build scripts. + * This is the Forge extension API available to build scripts. */ @ApiStatus.NonExtendable public interface ForgeExtensionAPI { diff --git a/src/main/java/net/fabricmc/loom/api/LoomGradleExtensionAPI.java b/src/main/java/net/fabricmc/loom/api/LoomGradleExtensionAPI.java index 043b33dec..bdd72f9d3 100644 --- a/src/main/java/net/fabricmc/loom/api/LoomGradleExtensionAPI.java +++ b/src/main/java/net/fabricmc/loom/api/LoomGradleExtensionAPI.java @@ -268,9 +268,20 @@ default void addTaskBeforeRun(String task) { * * @return the Forge extension * @throws UnsupportedOperationException if running on another platform - * @see #isForgeLike() + * @see #isForge() */ ForgeExtensionAPI getForge(); void forge(Action action); + + /** + * Gets the NeoForge extension used to configure NeoForge details. + * + * @return the NeoForge extension + * @throws UnsupportedOperationException if running on another platform + * @see #isNeoForge() + */ + NeoForgeExtensionAPI getNeoForge(); + + void neoForge(Action action); } diff --git a/src/main/java/net/fabricmc/loom/api/NeoForgeExtensionAPI.java b/src/main/java/net/fabricmc/loom/api/NeoForgeExtensionAPI.java new file mode 100644 index 000000000..9d5474b3d --- /dev/null +++ b/src/main/java/net/fabricmc/loom/api/NeoForgeExtensionAPI.java @@ -0,0 +1,50 @@ +/* + * This file is part of fabric-loom, licensed under the MIT License (MIT). + * + * Copyright (c) 2023 FabricMC + * + * 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.fabricmc.loom.api; + +import org.gradle.api.file.ConfigurableFileCollection; + +/** + * This is the NeoForge extension API available to build scripts. + */ +public interface NeoForgeExtensionAPI { + /** + * A collection of all project access transformers. + * The collection should only contain AT files, and not directories or other files. + * + *

If this collection is empty, Loom tries to resolve the AT from the default path + * ({@code META-INF/accesstransformer.cfg} in the {@code main} source set). + * + * @return the collection of AT files + */ + ConfigurableFileCollection getAccessTransformers(); + + /** + * Adds a {@linkplain #getAccessTransformers() project access transformer}. + * + * @param file the file, evaluated as per {@link org.gradle.api.Project#file(Object)} + */ + void accessTransformer(Object file); +} diff --git a/src/main/java/net/fabricmc/loom/configuration/CompileConfiguration.java b/src/main/java/net/fabricmc/loom/configuration/CompileConfiguration.java index 9490fc141..9837c2ca7 100644 --- a/src/main/java/net/fabricmc/loom/configuration/CompileConfiguration.java +++ b/src/main/java/net/fabricmc/loom/configuration/CompileConfiguration.java @@ -36,6 +36,7 @@ import javax.inject.Inject; import org.gradle.api.Project; +import org.gradle.api.file.FileCollection; import org.gradle.api.plugins.JavaPlugin; import org.gradle.api.plugins.JavaPluginExtension; import org.gradle.api.tasks.AbstractCopyTask; @@ -268,7 +269,15 @@ private void registerGameProcessors(ConfigContext configContext) { } if (extension.isForgeLike()) { - extension.addMinecraftJarProcessor(AccessTransformerJarProcessor.class, "loom:access-transformer", configContext.project(), extension.getForge().getAccessTransformers()); + FileCollection accessTransformers; + + if (extension.isNeoForge()) { + accessTransformers = extension.getNeoForge().getAccessTransformers(); + } else { + accessTransformers = extension.getForge().getAccessTransformers(); + } + + extension.addMinecraftJarProcessor(AccessTransformerJarProcessor.class, "loom:access-transformer", configContext.project(), accessTransformers); } } diff --git a/src/main/java/net/fabricmc/loom/extension/LoomGradleExtensionApiImpl.java b/src/main/java/net/fabricmc/loom/extension/LoomGradleExtensionApiImpl.java index 1ac418f11..43959a217 100644 --- a/src/main/java/net/fabricmc/loom/extension/LoomGradleExtensionApiImpl.java +++ b/src/main/java/net/fabricmc/loom/extension/LoomGradleExtensionApiImpl.java @@ -54,6 +54,7 @@ import net.fabricmc.loom.api.LoomGradleExtensionAPI; import net.fabricmc.loom.api.MixinExtensionAPI; import net.fabricmc.loom.api.ModSettings; +import net.fabricmc.loom.api.NeoForgeExtensionAPI; import net.fabricmc.loom.api.RemapConfigurationSettings; import net.fabricmc.loom.api.decompilers.DecompilerOptions; import net.fabricmc.loom.api.mappings.intermediate.IntermediateMappingsProvider; @@ -481,6 +482,11 @@ public void forge(Action action) { action.execute(getForge()); } + @Override + public void neoForge(Action action) { + action.execute(getNeoForge()); + } + // This is here to ensure that LoomGradleExtensionApiImpl compiles without any unimplemented methods private final class EnsureCompile extends LoomGradleExtensionApiImpl { private EnsureCompile() { @@ -522,5 +528,10 @@ protected String getMinecraftVersion() { public ForgeExtensionAPI getForge() { throw new RuntimeException("Yeah... something is really wrong"); } + + @Override + public NeoForgeExtensionAPI getNeoForge() { + throw new RuntimeException("Yeah... something is really wrong"); + } } } diff --git a/src/main/java/net/fabricmc/loom/extension/LoomGradleExtensionImpl.java b/src/main/java/net/fabricmc/loom/extension/LoomGradleExtensionImpl.java index e8b639a78..59a0d858e 100644 --- a/src/main/java/net/fabricmc/loom/extension/LoomGradleExtensionImpl.java +++ b/src/main/java/net/fabricmc/loom/extension/LoomGradleExtensionImpl.java @@ -40,6 +40,7 @@ import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.api.ForgeExtensionAPI; +import net.fabricmc.loom.api.NeoForgeExtensionAPI; import net.fabricmc.loom.api.mappings.intermediate.IntermediateMappingsProvider; import net.fabricmc.loom.api.mappings.layered.MappingsNamespace; import net.fabricmc.loom.configuration.InstallerData; @@ -66,7 +67,6 @@ public class LoomGradleExtensionImpl extends LoomGradleExtensionApiImpl implemen private final MixinExtension mixinApExtension; private final LoomFiles loomFiles; private final ConfigurableFileCollection unmappedMods; - private final Supplier forgeExtension; private final List transitiveAccessWideners = new ArrayList<>(); @@ -87,6 +87,8 @@ public class LoomGradleExtensionImpl extends LoomGradleExtensionApiImpl implemen // +-------------------+ private DependencyProviders dependencyProviders; private ForgeRunsProvider forgeRunsProvider; + private final Supplier forgeExtension; + private final Supplier neoForgeExtension; public LoomGradleExtensionImpl(Project project, LoomFiles files) { super(project, files); @@ -95,7 +97,8 @@ public LoomGradleExtensionImpl(Project project, LoomFiles files) { this.mixinApExtension = project.getObjects().newInstance(MixinExtensionImpl.class, project); this.loomFiles = files; this.unmappedMods = project.files(); - this.forgeExtension = Suppliers.memoize(() -> isForgeLike() ? project.getObjects().newInstance(ForgeExtensionImpl.class, project, this) : null); + this.forgeExtension = Suppliers.memoize(() -> isForge() ? project.getObjects().newInstance(ForgeExtensionImpl.class, project, this) : null); + this.neoForgeExtension = Suppliers.memoize(() -> isNeoForge() ? project.getObjects().newInstance(NeoForgeExtensionImpl.class, project, this) : null); // Setup the default intermediate mappings provider. setIntermediateMappingsProvider(IntermediaryMappingsProvider.class, provider -> { @@ -301,10 +304,16 @@ protected String getMinecraftVersion() { @Override public ForgeExtensionAPI getForge() { - ModPlatform.assertForgeLike(this); + ModPlatform.assertPlatform(this, ModPlatform.FORGE); return forgeExtension.get(); } + @Override + public NeoForgeExtensionAPI getNeoForge() { + ModPlatform.assertPlatform(this, ModPlatform.NEOFORGE); + return neoForgeExtension.get(); + } + @Override public DependencyProviders getDependencyProviders() { return dependencyProviders; diff --git a/src/main/java/net/fabricmc/loom/extension/NeoForgeExtensionImpl.java b/src/main/java/net/fabricmc/loom/extension/NeoForgeExtensionImpl.java new file mode 100644 index 000000000..7795978c9 --- /dev/null +++ b/src/main/java/net/fabricmc/loom/extension/NeoForgeExtensionImpl.java @@ -0,0 +1,51 @@ +/* + * This file is part of fabric-loom, licensed under the MIT License (MIT). + * + * Copyright (c) 2023 FabricMC + * + * 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.fabricmc.loom.extension; + +import javax.inject.Inject; + +import org.gradle.api.Project; +import org.gradle.api.file.ConfigurableFileCollection; + +import net.fabricmc.loom.api.NeoForgeExtensionAPI; + +public class NeoForgeExtensionImpl implements NeoForgeExtensionAPI { + private final ConfigurableFileCollection accessTransformers; + + @Inject + public NeoForgeExtensionImpl(Project project) { + accessTransformers = project.getObjects().fileCollection(); + } + + @Override + public ConfigurableFileCollection getAccessTransformers() { + return accessTransformers; + } + + @Override + public void accessTransformer(Object file) { + accessTransformers.from(file); + } +} diff --git a/src/main/java/net/fabricmc/loom/task/RemapTaskConfiguration.java b/src/main/java/net/fabricmc/loom/task/RemapTaskConfiguration.java index e942876a3..66b86d967 100644 --- a/src/main/java/net/fabricmc/loom/task/RemapTaskConfiguration.java +++ b/src/main/java/net/fabricmc/loom/task/RemapTaskConfiguration.java @@ -104,7 +104,7 @@ public void run() { trySetupSourceRemapping(); getProject().afterEvaluate(p -> { - if (extension.isForgeLike()) { + if (extension.isForge()) { if (PropertyUtil.getAndFinalize(extension.getForge().getConvertAccessWideners())) { Aw2At.setup(getProject(), remapJarTask); } diff --git a/src/main/java/net/fabricmc/loom/task/launch/GenerateLog4jConfigTask.java b/src/main/java/net/fabricmc/loom/task/launch/GenerateLog4jConfigTask.java index 127a6064c..6163eadeb 100644 --- a/src/main/java/net/fabricmc/loom/task/launch/GenerateLog4jConfigTask.java +++ b/src/main/java/net/fabricmc/loom/task/launch/GenerateLog4jConfigTask.java @@ -39,7 +39,7 @@ public abstract class GenerateLog4jConfigTask extends AbstractLoomTask { public void run() { Path outputFile = getExtension().getFiles().getDefaultLog4jConfigFile().toPath(); - if (getExtension().isForgeLike() && getExtension().getForge().getUseForgeLoggerConfig().get()) { + if (getExtension().isForge() && getExtension().getForge().getUseForgeLoggerConfig().get()) { ForgeLoggerConfig.copyToPath(getProject(), outputFile); return; }