Skip to content

Commit

Permalink
Merge branch '1.21.x' into l10n_1.21.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Matyrobbrt authored Jan 12, 2025
2 parents c53bb6c + 44e71fe commit 0ad1394
Show file tree
Hide file tree
Showing 340 changed files with 3,783 additions and 7,736 deletions.
12 changes: 12 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,18 @@ immaculate {
return sb.toString()
}

// Disallow explicit not null in patches, it's always implied.
custom 'noNotNull', { String fileContents ->
fileContents.eachLine {
if (!it.startsWith("+")) return
if (it.contains('@NotNull') || it.contains('@Nonnull')
|| it.contains('@org.jetbrains.annotations.NotNull')
|| it.contains('@javax.annotation.Nonnull')) {
throw new GradleException('@NotNull and @Nonnull are disallowed.')
}
}
}

//Replace any FQN versions of javax.annotation.Nullable with the jetbrains variant
custom 'jetbrainsNullablePatches', { String fileContents ->
fileContents.replace('@javax.annotation.Nullable', '@org.jetbrains.annotations.Nullable')
Expand Down
50 changes: 28 additions & 22 deletions buildSrc/src/main/java/net/neoforged/neodev/NeoDevPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.io.File;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
Expand Down Expand Up @@ -271,6 +272,7 @@ public void apply(Project project) {
genProductionPatches.flatMap(GenerateSourcePatches::getPatchesFolder)
);

var installerRepositoryUrls = getInstallerRepositoryUrls(project);
// Launcher profile = the version.json file used by the Minecraft launcher.
var createLauncherProfile = tasks.register("createLauncherProfile", CreateLauncherProfile.class, task -> {
task.setGroup(INTERNAL_GROUP);
Expand All @@ -279,17 +281,7 @@ public void apply(Project project) {
task.getNeoForgeVersion().set(neoForgeVersion);
task.getRawNeoFormVersion().set(rawNeoFormVersion);
task.setLibraries(configurations.launcherProfileClasspath);
task.getRepositoryURLs().set(project.provider(() -> {
List<URI> repos = new ArrayList<>();
for (var repo : project.getRepositories().withType(MavenArtifactRepository.class)) {
var uri = repo.getUrl();
if (!uri.toString().endsWith("/")) {
uri = URI.create(uri + "/");
}
repos.add(uri);
}
return repos;
}));
task.getRepositoryURLs().set(installerRepositoryUrls);
// ${version_name}.jar will be filled out by the launcher. It corresponds to the raw SRG Minecraft client jar.
task.getIgnoreList().addAll("client-extra", "${version_name}.jar");
task.setModules(configurations.modulePath);
Expand All @@ -308,17 +300,7 @@ public void apply(Project project) {
task.addLibraries(configurations.launcherProfileClasspath);
// We need the NeoForm zip for the SRG mappings.
task.addLibraries(configurations.neoFormDataOnly);
task.getRepositoryURLs().set(project.provider(() -> {
List<URI> repos = new ArrayList<>();
for (var repo : project.getRepositories().withType(MavenArtifactRepository.class)) {
var uri = repo.getUrl();
if (!uri.toString().endsWith("/")) {
uri = URI.create(uri + "/");
}
repos.add(uri);
}
return repos;
}));
task.getRepositoryURLs().set(installerRepositoryUrls);
task.getUniversalJar().set(universalJar.flatMap(AbstractArchiveTask::getArchiveFile));
task.getInstallerProfile().set(neoDevBuildDir.map(dir -> dir.file("installer-profile.json")));

Expand Down Expand Up @@ -467,6 +449,30 @@ public void apply(Project project) {
setupProductionServerTest(project, installerJar);
}

/**
* Get the list of Maven repositories that may contain artifacts for the installer.
*/
private static Provider<List<URI>> getInstallerRepositoryUrls(Project project) {
return project.provider(() -> {
List<URI> repos = new ArrayList<>();
var projectRepos = project.getRepositories();
if (!projectRepos.isEmpty()) {
for (var repo : projectRepos.withType(MavenArtifactRepository.class)) {
repos.add(repo.getUrl());
}
} else {
// If no project repos are defined, use the repository list we exposed in settings.gradle via an extension
// See the end of settings.gradle for details
Collections.addAll(repos, (URI[]) project.getGradle().getExtensions().getByName("repositoryBaseUrls"));
}

// Ensure all base urls end with a slash
repos.replaceAll(uri -> uri.toString().endsWith("/") ? uri : URI.create(uri + "/"));

return repos;
});
}

private static TaskProvider<TransformSources> configureAccessTransformer(
Project project,
TaskProvider<CreateMinecraftArtifacts> createSourceArtifacts,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import java.io.File;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
Expand All @@ -21,6 +22,8 @@
import java.util.List;
import java.util.Locale;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.function.Function;

Expand All @@ -41,7 +44,7 @@ public static List<Library> resolveLibraries(List<URI> repositoryUrls, Collectio
throw new RuntimeException(e);
}
}).toList();
LOGGER.info("Collected %d libraries".formatted(result.size()));
LOGGER.info("Collected {} libraries", result.size());
return result;
}

Expand All @@ -63,7 +66,9 @@ public static List<Library> resolveLibraries(List<URI> repositoryUrls, Collectio

private final List<Future<Library>> libraries = new ArrayList<>();

private final HttpClient httpClient = HttpClient.newBuilder().build();
private final HttpClient httpClient = HttpClient.newBuilder()
.followRedirects(HttpClient.Redirect.NORMAL)
.build();

private LibraryCollector(List<URI> repoUrl) {
this.repositoryUrls = new ArrayList<>(repoUrl);
Expand All @@ -86,7 +91,7 @@ private LibraryCollector(List<URI> repoUrl) {

LOGGER.info("Collecting libraries from:");
for (var repo : repositoryUrls) {
LOGGER.info(" - " + repo);
LOGGER.info(" - {}", repo);
}
}

Expand All @@ -109,15 +114,15 @@ private void addLibrary(File file, MavenIdentifier identifier) throws IOExceptio
return httpClient.sendAsync(request, HttpResponse.BodyHandlers.discarding())
.thenApply(response -> {
if (response.statusCode() != 200) {
LOGGER.info(" Got %d for %s".formatted(response.statusCode(), artifactUri));
LOGGER.info(" Got {} for {}", response.statusCode(), artifactUri);
String message = "Could not find %s: %d".formatted(artifactUri, response.statusCode());
// Prepend error message from previous repo if they all fail
if (previousError != null) {
message = previousError + "\n" + message;
}
throw new RuntimeException(message);
}
LOGGER.info(" Found %s -> %s".formatted(name, artifactUri));
LOGGER.info(" Found {} -> {}", name, artifactUri);
return new Library(
name,
new LibraryDownload(new LibraryArtifact(
Expand All @@ -132,6 +137,9 @@ private void addLibrary(File file, MavenIdentifier identifier) throws IOExceptio
libraryFuture = makeRequest.apply(null);
} else {
libraryFuture = libraryFuture.exceptionallyCompose(error -> {
if (error instanceof CompletionException e) {
return makeRequest.apply(e.getCause().getMessage());
}
return makeRequest.apply(error.getMessage());
});
}
Expand Down
8 changes: 3 additions & 5 deletions patches/net/minecraft/client/data/Main.java.patch
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
--- a/net/minecraft/client/data/Main.java
+++ b/net/minecraft/client/data/Main.java
@@ -30,16 +_,33 @@
@@ -30,16 +_,31 @@
OptionSpec<Void> optionspec1 = optionparser.accepts("client", "Include client generators");
OptionSpec<Void> optionspec2 = optionparser.accepts("all", "Include all generators");
OptionSpec<String> optionspec3 = optionparser.accepts("output", "Output folder").withRequiredArg().defaultsTo("generated");
+ OptionSpec<String> existing = optionparser.accepts("existing", "Existing resource packs that generated resources can reference").withRequiredArg();
+ OptionSpec<String> existingMod = optionparser.accepts("existing-mod", "Existing mods that generated resources can reference the resource packs of").withRequiredArg();
+ OptionSpec<java.io.File> gameDir = optionparser.accepts("gameDir").withRequiredArg().ofType(java.io.File.class).defaultsTo(new java.io.File(".")).required(); //Need by modlauncher, so lets just eat it
+ optionparser.accepts("gameDir").withRequiredArg().ofType(java.io.File.class).defaultsTo(new java.io.File(".")).required(); //Need by modlauncher, so lets just eat it
+ OptionSpec<String> mod = optionparser.accepts("mod", "A modid to dump").withRequiredArg().withValuesSeparatedBy(",");
+ OptionSpec<Void> flat = optionparser.accepts("flat", "Do not append modid prefix to output directory when generating for multiple mods");
+ OptionSpec<String> assetIndex = optionparser.accepts("assetIndex").withRequiredArg();
Expand All @@ -21,7 +20,6 @@
- ClientBootstrap.bootstrap();
- DataGenerator datagenerator = new DataGenerator(path, SharedConstants.getCurrentVersion(), true);
+ java.util.Collection<Path> existingPacks = optionset.valuesOf(existing).stream().map(Paths::get).toList();
+ java.util.Set<String> existingMods = new java.util.HashSet<>(optionset.valuesOf(existingMod));
+ java.util.Set<String> mods = new java.util.HashSet<>(optionset.valuesOf(mod));
+ boolean isFlat = mods.isEmpty() || optionset.has(flat);
+ boolean validate = optionset.has(validateSpec);
Expand All @@ -30,7 +28,7 @@
addClientProviders(datagenerator, flag1);
- datagenerator.run();
+ }
+ net.neoforged.neoforge.data.loading.DatagenModLoader.begin(mods, path, java.util.List.of(), existingPacks, existingMods, false, false, validate, isFlat, optionset.valueOf(assetIndex), optionset.valueOf(assetsDir), () -> {
+ net.neoforged.neoforge.data.loading.DatagenModLoader.begin(mods, path, java.util.List.of(), existingPacks, false, false, validate, isFlat, optionset.valueOf(assetIndex), optionset.valueOf(assetsDir), () -> {
+ ClientBootstrap.bootstrap();
+ net.neoforged.neoforge.client.ClientHooks.registerSpriteSourceTypes();
+ net.neoforged.neoforge.client.entity.animation.json.AnimationTypeManager.init();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--- a/net/minecraft/client/data/models/BlockModelGenerators.java
+++ b/net/minecraft/client/data/models/BlockModelGenerators.java
@@ -5819,4 +_,16 @@
return this;
}
}
+
+ /**
+ * Neo: create a {@link BlockModelGenerators.BlockFamilyProvider} which re-uses the existing model of the given full
+ * block instead of creating a model and blockstate file for it. Intended for use cases where the full block is
+ * separately generated or otherwise exists such as when a dummy {@link BlockFamily} is used to create additional
+ * variants for existing vanilla block families
+ */
+ public BlockModelGenerators.BlockFamilyProvider familyWithExistingFullBlock(Block fullBlock) {
+ var provider = new BlockModelGenerators.BlockFamilyProvider(TextureMapping.cube(fullBlock));
+ provider.fullBlock = ModelLocationUtils.getModelLocation(fullBlock);
+ return provider;
+ }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--- a/net/minecraft/client/data/models/EquipmentAssetProvider.java
+++ b/net/minecraft/client/data/models/EquipmentAssetProvider.java
@@ -26,6 +_,10 @@
this.pathProvider = p_387559_.createPathProvider(PackOutput.Target.RESOURCE_PACK, "equipment");
}

+ protected void registerModels(BiConsumer<ResourceKey<EquipmentAsset>, EquipmentClientInfo> output) {
+ bootstrap(output);
+ }
+
private static void bootstrap(BiConsumer<ResourceKey<EquipmentAsset>, EquipmentClientInfo> p_387865_) {
p_387865_.accept(
EquipmentAssets.LEATHER,
@@ -106,7 +_,7 @@
@Override
public CompletableFuture<?> run(CachedOutput p_387304_) {
Map<ResourceKey<EquipmentAsset>, EquipmentClientInfo> map = new HashMap<>();
- bootstrap((p_386976_, p_388942_) -> {
+ registerModels((p_386976_, p_388942_) -> {
if (map.putIfAbsent(p_386976_, p_388942_) != null) {
throw new IllegalStateException("Tried to register equipment asset twice for id: " + p_386976_);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--- a/net/minecraft/client/data/models/ItemModelOutput.java
+++ b/net/minecraft/client/data/models/ItemModelOutput.java
@@ -10,4 +_,10 @@
void accept(Item p_387543_, ItemModel.Unbaked p_386880_);

void copy(Item p_387316_, Item p_387995_);
+
+ /**
+ * Neo: Pulled up from {@link ModelProvider.ItemInfoCollector} to give modders full control over the {@link net.minecraft.client.renderer.item.ClientItem} instead of just the {@link ItemModel.Unbaked} in {@link #accept(Item, ItemModel.Unbaked)
+ */
+ default void register(Item item, net.minecraft.client.renderer.item.ClientItem clientItem) {
+ }
}
Loading

0 comments on commit 0ad1394

Please sign in to comment.