Skip to content

Commit

Permalink
Update Forge to 40.2.17
Browse files Browse the repository at this point in the history
  • Loading branch information
TonimatasDEV committed Jan 20, 2024
1 parent 6821537 commit 2208f39
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 27 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ ext {
JARJAR_VERSION = '0.3.19'

GIT_INFO = gradleutils.gitInfo
FORGE_VERSION = '40.2.14'
FORGE_VERSION = '40.2.17'
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"

Expand Down
19 changes: 19 additions & 0 deletions fmlcore/src/main/java/net/minecraftforge/fml/IExtensionPoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,24 @@ public interface IExtensionPoint<T extends Record>
*/
record DisplayTest(Supplier<String> suppliedVersion, BiPredicate<String, Boolean> remoteVersionTest) implements IExtensionPoint<DisplayTest> {
public static final String IGNORESERVERONLY = "OHNOES\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31";

/**
* Ignores any version information coming from the server - use for server only mods
*/
public static final Supplier<DisplayTest> IGNORE_SERVER_VERSION = () -> new DisplayTest(IGNORESERVERONLY, (remoteVersion, isFromServer) -> true);

/**
* Ignores all information and provides no information
*/
public static final Supplier<DisplayTest> IGNORE_ALL_VERSION = () -> new DisplayTest("", (remoteVersion, isFromServer) -> true);

/**
* An optional alternative to {@link #DisplayTest(Supplier, BiPredicate)} which accepts a constant version string
* instead of a {@link Supplier}.
* <p>Internally, the provided version string is wrapped in a Supplier for you.</p>
*/
public DisplayTest(String version, BiPredicate<String, Boolean> remoteVersionTest) {
this(() -> version, remoteVersionTest);
}
}
}
21 changes: 19 additions & 2 deletions fmlcore/src/main/java/net/minecraftforge/fml/ModContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.function.BiFunction;
import java.util.function.BiPredicate;
import java.util.function.Consumer;
import java.util.function.Supplier;

Expand Down Expand Up @@ -63,9 +64,9 @@ public ModContainer(IModInfo info)
() -> new IExtensionPoint.DisplayTest(() -> this.modInfo.getVersion().toString(),
(incoming, isNetwork) -> Objects.equals(incoming, this.modInfo.getVersion().toString()));
case "IGNORE_SERVER_VERSION" -> // Ignores any version information coming from the server - use for server only mods
() -> new IExtensionPoint.DisplayTest(() -> IExtensionPoint.DisplayTest.IGNORESERVERONLY, (incoming, isNetwork) -> true);
IExtensionPoint.DisplayTest.IGNORE_SERVER_VERSION;
case "IGNORE_ALL_VERSION" -> // Ignores all information and provides no information
() -> new IExtensionPoint.DisplayTest(() -> "", (incoming, isNetwork) -> true);
IExtensionPoint.DisplayTest.IGNORE_ALL_VERSION;
case "NONE" -> null; // NO display test at all - use this if you're going to do your own display test
default -> // any other value throws an exception
throw new IllegalArgumentException("Invalid displayTest value supplied in mods.toml");
Expand Down Expand Up @@ -142,6 +143,22 @@ public <T extends Record & IExtensionPoint<T>> void registerExtensionPoint(Class
extensionPoints.put(point, extension);
}

public void registerDisplayTest(IExtensionPoint.DisplayTest displayTest) {
registerExtensionPoint(IExtensionPoint.DisplayTest.class, () -> displayTest);
}

public void registerDisplayTest(Supplier<IExtensionPoint.DisplayTest> displayTest) {
registerExtensionPoint(IExtensionPoint.DisplayTest.class, displayTest);
}

public void registerDisplayTest(String version, BiPredicate<String, Boolean> remoteVersionTest) {
registerDisplayTest(new IExtensionPoint.DisplayTest(version, remoteVersionTest));
}

public void registerDisplayTest(Supplier<String> suppliedVersion, BiPredicate<String, Boolean> remoteVersionTest) {
registerDisplayTest(new IExtensionPoint.DisplayTest(suppliedVersion, remoteVersionTest));
}

