Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NPE getting range on NeoForge platform #139

Open
wants to merge 4 commits into
base: multiloader/1.20.6
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions buildSrc/src/main/groovy/multiloader-common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,29 @@ repositories {
includeGroupAndSubgroups("com.terraformersmc")
}
}
exclusiveContent {
forRepository {
maven {
name = "MrCrayfish (GitHub)"
url = "https://maven.pkg.github.com/MrCrayfish/Maven"
credentials {
username = findProperty("gpr.user") ?: System.getenv("GPR_USER")
password = findProperty("gpr.key") ?: System.getenv("GPR_KEY")
if (findProperty("gpr.user") ?: System.getenv("GPR_USER")) {
exclusiveContent {
forRepository {
maven {
name = "MrCrayfish (GitHub)"
url = "https://maven.pkg.github.com/MrCrayfish/Maven"
credentials {
username = findProperty("gpr.user") ?: System.getenv("GPR_USER")
password = findProperty("gpr.key") ?: System.getenv("GPR_KEY")
}
}
}
}
filter {
includeGroupAndSubgroups("com.mrcrayfish")
filter {
includeGroupAndSubgroups("com.mrcrayfish")
}
}
}
if (!System.getenv("CI")) {
if (System.getenv("LOCAL_MAVEN") && !System.getenv("CI")) {
maven {
url "file://" + System.getenv("LOCAL_MAVEN")
url "file://${System.getenv("LOCAL_MAVEN")}"
}
} else {
mavenLocal()
}
maven {
name = 'BlameJared'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.fml.util.ObfuscationReflectionHelper;
import org.apache.commons.lang3.tuple.Pair;

import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -158,27 +157,22 @@ public static <V> V lastValue(List<V> list, V defaultValue)
}

/**
* Reflection to get Forge's range of a value
* Gets Forge's range of a value
*/
@SuppressWarnings({"unchecked", "rawtypes"})
@SuppressWarnings("unchecked")
public void loadRange()
{
if(this.range == null)
{
try
ForgeConfigSpec.Range<?> range = this.valueSpec.getRange();
if(range != null)
{
Object range = ObfuscationReflectionHelper.getPrivateValue(ForgeConfigSpec.ValueSpec.class, this.valueSpec, "range");
if(range != null)
{
Class rangeClass = Class.forName("net.minecraftforge.common.ForgeConfigSpec$Range");
Object min = ObfuscationReflectionHelper.getPrivateValue(rangeClass, range, "min");
Object max = ObfuscationReflectionHelper.getPrivateValue(rangeClass, range, "max");
this.range = Pair.of((T) min, (T) max);
return;
}
this.range = Pair.of((T) range.getMin(), (T) range.getMax());
}
else
{
this.range = Pair.of(null, null);
}
catch(ClassNotFoundException ignored) {}
this.range = Pair.of(null, null);
}
}
}
2 changes: 2 additions & 0 deletions forge/src/test/java/test/config/ConfigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public static class Test
public final ForgeConfigSpec.ConfigValue<List<? extends Long>> longList;
public final ForgeConfigSpec.ConfigValue<List<? extends Double>> doubleList;
public final ForgeConfigSpec.EnumValue<ChatFormatting> restrictedEnums;
public final ForgeConfigSpec.ConfigValue<String> stringWithPattern;

public Test(ForgeConfigSpec.Builder builder)
{
Expand All @@ -59,6 +60,7 @@ public Test(ForgeConfigSpec.Builder builder)
this.longValue = builder.comment("This is a Long value").defineInRange("longValue", 0L, 0L, 10L);
this.enumValue = builder.comment("This is an Enum value").defineEnum("enumValue", ChatFormatting.BLACK);
this.restrictedEnums = builder.comment("An enum value but with restricted values").defineEnum("restrictedEnums", ChatFormatting.RED, ChatFormatting.RED, ChatFormatting.GREEN, ChatFormatting.BLUE);
this.stringWithPattern = builder.comment("A string value with pattern \\d+").define("stringWithPattern", "0", o -> o instanceof String s && s.matches("\\d+"));
builder.pop();
builder.translation("forge_config.config_test.client.lists").push("lists");
this.intList = builder.comment("This is an Integer list").defineList("intList", Arrays.asList(5, 10), o -> o instanceof Integer);
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fabric_version=0.97.8+1.20.6
fabric_loader_version=0.15.10

# NeoForge
neoforge_version=20.6.48-beta
neoforge_version=20.6.99-beta
neoforge_version_range=[20.6,)
neoforge_loader_version_range=[2,)

Expand All @@ -31,7 +31,7 @@ mod_issues=https://github.com/MrCrayfish/Configured/issues
mod_license=GNU Lesser General Public License v3.0

# Dependency options
framework_version=0.8.8
framework_version=0.8.13
jei_version=17.3.0.48
catalogue_version=1.10.1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,22 @@ public static <V> V lastValue(List<V> list, V defaultValue)
}

/**
* Reflection to get Forge's range of a value
* Gets Forge's range of a value
*/
@SuppressWarnings({"unchecked"})
@SuppressWarnings("unchecked")
public void loadRange()
{
if(this.range == null)
{
this.range = Pair.of((T) this.valueSpec.getRange().getMin(), (T) this.valueSpec.getRange().getMax());
ModConfigSpec.Range<?> range = this.valueSpec.getRange();
if(range != null)
{
this.range = Pair.of((T) range.getMin(), (T) range.getMax());
}
else
{
this.range = Pair.of(null, null);
}
}
}
}
3 changes: 3 additions & 0 deletions neoforge/src/test/java/test/config/ConfigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;

/**
* Author: MrCrayfish
Expand Down Expand Up @@ -48,6 +49,7 @@ public static class Test
public final ModConfigSpec.ConfigValue<List<? extends Long>> longList;
public final ModConfigSpec.ConfigValue<List<? extends Double>> doubleList;
public final ModConfigSpec.EnumValue<ChatFormatting> restrictedEnums;
public final ModConfigSpec.ConfigValue<String> stringWithPattern;

public Test(ModConfigSpec.Builder builder)
{
Expand All @@ -59,6 +61,7 @@ public Test(ModConfigSpec.Builder builder)
this.longValue = builder.comment("This is a Long value").defineInRange("longValue", 0L, 0L, 10L);
this.enumValue = builder.comment("This is an Enum value").defineEnum("enumValue", ChatFormatting.BLACK);
this.restrictedEnums = builder.comment("An enum value but with restricted values").defineEnum("restrictedEnums", ChatFormatting.RED, ChatFormatting.RED, ChatFormatting.GREEN, ChatFormatting.BLUE);
this.stringWithPattern = builder.comment("A string value with pattern \\d+").define("stringWithPattern", "0", o -> o instanceof String s && s.matches("\\d+"));
builder.pop();
builder.translation("forge_config.config_test.client.lists").push("lists");
this.intList = builder.comment("This is an Integer list").defineList("intList", Arrays.asList(5, 10), o -> o instanceof Integer);
Expand Down