Skip to content

Commit

Permalink
Split Forge and NeoForge extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
Juuxel committed Nov 13, 2023
1 parent 2ab5906 commit 9c92a16
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/main/java/net/fabricmc/loom/api/ForgeExtensionAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/net/fabricmc/loom/api/LoomGradleExtensionAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<ForgeExtensionAPI> 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<NeoForgeExtensionAPI> action);
}
50 changes: 50 additions & 0 deletions src/main/java/net/fabricmc/loom/api/NeoForgeExtensionAPI.java
Original file line number Diff line number Diff line change
@@ -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.
*
* <p>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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -481,6 +482,11 @@ public void forge(Action<ForgeExtensionAPI> action) {
action.execute(getForge());
}

@Override
public void neoForge(Action<NeoForgeExtensionAPI> action) {
action.execute(getNeoForge());
}

// This is here to ensure that LoomGradleExtensionApiImpl compiles without any unimplemented methods
private final class EnsureCompile extends LoomGradleExtensionApiImpl {
private EnsureCompile() {
Expand Down Expand Up @@ -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");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<ForgeExtensionAPI> forgeExtension;

private final List<AccessWidenerFile> transitiveAccessWideners = new ArrayList<>();

Expand All @@ -87,6 +87,8 @@ public class LoomGradleExtensionImpl extends LoomGradleExtensionApiImpl implemen
// +-------------------+
private DependencyProviders dependencyProviders;
private ForgeRunsProvider forgeRunsProvider;
private final Supplier<ForgeExtensionAPI> forgeExtension;
private final Supplier<NeoForgeExtensionAPI> neoForgeExtension;

public LoomGradleExtensionImpl(Project project, LoomFiles files) {
super(project, files);
Expand All @@ -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 -> {
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 9c92a16

Please sign in to comment.