From 98cd29b9f119f621f102a365a04b8469ac8e2e5e Mon Sep 17 00:00:00 2001 From: TonimatasDEV Date: Mon, 20 May 2024 18:00:49 +0200 Subject: [PATCH] Update forge to 40.2.21 and fix #24 --- build.gradle | 32 +++++++++------ .../client/ConfigGuiHandler.java | 21 +++++++++- .../common/ForgeConfigSpec.java | 2 +- .../minecraftforge/common/MinecraftForge.java | 40 +++++++++++++++++++ .../v1_18_R2/inventory/CraftItemStack.java | 3 +- 5 files changed, 82 insertions(+), 16 deletions(-) diff --git a/build.gradle b/build.gradle index c6d5e888..b1bfc3c5 100644 --- a/build.gradle +++ b/build.gradle @@ -32,7 +32,7 @@ plugins { id 'com.github.ben-manes.versions' version '0.36.0' id 'net.minecraftforge.gradleutils' version '2.1.3' id 'eclipse' - id 'de.undercouch.download' version '4.1.2' + id 'de.undercouch.download' version '5.1.3' id 'net.nemerosa.versioning' version '3.0.0' } @@ -58,19 +58,19 @@ ext { MODLAUNCHER_VERSION = '9.1.3' SECUREJARHANDLER_VERSION = '1.0.8' BOOTSTRAPLAUNCHER_VERSION = '1.0.0' - ASM_VERSION = '9.5' - INSTALLER_VERSION = '2.1.+' + ASM_VERSION = '9.7' + INSTALLER_VERSION = '2.2.+' MIXIN_VERSION = '0.8.5' JARJAR_VERSION = '0.3.19' GIT_INFO = gradleutils.gitInfo - FORGE_VERSION = '40.2.17' + FORGE_VERSION = '40.2.21' MAGMA_VERSION = "1.18.2-$FORGE_VERSION-" + versioning.info.commit.substring(0, 7) // Use 8 characters for the commit hash VERSION = "1.18.2-$FORGE_VERSION" SPECIAL_SOURCE = 'net.md-5:SpecialSource:1.10.0' BINPATCH_TOOL = 'net.minecraftforge:binarypatcher:1.0.12:fatjar' - INSTALLER_TOOLS = 'net.minecraftforge:installertools:1.3.0' + INSTALLER_TOOLS = 'net.minecraftforge:installertools:1.4.1' JAR_SPLITTER = 'net.minecraftforge:jarsplitter:1.1.4' FART = 'net.minecraftforge:ForgeAutoRenamingTool:0.1.25:all' MIN_TAG_FOR_CHANGELOG = "39.0" @@ -345,7 +345,7 @@ def sharedFmlonlyForge = { Project prj -> } prj.task([type: DownloadMavenArtifact], 'downloadInstaller') { - artifact = "net.minecraftforge:installer:${INSTALLER_VERSION}:shrunk" + artifact = "net.minecraftforge:installer:${INSTALLER_VERSION}:fatjar" changing = true } @@ -743,9 +743,12 @@ project(':forge') { ] } - task crowdin(type: Crowdin) { - key = project.hasProperty('crowdinKey') ? project.crowdinKey : null - //TODO: Merge our english.json? + tasks.register('downloadCrowdin', Download) { + src 'https://files.minecraftforge.net/crowdin.zip' + dest file('build/crowdin.zip') + useETag 'all' + onlyIfModified true + quiet true } sharedFmlonlyForge.call(project) @@ -1087,7 +1090,7 @@ project(':forge') { 'libraries/' + Util.getMavenPath(rootProject.tasks.findByPath(':fmlloader:jar')), "libraries/net/minecraft/server/${MC_VERSION}-${MCP_VERSION}/server-${MC_VERSION}-${MCP_VERSION}-extra.jar", "libraries/cpw/mods/bootstraplauncher/1.0.0/bootstraplauncher-1.0.0.jar", - "libraries/net/minecraftforge/installertools/1.3.0/installertools-1.3.0.jar" + "libraries/net/minecraftforge/installertools/1.4.1/installertools-1.4.1.jar" ] def claimed = CLASS_PATH.collect { it.rsplit('/', 2)[0] }.toSet() // Allow us to override versions if (rootProject.downloadServerRaw.dest.exists()) { @@ -1184,9 +1187,12 @@ project(':forge') { from extraTxts // add crowdin locales - from { crowdin.output.present && crowdin.output.get().asFile.exists() ? zipTree(crowdin.output) : null} - dependsOn crowdin - duplicatesStrategy = 'exclude' + from zipTree(downloadCrowdin.dest).matching { + include 'assets/forge/lang/*.json' + } + + dependsOn downloadCrowdin + duplicatesStrategy = DuplicatesStrategy.EXCLUDE doFirst { MANIFESTS.each{ pkg, values -> diff --git a/src/main/java/net/minecraftforge/client/ConfigGuiHandler.java b/src/main/java/net/minecraftforge/client/ConfigGuiHandler.java index 4d92822c..86c428c7 100644 --- a/src/main/java/net/minecraftforge/client/ConfigGuiHandler.java +++ b/src/main/java/net/minecraftforge/client/ConfigGuiHandler.java @@ -13,10 +13,29 @@ import java.util.Optional; import java.util.function.BiFunction; +import java.util.function.Function; public class ConfigGuiHandler { - public record ConfigGuiFactory(BiFunction screenFunction) implements IExtensionPoint {} + /** + * @param screenFunction A function that takes the {@link Minecraft} client instance and the mods screen as + * arguments and returns your config screen to show when the player clicks the config button + * for your mod on the mods screen. + *