public void addConfig(final ModConfig modConfig) {
configs.put(modConfig.getType(), modConfig);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraftforge.fml.config.IConfigSpec;
import net.minecraftforge.fml.config.ModConfig;

import java.util.function.BiPredicate;
import java.util.function.Supplier;

public class ModLoadingContext
Expand Down Expand Up @@ -49,6 +50,44 @@ public void registerConfig(ModConfig.Type type, IConfigSpec<?> spec) {
getActiveContainer().addConfig(new ModConfig(type, spec, getActiveContainer()));
}

/**
* Register a {@link IExtensionPoint.DisplayTest} with the mod container.
* <p>A shorthand for registering a DisplayTest with {@link #registerExtensionPoint(Class, Supplier)}.</p>
* @param displayTest The {@link IExtensionPoint.DisplayTest} to register
*/
public void registerDisplayTest(IExtensionPoint.DisplayTest displayTest) {
getActiveContainer().registerDisplayTest(() -> displayTest);
}

/**
* Register a {@link IExtensionPoint.DisplayTest} with the mod container.
* <p>A shorthand for registering a DisplayTest supplier with {@link #registerExtensionPoint(Class, Supplier)}.</p>
* @param displayTest The {@link Supplier<IExtensionPoint.DisplayTest>} to register
*/
public void registerDisplayTest(Supplier<IExtensionPoint.DisplayTest> displayTest) {
getActiveContainer().registerDisplayTest(displayTest);
}

/**
* Register a {@link IExtensionPoint.DisplayTest} with the mod container.
* <p>A shorthand for registering a DisplayTest with {@link #registerExtensionPoint(Class, Supplier)} that also
* creates the DisplayTest instance for you using the provided parameters.</p>
* @see IExtensionPoint.DisplayTest#DisplayTest(String, BiPredicate)
*/
public void registerDisplayTest(String version, BiPredicate<String, Boolean> remoteVersionTest) {
getActiveContainer().registerDisplayTest(new IExtensionPoint.DisplayTest(version, remoteVersionTest));
}

/**
* Register a {@link IExtensionPoint.DisplayTest} with the mod container.
* <p>A shorthand for registering a DisplayTest with {@link #registerExtensionPoint(Class, Supplier)} that also
* creates the DisplayTest instance for you using the provided parameters.</p>
* @see IExtensionPoint.DisplayTest#DisplayTest(Supplier, BiPredicate)
*/
public void registerDisplayTest(Supplier<String> suppliedVersion, BiPredicate<String, Boolean> remoteVersionTest) {
getActiveContainer().registerDisplayTest(new IExtensionPoint.DisplayTest(suppliedVersion, remoteVersionTest));
}

public void registerConfig(ModConfig.Type type, IConfigSpec<?> spec, String fileName) {
getActiveContainer().addConfig(new ModConfig(type, spec, getActiveContainer(), fileName));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ public ModInfo(final ModFileInfo owningFile, final IConfigurable config)
.map(s -> StringSubstitutor.replace(s, ownFile.map(ModFileInfo::getFile).orElse(null)))
.map(DefaultArtifactVersion::new).orElse(DEFAULT_VERSION);
this.displayName = config.<String>getConfigElement("displayName").orElse(this.modId);
this.description = config.<String>getConfigElement("description").orElse("MISSING DESCRIPTION");
this.description = config.<String>getConfigElement("description")
.orElse("MISSING DESCRIPTION")
.replace("\r\n", "\n").stripIndent();

this.logoFile = Optional.ofNullable(config.<String>getConfigElement("logoFile")
.orElseGet(() -> ownFile.flatMap(mf -> mf.<String>getConfigElement("logoFile")).orElse(null)));
Expand Down
42 changes: 20 additions & 22 deletions src/main/java/net/minecraftforge/common/ForgeConfigSpec.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import javax.annotation.Nonnull;
Expand Down Expand Up @@ -55,14 +56,16 @@
*/
public class ForgeConfigSpec extends UnmodifiableConfigWrapper<UnmodifiableConfig> implements IConfigSpec<ForgeConfigSpec>//TODO: Remove extends and pipe everything through getSpec/getValues?
{
private Map<List<String>, String> levelComments;
private Map<List<String>, String> levelTranslationKeys;
private final Map<List<String>, String> levelComments;
private final Map<List<String>, String> levelTranslationKeys;

private UnmodifiableConfig values;
private final UnmodifiableConfig values;
private Config childConfig;

private boolean isCorrecting = false;

private static final Pattern WINDOWS_NEWLINE = Pattern.compile("\r\n");

private ForgeConfigSpec(UnmodifiableConfig storage, UnmodifiableConfig values, Map<List<String>, String> levelComments, Map<List<String>, String> levelTranslationKeys) {
super(storage);
this.values = values;
Expand Down Expand Up @@ -123,11 +126,9 @@ public void afterReload() {

private void resetCaches(final Iterable<Object> configValues) {
configValues.forEach(value -> {
if (value instanceof ConfigValue) {
final ConfigValue<?> configValue = (ConfigValue<?>) value;
if (value instanceof ConfigValue<?> configValue) {
configValue.clearCache();
} else if (value instanceof Config) {
final Config innerConfig = (Config) value;
} else if (value instanceof Config innerConfig) {
this.resetCaches(innerConfig.valueMap().values());
}
});
Expand Down Expand Up @@ -266,15 +267,12 @@ else if (dryRun)

private boolean stringsMatchIgnoringNewlines(@Nullable Object obj1, @Nullable Object obj2)
{
if(obj1 instanceof String && obj2 instanceof String)
if(obj1 instanceof String string1 && obj2 instanceof String string2)
{
String string1 = (String) obj1;
String string2 = (String) obj2;

if(string1.length() > 0 && string2.length() > 0)
if (!string1.isEmpty() && !string2.isEmpty())
{
return string1.replaceAll("\r\n", "\n")
.equals(string2.replaceAll("\r\n", "\n"));
return WINDOWS_NEWLINE.matcher(string1).replaceAll("\n")
.equals(WINDOWS_NEWLINE.matcher(string2).replaceAll("\n"));

}
}
Expand All @@ -286,10 +284,10 @@ public static class Builder
{
private final Config storage = Config.of(LinkedHashMap::new, InMemoryFormat.withUniversalSupport()); // Use LinkedHashMap for consistent ordering
private BuilderContext context = new BuilderContext();
private Map<List<String>, String> levelComments = new HashMap<>();
private Map<List<String>, String> levelTranslationKeys = new HashMap<>();
private List<String> currentPath = new ArrayList<>();
private List<ConfigValue<?>> values = new ArrayList<>();
private final Map<List<String>, String> levelComments = new HashMap<>();
private final Map<List<String>, String> levelTranslationKeys = new HashMap<>();
private final List<String> currentPath = new ArrayList<>();
private final List<ConfigValue<?>> values = new ArrayList<>();
private boolean hasInvalidComment = false;

//Object
Expand Down Expand Up @@ -375,7 +373,7 @@ public Object correct(Object value) {
LogManager.getLogger().debug(CORE, "List on key {} is deemed to need correction. It is null, not a list, or an empty list. Modders, consider defineListAllowEmpty?", path.get(path.size() - 1));
return getDefault();
}
List<?> list = Lists.newArrayList((List<?>) value);
List<?> list = new ArrayList<>((List<?>) value);
list.removeIf(elementValidator.negate());
if (list.isEmpty()) {
LogManager.getLogger().debug(CORE, "List on key {} is deemed to need correction. It failed validation.", path.get(path.size() - 1));
Expand All @@ -395,7 +393,7 @@ public Object correct(Object value) {
LogManager.getLogger().debug(CORE, "List on key {} is deemed to need correction, as it is null or not a list.", path.get(path.size() - 1));
return getDefault();
}
List<?> list = Lists.newArrayList((List<?>) value);
List<?> list = new ArrayList<>((List<?>) value);
list.removeIf(elementValidator.negate());
if (list.isEmpty()) {
LogManager.getLogger().debug(CORE, "List on key {} is deemed to need correction. It failed validation.", path.get(path.size() - 1));
Expand Down Expand Up @@ -696,7 +694,7 @@ private void validate(boolean value, String message)
}

@SuppressWarnings("unused")
private static class Range<V extends Comparable<? super V>> implements Predicate<Object>
public static class Range<V extends Comparable<? super V>> implements Predicate<Object>
{
private final Class<? extends V> clazz;
private final V min;
Expand Down Expand Up @@ -832,7 +830,7 @@ public static class ConfigValue<T> implements Supplier<T>

public List<String> getPath()
{
return Lists.newArrayList(path);
return new ArrayList<>(path);
}

@Override
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
modLoader="javafml"
loaderVersion="[24,]"
issueTrackerURL="http://www.minecraftforge.net/"
issueTrackerURL="https://minecraftforge.net/"
logoFile="forge_logo.png"
license="LGPL v2.1"

Expand All @@ -9,6 +9,7 @@ license="LGPL v2.1"
# We use the global forge version
version="${global.forgeVersion}"
updateJSONURL="https://files.minecraftforge.net/net/minecraftforge/forge/promotions_slim.json"
displayURL="https://minecraftforge.net/"
displayName="Forge"
credits="Anyone who has contributed on Github and supports our development"
authors="LexManos,cpw"
Expand Down

0 comments on commit 2208f39

Please sign in to comment.