Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

Commit

Permalink
Update to forge 47.2.20
Browse files Browse the repository at this point in the history
  • Loading branch information
TonimatasDEV committed Jan 17, 2024
1 parent b18fa30 commit e14add5
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 31 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ ext {
COMMONS_IO_VERSION = '2.11.0'

GIT_INFO = gradleutils.gitInfo
FORGE_VERSION = '47.2.17'
FORGE_VERSION = '47.2.20'
MAGMA_VERSION = "1.20.1-$FORGE_VERSION-" + versioning.info.commit.substring(0, 7) // Use 7 characters for the commit hash
VERSION = "1.20.1-$FORGE_VERSION"

Expand Down
18 changes: 18 additions & 0 deletions fmlcore/src/main/java/net/minecraftforge/fml/IExtensionPoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,23 @@ public interface IExtensionPoint<T extends Record>
@SuppressWarnings("JavadocReference") // reference to NetworkConstants, ForgeHooksClient
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 @@ -21,6 +21,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 @@ -64,9 +65,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 @@ -145,6 +146,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 @@ -12,6 +12,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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

public class ModLoadingContext
Expand Down Expand Up @@ -50,6 +51,44 @@ public <T extends Record & IExtensionPoint<T>> void registerExtensionPoint(Class
getActiveContainer().registerExtensionPoint(point, extension);
}

/**
* 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) {
if (spec.isEmpty())
{
Expand Down
36 changes: 18 additions & 18 deletions src/main/java/net/minecraftforge/common/ForgeConfigSpec.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,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 net.minecraftforge.fml.Logging;
Expand Down Expand Up @@ -49,15 +50,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 Logger LOGGER = LogManager.getLogger();
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);
Expand Down Expand Up @@ -119,11 +121,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 @@ -264,10 +264,10 @@ private boolean stringsMatchIgnoringNewlines(@Nullable Object obj1, @Nullable Ob
{
if (obj1 instanceof String string1 && obj2 instanceof String string2)
{
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 @@ -279,10 +279,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<>();

//Object
public <T> ConfigValue<T> define(String path, T defaultValue) {
Expand Down Expand Up @@ -366,7 +366,7 @@ public Object correct(Object value) {
LOGGER.debug(Logging.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()) {
LOGGER.debug(Logging.CORE, "List on key {} is deemed to need correction. It failed validation.", path.get(path.size() - 1));
Expand Down Expand Up @@ -394,7 +394,7 @@ public Object correct(Object value) {
LOGGER.debug(Logging.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()) {
LOGGER.debug(Logging.CORE, "List on key {} is deemed to need correction. It failed validation.", path.get(path.size() - 1));
Expand Down Expand Up @@ -695,7 +695,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 @@ -825,7 +825,7 @@ public static class ConfigValue<T> implements Supplier<T>

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

/**
Expand Down
21 changes: 11 additions & 10 deletions src/main/java/net/minecraftforge/common/extensions/IForgeItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -340,16 +340,17 @@ default void onArmorTick(ItemStack stack, Level level, Player player)
*/
default void onInventoryTick(ItemStack stack, Level level, Player player, int slotIndex, int selectedIndex)
{
// For compatibility reasons we have to use non-local index values, I think this is a vanilla bug but lets maintain compatibility
int vanillaIndex = slotIndex;
if (slotIndex >= 36) {
vanillaIndex -= 36;
if (vanillaIndex >= 4)
vanillaIndex -= 4;
else
onArmorTick(stack, level, player);
}
stack.inventoryTick(level, player, vanillaIndex, selectedIndex == vanillaIndex);
// For compatibility reasons we have to use non-local index values, I think this is a vanilla bug but lets maintain compatibility
var inv = player.getInventory();
int vanillaIndex = slotIndex;
if (slotIndex >= inv.items.size()) {
vanillaIndex -= inv.items.size();
if (vanillaIndex >= inv.armor.size())
vanillaIndex -= inv.armor.size();
else
onArmorTick(stack, level, player);
}
stack.inventoryTick(level, player, vanillaIndex, selectedIndex == vanillaIndex);
}

/**
Expand Down

0 comments on commit e14add5

Please sign in to comment.