Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/api-13' into api-14
Browse files Browse the repository at this point in the history
  • Loading branch information
aromaa committed Jan 14, 2025
2 parents e55b332 + 68d8ce7 commit 993a94d
Show file tree
Hide file tree
Showing 70 changed files with 930 additions and 486 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/common-run-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ jobs:
uses: "actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3" # v4.3.1
with:
name: SpongeVanilla installer libraries
path: "${{ github.workspace }}/vanilla/build/resources/installer/libraries.json"
path: "${{ github.workspace }}/vanilla/build/resources/installer/sponge-libraries.json"
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import java.nio.file.Files;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -111,10 +112,10 @@ public final void dependencies(final String key, final NamedDomainObjectProvider

@Input
@Optional
protected abstract SetProperty<ModuleComponentIdentifier> getExcludedDependenciesBuildInput();
protected abstract SetProperty<ModuleComponentIdentifier> getExcludedDependencyIdentifiers();

public final void excludedDependencies(final NamedDomainObjectProvider<Configuration> config) {
this.getExcludedDependencies().set(config.flatMap(conf -> conf.getIncoming().getArtifacts().getResolvedArtifacts()));
public final void excludeDependencies(final NamedDomainObjectProvider<Configuration> config) {
this.getExcludedDependencies().addAll(config.flatMap(conf -> conf.getIncoming().getArtifacts().getResolvedArtifacts()));
}

/**
Expand All @@ -128,25 +129,21 @@ public final void excludedDependencies(final NamedDomainObjectProvider<Configura

public OutputDependenciesToJson() {
this.getAllowedClassifiers().add("");
this.getExcludedDependenciesBuildInput().set(this.getExcludedDependencies().map(deps -> {
return deps.stream()
.map(res -> res.getId().getComponentIdentifier())
.filter(res -> res instanceof ModuleComponentIdentifier)
.map(res -> (ModuleComponentIdentifier) res)
.collect(Collectors.toSet());
this.getExcludedDependencyIdentifiers().set(this.getExcludedDependencies().map(artifacts -> {
final Set<ModuleComponentIdentifier> ids = new HashSet<>();
for (final ResolvedArtifactResult artifact : artifacts) {
final ComponentIdentifier id = artifact.getId().getComponentIdentifier();
if (id instanceof ModuleComponentIdentifier) {
ids.add((ModuleComponentIdentifier) id);
}
}
return ids;
}));
}

@TaskAction
public void generateDependenciesJson() {
final Set<ModuleComponentIdentifier> excludedDeps = new HashSet<>();
if (this.getExcludedDependencies().isPresent()) {
for (final ResolvedArtifactResult result : this.getExcludedDependencies().get()) {
if (result.getId().getComponentIdentifier() instanceof ModuleComponentIdentifier) {
excludedDeps.add((ModuleComponentIdentifier) result.getId().getComponentIdentifier());
}
}
}
final Set<ModuleComponentIdentifier> excludedDeps = this.getExcludedDependencyIdentifiers().getOrElse(Collections.emptySet());

final Map<String, ConfigurationHolder> inputConfigs = this.getDependencies().get();
final Map<String, List<DependencyDescriptor>> dependenciesMap = new TreeMap<>();
Expand Down Expand Up @@ -213,25 +210,29 @@ public static String toHexString(final byte[] bytes) {
}

public static class ConfigurationHolder {
private final Provider<Set<ResolvedArtifactResult>> configuration;
private final Provider<Set<ResolvedArtifactResult>> artifacts;

public ConfigurationHolder(final Configuration configuration) {
this.configuration = configuration.getIncoming().getArtifacts().getResolvedArtifacts();
this.artifacts = configuration.getIncoming().getArtifacts().getResolvedArtifacts();
}

@Input
public Provider<Set<String>> getIds() {
return this.getArtifacts().map(set -> set.stream()
.map(art -> art.getId().getComponentIdentifier())
.filter(id -> id instanceof ModuleComponentIdentifier)
.map(ComponentIdentifier::getDisplayName)
.collect(Collectors.toSet()));
return this.artifacts.map(set -> {
final Set<String> ids = new HashSet<>();
for (final ResolvedArtifactResult artifact : set) {
final ComponentIdentifier id = artifact.getId().getComponentIdentifier();
if (id instanceof ModuleComponentIdentifier) {
ids.add(id.getDisplayName());
}
}
return ids;
});
}

@Internal
public Provider<Set<ResolvedArtifactResult>> getArtifacts() {
return this.configuration;
return this.artifacts;
}
}

}
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ dependencies {
exclude(group = "org.apache.commons", module = "commons-lang3")
}
launchConfig(libs.mixin)
launchConfig(libs.mixinextras.common)
launchConfig(apiLibs.checkerQual)
launchConfig(libs.guava) {
exclude(group = "com.google.code.findbugs", module = "jsr305") // We don't want to use jsr305, use checkerframework
Expand Down
14 changes: 12 additions & 2 deletions forge/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ val gameManagedLibrariesConfig: NamedDomainObjectProvider<Configuration> = confi
val serviceShadedLibrariesConfig: NamedDomainObjectProvider<Configuration> = configurations.register("serviceShadedLibraries")
val gameShadedLibrariesConfig: NamedDomainObjectProvider<Configuration> = configurations.register("gameShadedLibraries")

val productionExcludedLibrariesConfig: NamedDomainObjectProvider<Configuration> = configurations.register("productionExcludedLibraries")

// ModLauncher layers
val bootLayerConfig: NamedDomainObjectProvider<Configuration> = configurations.register("bootLayer") {
extendsFrom(bootLibrariesConfig.get())
Expand Down Expand Up @@ -189,6 +191,7 @@ dependencies {
game(libs.javaxInject)
game(platform(apiLibs.adventure.bom))
game(libs.adventure.serializerConfigurate4)
game(libs.mixinextras.common)

val serviceShadedLibraries = serviceShadedLibrariesConfig.name
serviceShadedLibraries(project(transformersProject.path)) { isTransitive = false }
Expand All @@ -197,6 +200,12 @@ dependencies {
val gameShadedLibraries = gameShadedLibrariesConfig.name
gameShadedLibraries("org.spongepowered:spongeapi:$apiVersion") { isTransitive = false }

val gameManaged = gameManagedLibrariesConfig.name
gameManaged(libs.mixinextras.forge) // prod only

val productionExcluded = productionExcludedLibrariesConfig.name
productionExcluded(libs.mixinextras.common) // dev only

afterEvaluate {
spongeImpl.copyModulesExcludingProvided(serviceLibrariesConfig.get(), bootLayerConfig.get(), serviceShadedLibrariesConfig.get())
spongeImpl.copyModulesExcludingProvided(gameLibrariesConfig.get(), serviceLayerConfig.get(), gameManagedLibrariesConfig.get())
Expand Down Expand Up @@ -307,9 +316,10 @@ tasks {
val emitDependencies by registering(org.spongepowered.gradle.impl.OutputDependenciesToJson::class) {
group = "sponge"
this.dependencies("main", gameManagedLibrariesConfig)
this.excludedDependencies(gameShadedLibrariesConfig)
this.excludeDependencies(gameShadedLibrariesConfig)
this.excludeDependencies(productionExcludedLibrariesConfig)

outputFile.set(installerResources.map { it.file("org/spongepowered/forge/applaunch/loading/moddiscovery/libraries.json") })
outputFile.set(installerResources.map { it.file("sponge-libraries.json") })
}
named(forgeAppLaunch.processResourcesTaskName).configure {
dependsOn(emitDependencies)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ public void initArguments(final Map<String, ?> arguments) {
new Log4JLogger(LogManager.getLogger(LibraryManager.class)),
env.getProperty(SpongeForgeTransformationService.Keys.CHECK_LIBRARY_HASHES.get()).orElse(true),
env.getProperty(SpongeForgeTransformationService.Keys.LIBRARIES_DIRECTORY.get())
.orElseThrow(() -> new IllegalStateException("no libraries available")),
SpongeForgeModLocator.class.getResource("libraries.json")
.orElseThrow(() -> new IllegalStateException("No libraries directory available")),
SpongeForgeModLocator.class.getResource("/sponge-libraries.json")
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,14 @@
*/
package org.spongepowered.forge.hook;

import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraftforge.event.ForgeEventFactory;
import org.spongepowered.common.hooks.EventHooks;

public final class ForgeEventHooks implements EventHooks {

@Override
public boolean callPlayerDestruction(ServerPlayer serverPlayer, DamageSource cause) {
return ForgeEventFactory.onLivingDeath(serverPlayer, cause);
}
}
3 changes: 3 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ asm = "9.7"
log4j = "2.24.1"
forgeAutoRenamingTool = "1.0.6"
mixin = "0.8.7"
mixinextras = "0.4.1"
bootstrap = "2.1.3"
modlauncher = "10.2.2"
neo-modlauncher = "11.0.3"
Expand Down Expand Up @@ -54,6 +55,8 @@ configurate-jackson = { module = "org.spongepowered:configurate-jackson" } # ver
guava = { module = "com.google.guava:guava", version.ref = "guava" }
javaxInject = { module = "javax.inject:javax.inject", version = "1" }
mixin = { module = "org.spongepowered:mixin", version.ref = "mixin" }
mixinextras-common = { module = "io.github.llamalad7:mixinextras-common", version.ref = "mixinextras" }
mixinextras-forge = { module = "io.github.llamalad7:mixinextras-forge", version.ref = "mixinextras" }
mockito-core = { module = "org.mockito:mockito-core", version.ref = "mockito" }
mockito-junitJupiter = { module = "org.mockito:mockito-junit-jupiter", version.ref = "mockito" }

Expand Down
16 changes: 16 additions & 0 deletions gradle/verification-metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2139,6 +2139,22 @@
<sha256 value="f86cf4333704813b6c48aec578f548b1f2afa5059de864e7965120ddabec9042" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="io.github.llamalad7" name="mixinextras-common" version="0.4.1">
<artifact name="mixinextras-common-0.4.1.jar">
<sha256 value="6a2c6f39f285348635ba1e0e914d066fe718c207e220a49012e8b347cb27fbda" origin="Generated by Gradle"/>
</artifact>
<artifact name="mixinextras-common-0.4.1.pom">
<sha256 value="bc224bc9bb3c376b76a673e146f548dfb5152b15f2cf0a1f1df697cf1a3acc9e" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="io.github.llamalad7" name="mixinextras-forge" version="0.4.1">
<artifact name="mixinextras-forge-0.4.1.jar">
<sha256 value="9d48cb0a40299d283248fdad8b02c6d175c45b27f9bec48ef63d7ee8a4ee3066" origin="Generated by Gradle"/>
</artifact>
<artifact name="mixinextras-forge-0.4.1.pom">
<sha256 value="8c3bc9fd591bc79e46cbc93e917cb718af952d1539f44cc9599c6299f2c778d5" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="io.github.llamalad7" name="mixinextras-neoforge" version="0.4.1">
<artifact name="mixinextras-neoforge-0.4.1.jar">
<sha256 value="9f9b6b2b1a2f376a1d62489fc8d928338d5798d69d329d2b3af7f84e420e90e9" origin="Generated by Gradle"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
Expand All @@ -53,8 +54,14 @@
import java.util.concurrent.TimeUnit;

public final class LibraryManager {
public static final String SPONGE_NEXUS_DOWNLOAD_URL = "https://repo.spongepowered.org/service/rest/v1/search/assets?sha512=%s"
+ "&maven.groupId=%s&maven.artifactId=%s&maven.baseVersion=%s&maven.extension=jar";
public static final String SPONGE_NEXUS_DOWNLOAD_URL = "https://repo.spongepowered.org/service/rest/v1/search/assets?sha512=%s&maven.groupId=%s&maven.artifactId=%s&maven.baseVersion=%s&maven.extension=jar";

// This is the list of repositories we sort artifacts by when retrieving them via the library manager.
// The order of which is semi-important as we want to prefer the most authoritative repository for a given
// artifact.
private static final List<String> PREFERRED_REPOSITORY_ORDER = List.of(
"maven-central", "minecraft-proxy", "maven-releases", "maven-snapshots", "google-proxy",
"forge-proxy", "neoforge-releases", "neoforge-snapshots", "fabric-proxy");

private final Logger logger;
private final boolean checkLibraryHashes;
Expand Down Expand Up @@ -166,8 +173,16 @@ private Set<Library> scheduleDownloads(
failures.add("No data received from '" + requestUrl + "'!");
return null;
}

final SonatypeResponse.Item item = response.items().get(0);
// Sort the items based on the preferred repository order
final var item = response.items()
.stream()
.min(Comparator.comparingInt(i -> {
if (!PREFERRED_REPOSITORY_ORDER.contains(i.repository())) {
return Integer.MAX_VALUE;
}
return PREFERRED_REPOSITORY_ORDER.indexOf(i.repository());
}))
.get();

if (checkHashes) {
LibraryUtils.downloadAndVerifyDigest(this.logger, item.downloadUrl(), depFile, "SHA-512", item.checksum().sha512());
Expand Down
4 changes: 2 additions & 2 deletions neoforge/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,9 @@ tasks {
val emitDependencies by registering(org.spongepowered.gradle.impl.OutputDependenciesToJson::class) {
group = "sponge"
this.dependencies("main", gameManagedLibrariesConfig)
this.excludedDependencies(gameShadedLibrariesConfig)
this.excludeDependencies(gameShadedLibrariesConfig)

outputFile.set(installerResources.map { it.file("org/spongepowered/neoforge/applaunch/loading/moddiscovery/libraries.json") })
outputFile.set(installerResources.map { it.file("sponge-libraries.json") })
}
named(forgeAppLaunch.processResourcesTaskName).configure {
dependsOn(emitDependencies)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public void scanMods(final List<IModFile> loadedMods, final IDiscoveryPipeline p
new Log4JLogger(LogManager.getLogger(LibraryManager.class)),
env.getProperty(SpongeNeoTransformationService.Keys.CHECK_LIBRARY_HASHES.get()).orElse(true),
env.getProperty(SpongeNeoTransformationService.Keys.LIBRARIES_DIRECTORY.get())
.orElseThrow(() -> new IllegalStateException("no libraries available")),
SpongeNeoModLocator.class.getResource("libraries.json")
.orElseThrow(() -> new IllegalStateException("No libraries directory available")),
SpongeNeoModLocator.class.getResource("/sponge-libraries.json")
);

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,16 @@
*/
package org.spongepowered.neoforge.hook;

import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.damagesource.DamageSource;
import net.neoforged.neoforge.common.CommonHooks;
import org.spongepowered.common.hooks.EventHooks;

public final class NeoEventHooks implements EventHooks {

@Override
public boolean callPlayerDestruction(ServerPlayer serverPlayer, DamageSource cause) {
return CommonHooks.onLivingDeath(serverPlayer, cause);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* This file is part of Sponge, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* 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 org.spongepowered.neoforge.mixin.inventory.event.entity;

import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.InventoryMenu;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

@Mixin(Player.class)
public abstract class PlayerMixin_Inventory_Neo {

// @formatter:off
@Shadow public AbstractContainerMenu containerMenu;
@Shadow @Final public InventoryMenu inventoryMenu;
// @formatter:on
}
Loading

0 comments on commit 993a94d

Please sign in to comment.