You should call {@link Minecraft#setScreen(Screen)} with the provided client instance + * and mods screen for the action of your close button.

+ */ + public record ConfigGuiFactory(BiFunction screenFunction) implements IExtensionPoint { + /** + * @param screenFunction A function that takes the mods screen as an argument and returns your config screen to + * show when the player clicks the config button for your mod on the mods screen. + *

You should call {@link Minecraft#setScreen(Screen)} with the provided mods screen + * for the action of your close button, using {@link Screen#minecraft} to get the client + * instance.

+ */ + public ConfigGuiFactory(Function screenFunction) { + this((mcClient, modsScreen) -> screenFunction.apply(modsScreen)); + } + } public static Optional> getGuiFactoryFor(IModInfo selectedMod) { return ModList.get().getModContainerById(selectedMod.getModId()). diff --git a/src/main/java/net/minecraftforge/common/ForgeConfigSpec.java b/src/main/java/net/minecraftforge/common/ForgeConfigSpec.java index 5ffdbb4d..4521a718 100644 --- a/src/main/java/net/minecraftforge/common/ForgeConfigSpec.java +++ b/src/main/java/net/minecraftforge/common/ForgeConfigSpec.java @@ -353,7 +353,7 @@ public ConfigValue defineInList(List path, T defaultValue, Collec return defineInList(path, () -> defaultValue, acceptableValues); } public ConfigValue defineInList(List path, Supplier defaultSupplier, Collection acceptableValues) { - return define(path, defaultSupplier, acceptableValues::contains); + return define(path, defaultSupplier, o -> o != null && acceptableValues.contains(o)); } public ConfigValue> defineList(String path, List defaultValue, Predicate elementValidator) { return defineList(split(path), defaultValue, elementValidator); diff --git a/src/main/java/net/minecraftforge/common/MinecraftForge.java b/src/main/java/net/minecraftforge/common/MinecraftForge.java index 7cd76ecb..f038bf73 100644 --- a/src/main/java/net/minecraftforge/common/MinecraftForge.java +++ b/src/main/java/net/minecraftforge/common/MinecraftForge.java @@ -5,10 +5,16 @@ package net.minecraftforge.common; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.screens.Screen; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.client.ClientCommandHandler; +import net.minecraftforge.client.ConfigGuiHandler; import net.minecraftforge.eventbus.api.BusBuilder; import net.minecraftforge.eventbus.api.IEventBus; +import net.minecraftforge.fml.ModLoadingContext; +import net.minecraftforge.fml.config.IConfigSpec; +import net.minecraftforge.fml.config.ModConfig; import net.minecraftforge.fml.loading.FMLEnvironment; import net.minecraftforge.network.DualStackUtils; import net.minecraftforge.versions.forge.ForgeVersion; @@ -17,6 +23,10 @@ import org.apache.logging.log4j.Marker; import org.apache.logging.log4j.MarkerManager; +import java.util.function.BiFunction; +import java.util.function.Function; +import java.util.function.Supplier; + public class MinecraftForge { /** @@ -46,6 +56,36 @@ public static void initialize() DualStackUtils.initialise(); } + /** + * Register a config screen for the active mod container. + * @param screenFunction A function that takes the mods screen as an argument and returns your config screen to + * show when the player clicks the config button for your mod on the mods screen. + *

You should call {@link Minecraft#setScreen(Screen)} with the provided mods screen for the + * action of your close button, using {@link Screen#minecraft} to get the client instance.

+ * @see ModLoadingContext#registerExtensionPoint(Class, Supplier) + * @see ModLoadingContext#registerConfig(ModConfig.Type, IConfigSpec) + */ + public static void registerConfigScreen(Function screenFunction) { + registerConfigScreen((mcClient, modsScreen) -> screenFunction.apply(modsScreen)); + } + + /** + * Register a config screen for the active mod container. + * @param screenFunction A function that takes the {@link Minecraft} client instance and the mods screen as + * arguments and returns your config screen to show when the player clicks the config button + * for your mod on the mods screen. + *

You should call {@link Minecraft#setScreen(Screen)} with the provided client instance + * and mods screen for the action of your close button.

+ * @see ModLoadingContext#registerExtensionPoint(Class, Supplier) + * @see ModLoadingContext#registerConfig(ModConfig.Type, IConfigSpec) + */ + public static void registerConfigScreen(BiFunction screenFunction) { + ModLoadingContext.get().registerExtensionPoint( + ConfigGuiHandler.ConfigGuiFactory.class, + () -> new ConfigGuiHandler.ConfigGuiFactory(screenFunction) + ); + } + /* public static void preloadCrashClasses(ASMDataTable table, String modID, Set classes) { diff --git a/src/main/java/org/bukkit/craftbukkit/v1_18_R2/inventory/CraftItemStack.java b/src/main/java/org/bukkit/craftbukkit/v1_18_R2/inventory/CraftItemStack.java index 5f787b53..63f007f8 100644 --- a/src/main/java/org/bukkit/craftbukkit/v1_18_R2/inventory/CraftItemStack.java +++ b/src/main/java/org/bukkit/craftbukkit/v1_18_R2/inventory/CraftItemStack.java @@ -369,7 +369,8 @@ public static ItemMeta getItemMeta(net.minecraft.world.item.ItemStack item) { } static Material getType(net.minecraft.world.item.ItemStack item) { - return item == null ? Material.AIR : CraftMagicNumbers.getMaterial(item.getItem()); + Material material = CraftMagicNumbers.getMaterial(item.getItem()); + return material == null ? Material.AIR : material; } @Override