From 9c8e12db3bc7eafd3c51d9d9837ca499775217b3 Mon Sep 17 00:00:00 2001 From: HypherionMC Date: Thu, 19 Nov 2020 00:57:12 +0200 Subject: [PATCH 1/6] Initial Porting --- build.gradle | 94 +- gradle.properties | 4 +- gradle/wrapper/gradle-wrapper.properties | 2 +- .../loenwind/autoconfig/ConfigHandler.java | 5 +- .../autoconfig/factory/AbstractValue.java | 8 +- .../autoconfig/factory/BooleanValue.java | 5 +- .../autoconfig/factory/ByteBufAdapters.java | 4 +- .../autoconfig/factory/DoubleValue.java | 4 +- .../autoconfig/factory/FactoryManager.java | 13 +- .../autoconfig/factory/FloatValue.java | 4 +- .../autoconfig/factory/FluidValue.java | 12 +- .../loenwind/autoconfig/factory/IFactory.java | 2 - .../autoconfig/factory/IRootFactory.java | 1 - .../autoconfig/factory/IValueFactory.java | 2 +- .../autoconfig/factory/IntListValue.java | 4 +- .../loenwind/autoconfig/factory/IntValue.java | 4 +- .../factory/LimitedStringValue.java | 5 +- .../autoconfig/factory/SlaveFactory.java | 3 +- .../autoconfig/factory/StringListValue.java | 4 +- .../autoconfig/factory/StringValue.java | 5 +- .../autoconfig/factory/ValueFactory.java | 1 - .../autoconfig/util/ConfigProperty.java | 1183 +++++++++++++++++ .../info/loenwind/autoconfig/util/Lang.java | 11 +- 23 files changed, 1299 insertions(+), 81 deletions(-) create mode 100644 src/main/java/info/loenwind/autoconfig/util/ConfigProperty.java diff --git a/build.gradle b/build.gradle index 34d1a6a..13d9505 100644 --- a/build.gradle +++ b/build.gradle @@ -1,3 +1,6 @@ +import net.minecraftforge.gradle.common.task.SignJar +import groovy.json.JsonSlurper +import groovy.json.JsonOutput buildscript { repositories { jcenter() @@ -5,8 +8,8 @@ buildscript { maven { url = "http://files.minecraftforge.net/maven" } maven { url = "https://oss.sonatype.org/content/repositories/snapshots/" } } - dependencies { - classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT' + dependencies { + classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true } } @@ -14,7 +17,7 @@ plugins { id "com.matthewprenger.cursegradle" version "1.0.7" } -apply plugin: 'net.minecraftforge.gradle.forge' +apply plugin: 'net.minecraftforge.gradle' apply plugin: 'maven-publish' ext.buildnumber = 0 @@ -41,9 +44,59 @@ if (project.hasProperty('mod_appendix')) { } minecraft { - mappings = "snapshot_20171212" - version = "${minecraft_version}-${forge_version}" - runDir = 'run' + mappings channel: 'snapshot', version: "20201028-1.16.3" + + runs { + client { + workingDirectory project.file('run') + + // Recommended logging data for a userdev environment + property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP' + + // Recommended logging level for the console + property 'forge.logging.console.level', 'debug' + + mods { + examplemod { + source sourceSets.main + } + } + } + + server { + workingDirectory project.file('run') + + // Recommended logging data for a userdev environment + property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP' + + // Recommended logging level for the console + property 'forge.logging.console.level', 'debug' + + mods { + examplemod { + source sourceSets.main + } + } + } + + data { + workingDirectory project.file('run') + + // Recommended logging data for a userdev environment + property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP' + + // Recommended logging level for the console + property 'forge.logging.console.level', 'debug' + + args '--mod', 'examplemod', '--all', '--output', file('src/generated/resources/') + + mods { + examplemod { + source sourceSets.main + } + } + } + } } jar { @@ -53,6 +106,7 @@ jar { } dependencies { + minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" testImplementation "org.junit.jupiter:junit-jupiter-api:5.2.0" testRuntime "org.junit.jupiter:junit-jupiter-engine:5.2.0" } @@ -61,22 +115,6 @@ configurations { compile.extendsFrom exportedCompile } -processResources { - inputs.property "version", project.version - inputs.property "mcversion", project.minecraft.version - - from(sourceSets.main.resources.srcDirs) { - include '**/*.info' - include '**/*.properties' - - expand 'version': project.version, 'mcversion': project.minecraft.version - } - - from(sourceSets.main.resources.srcDirs) { - exclude '**/*.info' - exclude '**/*.properties' - } -} test { useJUnitPlatform() @@ -102,7 +140,13 @@ if (JavaVersion.current().isJava8Compatible()) { } } -build.dependsOn sourceJar, javadoc + +task srcJar(type: Jar) { + from(sourceSets.main.output) + classifier = 'srcs' +} + +build.dependsOn srcJar, javadoc publishing { tasks.publish.dependsOn 'build' @@ -110,7 +154,7 @@ publishing { mavenJava(MavenPublication) { from components.java - artifact sourceJar + artifact srcJar } } @@ -174,7 +218,7 @@ task mkKeyStore(type:Exec) { commandLine 'keytool', '-genkey', '-alias', 'signFiles', '-keystore', 'autosavestore.jks', '-storepass', '123456', '-noprompt', '-dname', 'CN='+getCN(), '-keypass', '123456' } -task signJar(type: SignJar, dependsOn: reobfJar) { +task signJar(type: SignJar, dependsOn: jar) { inputFile = jar.archivePath outputFile = jar.archivePath keyStore = 'autosavestore.jks' diff --git a/gradle.properties b/gradle.properties index a958680..6718526 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ -minecraft_version=1.12.2 -forge_version=14.23.5.2847 +minecraft_version=1.16.3 +forge_version=34.1.42 mod_version=1.0 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 1e9b863..f5095af 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-bin.zip diff --git a/src/main/java/info/loenwind/autoconfig/ConfigHandler.java b/src/main/java/info/loenwind/autoconfig/ConfigHandler.java index bdb4915..505e74b 100644 --- a/src/main/java/info/loenwind/autoconfig/ConfigHandler.java +++ b/src/main/java/info/loenwind/autoconfig/ConfigHandler.java @@ -9,10 +9,7 @@ import info.loenwind.autoconfig.util.Log; import info.loenwind.autoconfig.util.NullHelper; import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.common.config.Configuration; -import net.minecraftforge.fml.client.event.ConfigChangedEvent.OnConfigChangedEvent; -import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; public class ConfigHandler { diff --git a/src/main/java/info/loenwind/autoconfig/factory/AbstractValue.java b/src/main/java/info/loenwind/autoconfig/factory/AbstractValue.java index c0162f3..318a64a 100644 --- a/src/main/java/info/loenwind/autoconfig/factory/AbstractValue.java +++ b/src/main/java/info/loenwind/autoconfig/factory/AbstractValue.java @@ -10,8 +10,8 @@ import info.loenwind.autoconfig.util.NullHelper; import io.netty.buffer.ByteBuf; import net.minecraft.client.Minecraft; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; public abstract class AbstractValue implements IValue { @@ -95,7 +95,7 @@ public IValue startup() { return sync(); } - @SideOnly(Side.CLIENT) + @OnlyIn(Dist.CLIENT) public void onServerSync(Map serverConfig) { if (isStartup && serverConfig.containsKey(keyname)) { @SuppressWarnings("unchecked") @@ -103,7 +103,7 @@ public void onServerSync(Map serverConfig) { T clientValue = get(); if (!clientValue.equals(serverValue)) { Log.error(Lang.NETWORK_BAD_CONFIG.get(section, keyname, serverValue)); - Minecraft.getMinecraft().player.connection.getNetworkManager().closeChannel(Lang.NETWORK_BAD_CONFIG.toChat(section, keyname, serverValue)); + Minecraft.getInstance().player.connection.getNetworkManager().closeChannel(Lang.NETWORK_BAD_CONFIG.toChat(section, keyname, serverValue)); } } } diff --git a/src/main/java/info/loenwind/autoconfig/factory/BooleanValue.java b/src/main/java/info/loenwind/autoconfig/factory/BooleanValue.java index 6de2977..e394b21 100644 --- a/src/main/java/info/loenwind/autoconfig/factory/BooleanValue.java +++ b/src/main/java/info/loenwind/autoconfig/factory/BooleanValue.java @@ -3,8 +3,7 @@ import java.util.Random; import javax.annotation.Nullable; - -import net.minecraftforge.common.config.Property; +import info.loenwind.autoconfig.util.ConfigProperty; class BooleanValue extends AbstractValue { @@ -14,7 +13,7 @@ protected BooleanValue(IValueFactory owner, String section, String keyname, Bool @Override protected @Nullable Boolean makeValue() { - Property prop = owner.getConfig().get(section, keyname, defaultValue); + ConfigProperty prop = owner.getConfig().get(section, keyname, defaultValue); prop.setLanguageKey(keyname); prop.setComment(getText() + " [default: " + defaultValue + "]"); prop.setRequiresMcRestart(isStartup); diff --git a/src/main/java/info/loenwind/autoconfig/factory/ByteBufAdapters.java b/src/main/java/info/loenwind/autoconfig/factory/ByteBufAdapters.java index 38fb790..52607af 100644 --- a/src/main/java/info/loenwind/autoconfig/factory/ByteBufAdapters.java +++ b/src/main/java/info/loenwind/autoconfig/factory/ByteBufAdapters.java @@ -9,8 +9,10 @@ import info.loenwind.autoconfig.util.NullHelper; import io.netty.buffer.ByteBuf; +import net.minecraft.fluid.Fluid; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.registries.ForgeRegistries; public class ByteBufAdapters { @@ -251,7 +253,7 @@ public String getName() { @Override public void saveValue(ByteBuf buf, @Nonnull Fluid value) { - final byte[] vbytes = NullHelper.first(FluidRegistry.getFluidName(value), "").getBytes(Charset.forName("UTF-8")); + final byte[] vbytes = NullHelper.first(ForgeRegistries.FLUIDS.getKey(value), "").getBytes(Charset.forName("UTF-8")); if (vbytes.length > 0x7F) { throw new RuntimeException("Fluid name too long"); } diff --git a/src/main/java/info/loenwind/autoconfig/factory/DoubleValue.java b/src/main/java/info/loenwind/autoconfig/factory/DoubleValue.java index a62cdfc..63cc09f 100644 --- a/src/main/java/info/loenwind/autoconfig/factory/DoubleValue.java +++ b/src/main/java/info/loenwind/autoconfig/factory/DoubleValue.java @@ -4,7 +4,7 @@ import javax.annotation.Nullable; -import net.minecraftforge.common.config.Property; +import info.loenwind.autoconfig.util.ConfigProperty; class DoubleValue extends AbstractValue { @@ -16,7 +16,7 @@ protected DoubleValue(IValueFactory owner, String section, String keyname, Doubl protected @Nullable Double makeValue() { String comment = getText() + " [range: " + (minValue != null ? minValue : Double.NEGATIVE_INFINITY) + " ~ " + (maxValue != null ? maxValue : Double.MAX_VALUE) + ", default: " + defaultValue + "]"; - final Property property = owner.getConfig().get(section, keyname, defaultValue, comment); + final ConfigProperty property = owner.getConfig().get(section, keyname, defaultValue, comment); if (minValue != null) { property.setMinValue(minValue); } diff --git a/src/main/java/info/loenwind/autoconfig/factory/FactoryManager.java b/src/main/java/info/loenwind/autoconfig/factory/FactoryManager.java index adad567..96c24fb 100644 --- a/src/main/java/info/loenwind/autoconfig/factory/FactoryManager.java +++ b/src/main/java/info/loenwind/autoconfig/factory/FactoryManager.java @@ -6,11 +6,10 @@ import info.loenwind.autoconfig.util.Log; import info.loenwind.autoconfig.util.NullHelper; import io.netty.buffer.ByteBuf; -import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.entity.player.PlayerEntity; import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent; -import net.minecraftforge.fml.common.network.FMLNetworkEvent.ClientDisconnectionFromServerEvent; +import net.minecraftforge.event.entity.player.PlayerEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; public class FactoryManager { @@ -47,11 +46,11 @@ static void registerFactory(IValueFactory factory) { } @SubscribeEvent - public static void onPlayerLoggon(final PlayerLoggedInEvent evt) { + public static void onPlayerLoggon(final PlayerEvent.PlayerLoggedInEvent evt) { for (IValueFactory factory : factories.values()) { if (factory.needsSyncing()) { - Network.sendTo(new PacketConfigSync(factory), (EntityPlayerMP) NullHelper.notnullF(evt.player, "PlayerLoggedInEvent without player")); - Log.debug("Sent config to player " + evt.player.getDisplayNameString() + " for " + factory.getModid() + " (" + factory.getSection() + ")"); + Network.sendTo(new PacketConfigSync(factory), (PlayerEntity) NullHelper.notnullF(evt.getPlayer(), "PlayerLoggedInEvent without player")); + Log.debug("Sent config to player " + evt.getPlayer().getDisplayName() + " for " + factory.getModid() + " (" + factory.getSection() + ")"); } } } diff --git a/src/main/java/info/loenwind/autoconfig/factory/FloatValue.java b/src/main/java/info/loenwind/autoconfig/factory/FloatValue.java index ef44015..22ce665 100644 --- a/src/main/java/info/loenwind/autoconfig/factory/FloatValue.java +++ b/src/main/java/info/loenwind/autoconfig/factory/FloatValue.java @@ -4,8 +4,8 @@ import javax.annotation.Nullable; +import info.loenwind.autoconfig.util.ConfigProperty; import net.minecraft.util.math.MathHelper; -import net.minecraftforge.common.config.Property; class FloatValue extends AbstractValue { @@ -17,7 +17,7 @@ protected FloatValue(IValueFactory owner, String section, String keyname, Float protected @Nullable Float makeValue() { float min = minValue != null ? minValue.floatValue() : Float.NEGATIVE_INFINITY, max = maxValue != null ? maxValue.floatValue() : Float.MAX_VALUE; @SuppressWarnings("cast") - Property prop = owner.getConfig().get(section, keyname, (double) defaultValue); + ConfigProperty prop = owner.getConfig().get(section, keyname, (double) defaultValue); prop.setLanguageKey(keyname); prop.setComment(getText() + " [range: " + min + " ~ " + max + ", default: " + defaultValue + "]"); prop.setMinValue(min); diff --git a/src/main/java/info/loenwind/autoconfig/factory/FluidValue.java b/src/main/java/info/loenwind/autoconfig/factory/FluidValue.java index 19dfc97..96e65ec 100644 --- a/src/main/java/info/loenwind/autoconfig/factory/FluidValue.java +++ b/src/main/java/info/loenwind/autoconfig/factory/FluidValue.java @@ -5,12 +5,10 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; +import info.loenwind.autoconfig.util.ConfigProperty; import info.loenwind.autoconfig.util.NullHelper; -import net.minecraftforge.common.config.Property; -import net.minecraftforge.fluids.Fluid; -import net.minecraftforge.fluids.FluidRegistry; -import net.minecraftforge.fml.common.Loader; -import net.minecraftforge.fml.common.LoaderState; +import net.minecraft.fluid.Fluid; +import net.minecraftforge.fml.loading.FMLLoader; class FluidValue extends AbstractValue { @@ -28,7 +26,7 @@ protected FluidValue(IValueFactory owner, String section, String keyname, String @Override public Fluid get() { final String valueInConfig = getString(); // make sure the config value is registered with the config object - if (!Loader.instance().hasReachedState(LoaderState.INITIALIZATION)) { + if (!FMLLoader.hasReachedState(LoaderState.INITIALIZATION)) { return defaultValue; } if (defaultFluid == null) { @@ -50,7 +48,7 @@ public Fluid get() { } private @Nullable String getString() { - Property prop = owner.getConfig().get(section, keyname, defaultValueName); + ConfigProperty prop = owner.getConfig().get(section, keyname, defaultValueName); prop.setLanguageKey(keyname); prop.setValidationPattern(null); prop.setComment(getText() + " [default: " + defaultValueName + "]"); diff --git a/src/main/java/info/loenwind/autoconfig/factory/IFactory.java b/src/main/java/info/loenwind/autoconfig/factory/IFactory.java index 676817e..a87a1d5 100644 --- a/src/main/java/info/loenwind/autoconfig/factory/IFactory.java +++ b/src/main/java/info/loenwind/autoconfig/factory/IFactory.java @@ -1,7 +1,5 @@ package info.loenwind.autoconfig.factory; -import net.minecraftforge.common.config.Configuration; - public interface IFactory { IValueFactory section(String section); diff --git a/src/main/java/info/loenwind/autoconfig/factory/IRootFactory.java b/src/main/java/info/loenwind/autoconfig/factory/IRootFactory.java index d1c3d30..0afd52a 100644 --- a/src/main/java/info/loenwind/autoconfig/factory/IRootFactory.java +++ b/src/main/java/info/loenwind/autoconfig/factory/IRootFactory.java @@ -1,6 +1,5 @@ package info.loenwind.autoconfig.factory; -import net.minecraftforge.common.config.Configuration; public interface IRootFactory extends IFactory { diff --git a/src/main/java/info/loenwind/autoconfig/factory/IValueFactory.java b/src/main/java/info/loenwind/autoconfig/factory/IValueFactory.java index b4122f8..48b3c6a 100644 --- a/src/main/java/info/loenwind/autoconfig/factory/IValueFactory.java +++ b/src/main/java/info/loenwind/autoconfig/factory/IValueFactory.java @@ -6,7 +6,7 @@ import javax.annotation.Nullable; import io.netty.buffer.ByteBuf; -import net.minecraftforge.fluids.Fluid; +import net.minecraft.fluid.Fluid; public interface IValueFactory extends IFactory { diff --git a/src/main/java/info/loenwind/autoconfig/factory/IntListValue.java b/src/main/java/info/loenwind/autoconfig/factory/IntListValue.java index 56d853e..375949f 100644 --- a/src/main/java/info/loenwind/autoconfig/factory/IntListValue.java +++ b/src/main/java/info/loenwind/autoconfig/factory/IntListValue.java @@ -2,8 +2,8 @@ import javax.annotation.Nullable; +import info.loenwind.autoconfig.util.ConfigProperty; import net.minecraft.util.math.MathHelper; -import net.minecraftforge.common.config.Property; class IntListValue extends AbstractValue { @@ -14,7 +14,7 @@ protected IntListValue(IValueFactory owner, String section, String keyname, int[ @Override protected @Nullable int[] makeValue() { int min = minValue != null ? minValue.intValue() : Integer.MIN_VALUE, max = maxValue != null ? maxValue.intValue() : Integer.MAX_VALUE; - Property prop = owner.getConfig().get(section, keyname, defaultValue); + ConfigProperty prop = owner.getConfig().get(section, keyname, defaultValue); prop.setLanguageKey(keyname); prop.setComment(getText() + " [range: " + min + " ~ " + max + ", default: " + defaultValue + "]"); prop.setMinValue(min); diff --git a/src/main/java/info/loenwind/autoconfig/factory/IntValue.java b/src/main/java/info/loenwind/autoconfig/factory/IntValue.java index c879b03..72633d8 100644 --- a/src/main/java/info/loenwind/autoconfig/factory/IntValue.java +++ b/src/main/java/info/loenwind/autoconfig/factory/IntValue.java @@ -4,8 +4,8 @@ import javax.annotation.Nullable; +import info.loenwind.autoconfig.util.ConfigProperty; import net.minecraft.util.math.MathHelper; -import net.minecraftforge.common.config.Property; class IntValue extends AbstractValue { @@ -16,7 +16,7 @@ protected IntValue(IValueFactory owner, String section, String keyname, Integer @Override protected @Nullable Integer makeValue() { int min = minValue != null ? minValue.intValue() : Integer.MIN_VALUE, max = maxValue != null ? maxValue.intValue() : Integer.MAX_VALUE; - Property prop = owner.getConfig().get(section, keyname, defaultValue); + ConfigProperty prop = owner.getConfig().get(section, keyname, defaultValue); prop.setLanguageKey(keyname); prop.setComment(getText() + " [range: " + min + " ~ " + max + ", default: " + defaultValue + "]"); prop.setMinValue(min); diff --git a/src/main/java/info/loenwind/autoconfig/factory/LimitedStringValue.java b/src/main/java/info/loenwind/autoconfig/factory/LimitedStringValue.java index 89aba77..0a5dde5 100644 --- a/src/main/java/info/loenwind/autoconfig/factory/LimitedStringValue.java +++ b/src/main/java/info/loenwind/autoconfig/factory/LimitedStringValue.java @@ -1,8 +1,9 @@ package info.loenwind.autoconfig.factory; +import info.loenwind.autoconfig.util.ConfigProperty; + import javax.annotation.Nullable; -import net.minecraftforge.common.config.Property; class LimitedStringValue extends AbstractValue { @@ -15,7 +16,7 @@ protected LimitedStringValue(IValueFactory owner, String section, String keyname @Override protected @Nullable String makeValue() { - Property prop = owner.getConfig().get(section, keyname, defaultValue); + ConfigProperty prop = owner.getConfig().get(section, keyname, defaultValue); prop.setValidValues(limit); prop.setLanguageKey(keyname); prop.setComment(getText() + " [default: " + defaultValue + ", possible values: " + String.join(", ", limit) + "]"); diff --git a/src/main/java/info/loenwind/autoconfig/factory/SlaveFactory.java b/src/main/java/info/loenwind/autoconfig/factory/SlaveFactory.java index f86fed9..f3708f1 100644 --- a/src/main/java/info/loenwind/autoconfig/factory/SlaveFactory.java +++ b/src/main/java/info/loenwind/autoconfig/factory/SlaveFactory.java @@ -9,8 +9,7 @@ import javax.annotation.Nullable; import io.netty.buffer.ByteBuf; -import net.minecraftforge.common.config.Configuration; -import net.minecraftforge.fluids.Fluid; +import net.minecraft.fluid.Fluid; public class SlaveFactory implements IValueFactory { diff --git a/src/main/java/info/loenwind/autoconfig/factory/StringListValue.java b/src/main/java/info/loenwind/autoconfig/factory/StringListValue.java index 6369486..7a182f5 100644 --- a/src/main/java/info/loenwind/autoconfig/factory/StringListValue.java +++ b/src/main/java/info/loenwind/autoconfig/factory/StringListValue.java @@ -5,7 +5,7 @@ import javax.annotation.Nullable; -import net.minecraftforge.common.config.Property; +import info.loenwind.autoconfig.util.ConfigProperty; class StringListValue extends AbstractValue> { @@ -15,7 +15,7 @@ protected StringListValue(IValueFactory owner, String section, String keyname, L @Override protected @Nullable List makeValue() { - Property prop = owner.getConfig().get(section, keyname, defaultValue.toArray(new String[0])); + ConfigProperty prop = owner.getConfig().get(section, keyname, defaultValue.toArray(new String[0])); prop.setLanguageKey(keyname); prop.setValidationPattern(null); prop.setComment(getText() + " [default: " + defaultValue.toArray(new String[0]) + "]"); diff --git a/src/main/java/info/loenwind/autoconfig/factory/StringValue.java b/src/main/java/info/loenwind/autoconfig/factory/StringValue.java index b253c50..7da831e 100644 --- a/src/main/java/info/loenwind/autoconfig/factory/StringValue.java +++ b/src/main/java/info/loenwind/autoconfig/factory/StringValue.java @@ -1,8 +1,9 @@ package info.loenwind.autoconfig.factory; +import info.loenwind.autoconfig.util.ConfigProperty; + import javax.annotation.Nullable; -import net.minecraftforge.common.config.Property; class StringValue extends AbstractValue { @@ -12,7 +13,7 @@ protected StringValue(IValueFactory owner, String section, String keyname, Strin @Override protected @Nullable String makeValue() { - Property prop = owner.getConfig().get(section, keyname, defaultValue); + ConfigProperty prop = owner.getConfig().get(section, keyname, defaultValue); prop.setLanguageKey(keyname); prop.setValidationPattern(null); prop.setComment(getText() + " [default: " + defaultValue + "]"); diff --git a/src/main/java/info/loenwind/autoconfig/factory/ValueFactory.java b/src/main/java/info/loenwind/autoconfig/factory/ValueFactory.java index 641bf4f..116b404 100644 --- a/src/main/java/info/loenwind/autoconfig/factory/ValueFactory.java +++ b/src/main/java/info/loenwind/autoconfig/factory/ValueFactory.java @@ -7,7 +7,6 @@ import javax.annotation.Nullable; import info.loenwind.autoconfig.util.NullHelper; -import net.minecraftforge.common.config.Configuration; public class ValueFactory implements IRootFactory { diff --git a/src/main/java/info/loenwind/autoconfig/util/ConfigProperty.java b/src/main/java/info/loenwind/autoconfig/util/ConfigProperty.java new file mode 100644 index 0000000..7a7066f --- /dev/null +++ b/src/main/java/info/loenwind/autoconfig/util/ConfigProperty.java @@ -0,0 +1,1183 @@ +package info.loenwind.autoconfig.util; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.regex.Pattern; + +public class ConfigProperty +{ + public String getComment() + { + return comment; + } + + public void setComment(String comment) + { + this.comment = comment; + } + + public enum Type + { + STRING, + INTEGER, + BOOLEAN, + DOUBLE, + COLOR, + MOD_ID; + + public static Type tryParse(char id) + { + for (int x = 0; x < values().length; x++) + { + if (values()[x].getID() == id) + { + return values()[x]; + } + } + + return STRING; + } + + public char getID() + { + return name().charAt(0); + } + } + + private String name; + private String value; + private String defaultValue; + private String comment; + private String[] values; + private String[] defaultValues; + private String[] validValues; + private String[] validValuesDisplay; + private String langKey; + private String minValue; + private String maxValue; + /** If true, will have a slider attached automatically in configuration UI */ + private boolean hasSlidingControl; + + private boolean requiresWorldRestart = false; + private boolean showInGui = true; + private boolean requiresMcRestart = false; + private Pattern validationPattern; + private final boolean wasRead; + private final boolean isList; + private boolean isListLengthFixed = false; + private int maxListLength = -1; + private final Type type; + private boolean changed = false; + + public ConfigProperty(String name, String value, Type type) + { + this(name, value, type, false, new String[0], new String[0], name); + } + + public ConfigProperty(String name, String value, Type type, boolean read) + { + this(name, value, type, read, new String[0], new String[0], name); + } + + public ConfigProperty(String name, String value, Type type, String[] validValues) + { + this(name, value, type, false, validValues, new String[0], name); + } + + public ConfigProperty(String name, String value, Type type, String[] validValues, String[] validValuesDisplay) + { + this(name, value, type, false, validValues, validValuesDisplay, name); + } + + public ConfigProperty(String name, String value, Type type, String langKey) + { + this(name, value, type, false, new String[0], new String[0], langKey); + } + + public ConfigProperty(String name, String value, Type type, boolean read, String langKey) + { + this(name, value, type, read, new String[0], new String[0], langKey); + } + + public ConfigProperty(String name, String value, Type type, String[] validValues, String langKey) + { + this(name, value, type, false, validValues, new String[0], langKey); + } + + public ConfigProperty(String name, String value, Type type, String[] validValues, String[] validValuesDisplay, String langKey) + { + this(name, value, type, false, validValues, validValuesDisplay, langKey); + } + + ConfigProperty(String name, String value, Type type, boolean read, String[] validValues, String[] validValuesDisplay, String langKey) + { + setName(name); + this.value = value; + this.values = new String[0]; + this.type = type; + wasRead = read; + isList = false; + this.defaultValue = value; + this.defaultValues = new String[0]; + this.validValues = validValues; + this.validValuesDisplay = validValues; + this.isListLengthFixed = false; + this.maxListLength = -1; + this.minValue = String.valueOf(Integer.MIN_VALUE); + this.maxValue = String.valueOf(Integer.MAX_VALUE); + this.langKey = langKey; + this.setComment(""); + } + + public ConfigProperty(String name, String[] values, Type type) + { + this(name, values, type, false); + } + + ConfigProperty(String name, String[] values, Type type, boolean read) + { + this(name, values, type, read, new String[0], name); + } + + public ConfigProperty(String name, String[] values, Type type, String langKey) + { + this(name, values, type, false, langKey); + } + + ConfigProperty(String name, String[] values, Type type, boolean read, String langKey) + { + this(name, values, type, read, new String[0], langKey); + } + + ConfigProperty(String name, String[] values, Type type, boolean read, String[] validValues, String langKey) + { + this(name, values, type, read, validValues, new String[0], langKey); + } + + ConfigProperty(String name, String[] values, Type type, boolean read, String[] validValues, String[] validValuesDisplay, String langKey) + { + setName(name); + this.type = type; + this.values = Arrays.copyOf(values, values.length); + wasRead = read; + isList = true; + this.value = ""; + this.defaultValue = ""; + for (String s : values) + this.defaultValue += ", [" + s + "]"; + this.defaultValue = this.defaultValue.replaceFirst(", ", ""); + this.defaultValues = Arrays.copyOf(values, values.length); + this.validValues = validValues; + this.validValuesDisplay = validValues; + this.isListLengthFixed = false; + this.maxListLength = -1; + this.minValue = String.valueOf(Integer.MIN_VALUE); + this.maxValue = String.valueOf(Integer.MAX_VALUE); + this.langKey = langKey; + this.setComment(""); + } + + /** + * Returns whether or not this Property is defaulted. + * + * @return true if the current value(s) is(are) deeply equal to the default value(s) + */ + public boolean isDefault() + { + if (this.isBooleanList()) + { + if (values.length == defaultValues.length) + { + for (int i = 0; i < values.length; i++) + if (Boolean.parseBoolean(values[i]) != Boolean.parseBoolean(defaultValues[i])) + return false; + + return true; + } + else + return false; + } + + if (this.isIntList()) + { + if (values.length == defaultValues.length) + { + for (int i = 0; i < values.length; i++) + if (Integer.parseInt(values[i]) != Integer.parseInt(defaultValues[i])) + return false; + + return true; + } + else + return false; + } + + if (this.isDoubleList()) + { + if (values.length == defaultValues.length) + { + for (int i = 0; i < values.length; i++) + if (Double.parseDouble(values[i]) != Double.parseDouble(defaultValues[i])) + return false; + + return true; + } + else + return false; + } + + if (this.isList()) + { + if (values.length == defaultValues.length) + { + for (int i = 0; i < values.length; i++) + if (!values[i].equals(defaultValues[i])) + return false; + + return true; + } + else + return false; + } + + if (this.type == Type.BOOLEAN && this.isBooleanValue()) + return Boolean.parseBoolean(value) == Boolean.parseBoolean(defaultValue); + + if (this.type == Type.INTEGER && this.isIntValue()) + return Integer.parseInt(value) == Integer.parseInt(defaultValue); + + if (this.type == Type.DOUBLE && this.isDoubleValue()) + return Double.parseDouble(value) == Double.parseDouble(defaultValue); + + return value.equals(defaultValue); + } + + /** + * Sets the current value(s) of this Property to the default value(s). + */ + public ConfigProperty setToDefault() + { + this.value = this.defaultValue; + this.values = Arrays.copyOf(this.defaultValues, this.defaultValues.length); + return this; + } + + /** + * Gets the raw String default value of this Property. Check for isList() == false first. + * + * @return the default value String + */ + public String getDefault() + { + return defaultValue; + } + + /** + * Gets the raw String[] default values of this Property. Check for isList() == true first. + * + * @return the default values String[] + */ + public String[] getDefaults() + { + return Arrays.copyOf(this.defaultValues, this.defaultValues.length); + } + + /** + * Sets the flag for whether or not this Property can be edited while a world is running. Care should be taken to ensure + * that only properties that are truly dynamic can be changed from the in-game options menu. When set to false the Property will be + * editable from both the main menu Mods list config screen and the in-game Mod Options config screen. When set to true the Property + * will only be editable from the main menu Mods list config screen. + */ + public ConfigProperty setRequiresWorldRestart(boolean requiresWorldRestart) + { + this.requiresWorldRestart = requiresWorldRestart; + return this; + } + + /** + * Returns whether or not this Property is able to be edited while a world is running using the in-game Mod Options screen + * as well as the Mods list screen, or only from the Mods list screen. Setting this flag to true will disable editing of + * this property while a world is running. + */ + public boolean requiresWorldRestart() + { + return this.requiresWorldRestart; + } + + /** + * Sets whether or not this Property should be allowed to show on config GUIs. + * Defaults to true. + */ + public ConfigProperty setShowInGui(boolean showInGui) + { + this.showInGui = showInGui; + return this; + } + + /** + * Gets whether or not this Property should be allowed to show on config GUIs. + * Defaults to true unless set to false. + */ + public boolean showInGui() + { + return showInGui; + } + + /** + * Sets whether or not this Property requires Minecraft to be restarted when changed. + * Defaults to false. Setting this flag to true will also disable editing of + * this property while a world is running. + */ + public ConfigProperty setRequiresMcRestart(boolean requiresMcRestart) + { + this.requiresMcRestart = this.requiresWorldRestart = requiresMcRestart; + return this; + } + + /** + * Gets whether or not this Property requires Minecraft to be restarted when changed. + * Defaults to false unless set to true. + */ + public boolean requiresMcRestart() + { + return this.requiresMcRestart; + } + + /** + * Sets the maximum length of this list/array Property. Only important if isList() == true. If the current values array or default + * values array is longer than the new maximum it will be resized. If calling both this method and setIsListLengthFixed(true), this + * method should be called afterwards (but is not required). + */ + public ConfigProperty setMaxListLength(int max) + { + this.maxListLength = max; + if (this.maxListLength != -1) + { + if (values != null && values.length != maxListLength) + if (this.isListLengthFixed || values.length > maxListLength) + values = Arrays.copyOf(values, maxListLength); + + if (defaultValues != null && defaultValues.length != maxListLength) + if (this.isListLengthFixed || defaultValues.length > maxListLength) + defaultValues = Arrays.copyOf(defaultValues, maxListLength); + } + return this; + } + + /** + * Gets the maximum length of this list/array Property. Only important if isList() == true. + */ + public int getMaxListLength() + { + return this.maxListLength; + } + + /** + * Sets the flag for whether this list/array Property has a fixed length. Only important if isList() == true. If calling both this + * method and setMaxListLength(), this method should be called first (but is not required). + */ + public ConfigProperty setIsListLengthFixed(boolean isListLengthFixed) + { + this.isListLengthFixed = isListLengthFixed; + return this; + } + + /** + * Returns whether or not this list/array has a fixed length. Only important if isList() == true. + */ + public boolean isListLengthFixed() + { + return this.isListLengthFixed; + } + + + /** + * Sets a regex Pattern object used to validate user input for formatted String or String[] properties. + * + * @param validationPattern + */ + public ConfigProperty setValidationPattern(Pattern validationPattern) + { + this.validationPattern = validationPattern; + return this; + } + + /** + * Gets the Pattern object used to validate user input for this Property. + * + * @return the user input validation Pattern object, or null if none is set + */ + public Pattern getValidationPattern() + { + return this.validationPattern; + } + + /** + * Sets the localization language key for this Property so that the config GUI screens are nice and pretty <3. The string languageKey + + * ".tooltip" is used for tooltips when a user hovers the mouse over a GUI property label. + * + * @param langKey a string language key such as myawesomemod.config.myPropName + */ + public ConfigProperty setLanguageKey(String langKey) + { + this.langKey = langKey; + return this; + } + + /** + * Gets the language key string for this Property. + * + * @return the language key + */ + public String getLanguageKey() + { + return this.langKey; + } + + /** + * Sets the default string value of this Property. + * + * @param defaultValue a String value + */ + public ConfigProperty setDefaultValue(String defaultValue) + { + this.defaultValue = defaultValue; + return this; + } + + /** + * Sets the default String[] values of this Property. + * + * @param defaultValues an array of String values + */ + public ConfigProperty setDefaultValues(String[] defaultValues) + { + this.defaultValue = ""; + for (String s : defaultValues) + this.defaultValue += ", [" + s + "]"; + this.defaultValue = this.defaultValue.replaceFirst(", ", ""); + this.defaultValues = Arrays.copyOf(defaultValues, defaultValues.length); + return this; + } + + /** + * Sets the default int value of this Property. + * + * @param defaultValue an int value + */ + public ConfigProperty setDefaultValue(int defaultValue) + { + setDefaultValue(Integer.toString(defaultValue)); + return this; + } + + /** + * Sets the default int[] values of this Property. + * + * @param defaultValues an array of int values + */ + public ConfigProperty setDefaultValues(int[] defaultValues) + { + String[] temp = new String[defaultValues.length]; + for (int i = 0; i < defaultValues.length; i++) + temp[i] = Integer.toString(defaultValues[i]); + + setDefaultValues(temp); + return this; + } + + /** + * Sets the default double value of this Property. + * + * @param defaultValue a double value + */ + public ConfigProperty setDefaultValue(double defaultValue) + { + setDefaultValue(Double.toString(defaultValue)); + return this; + } + + /** + * Sets the default double[] values of this Property + * + * @param defaultValues an array of double values + */ + public ConfigProperty setDefaultValues(double[] defaultValues) + { + String[] temp = new String[defaultValues.length]; + for (int i = 0; i < defaultValues.length; i++) + temp[i] = Double.toString(defaultValues[i]); + + setDefaultValues(temp); + return this; + } + + /** + * Sets the default boolean value of this Property. + * + * @param defaultValue a boolean value + */ + public ConfigProperty setDefaultValue(boolean defaultValue) + { + setDefaultValue(Boolean.toString(defaultValue)); + return this; + } + + /** + * Sets the default boolean[] values of this Property. + * + * @param defaultValues an array of boolean values + */ + public ConfigProperty setDefaultValues(boolean[] defaultValues) + { + String[] temp = new String[defaultValues.length]; + for (int i = 0; i < defaultValues.length; i++) + temp[i] = Boolean.toString(defaultValues[i]); + + setDefaultValues(temp); + return this; + } + + /** + * Sets the minimum int value of this Property. + * + * @param minValue an int value + */ + public ConfigProperty setMinValue(int minValue) + { + this.minValue = Integer.toString(minValue); + return this; + } + + /** + * Sets the maximum int value of this Property. + * + * @param maxValue an int value + */ + public ConfigProperty setMaxValue(int maxValue) + { + this.maxValue = Integer.toString(maxValue); + return this; + } + + /** + * Sets the minimum double value of this Property. + * + * @param minValue a double value + */ + public ConfigProperty setMinValue(double minValue) + { + this.minValue = Double.toString(minValue); + return this; + } + + /** + * Sets the maximum double value of this Property. + * + * @param maxValue a double value + */ + public ConfigProperty setMaxValue(double maxValue) + { + this.maxValue = Double.toString(maxValue); + return this; + } + + /** + * Gets the minimum value. + * + * @return the minimum value bound + */ + public String getMinValue() + { + return minValue; + } + + /** + * Gets the maximum value. + * + * @return the maximum value bound + */ + public String getMaxValue() + { + return maxValue; + } + + /** + * Returns the value in this property as it's raw string. + * + * @return current value + */ + public String getString() + { + return value; + } + + /** + * Sets the array of valid values that this String Property can be set to. When an array of valid values is defined for a Property the + * GUI control for that property will be a value cycle button. + * + * @param validValues a String array of valid values + */ + public ConfigProperty setValidValues(String[] validValues) + { + this.validValues = validValues; + return this; + } + + /** + * Gets the array of valid values that this String Property can be set to, or null or empty if not defined. + * + * @return a String array of valid values + */ + public String[] getValidValues() + { + return this.validValues; + } + + + public ConfigProperty setValidValuesDisplay(String[] validValuesDisplay) + { + this.validValuesDisplay = validValuesDisplay; + return this; + } + + /** + * Gets the array of the config GUI display versions of the valid values that this String Property can be set to, or null or empty if not defined. + * + * @return a String array of the aliases of the valid values + */ + public String[] getValidValuesDisplay() + { + return this.validValuesDisplay; + } + + /** + * Returns the value in this property as an integer, + * if the value is not a valid integer, it will return the initially provided default. + * + * @return The value + */ + public int getInt() + { + return getInt(Integer.parseInt(defaultValue)); + } + + /** + * Returns the value in this property as an integer, + * if the value is not a valid integer, it will return the + * provided default. + * + * @param _default The default to provide if the current value is not a valid integer + * @return The value + */ + public int getInt(int _default) + { + try + { + return Integer.parseInt(value); + } + catch (NumberFormatException e) + { + return _default; + } + } + + /** + * Checks if the current value stored in this property can be converted to an integer. + * @return True if the type of the Property is an Integer + */ + public boolean isIntValue() + { + try + { + Integer.parseInt(value); + return true; + } + catch (NumberFormatException e) + { + return false; + } + } + + /** + * Returns the value in this property as a long, + * if the value is not a valid long, it will return the initially provided default. + * + * @return The value + */ + public long getLong() + { + return getLong(Long.parseLong(defaultValue)); + } + + /** + * Returns the value in this property as a long, + * if the value is not a valid long, it will return the + * provided default. + * + * @param _default The default to provide if the current value is not a validlong + * @return The value + */ + public long getLong(long _default) + { + try + { + return Long.parseLong(value); + } + catch (NumberFormatException e) + { + return _default; + } + } + + /** + * Checks if the current value stored in this property can be converted to a long. + * @return True if the type of the Property is an Long + */ + public boolean isLongValue() + { + try + { + Long.parseLong(value); + return true; + } + catch (NumberFormatException e) + { + return false; + } + } + + /** + * Returns the value in this property as a boolean, + * if the value is not a valid boolean, it will return the + * provided default. + * + * @param _default The default to provide + * @return The value as a boolean, or the default + */ + public boolean getBoolean(boolean _default) + { + if (isBooleanValue()) + { + return Boolean.parseBoolean(value); + } + else + { + return _default; + } + } + + /** + * Returns the value in this property as a boolean, if the value is not a valid boolean, it will return the provided default. + * + * @return The value as a boolean, or the default + */ + public boolean getBoolean() + { + if (isBooleanValue()) + { + return Boolean.parseBoolean(value); + } + else + { + return Boolean.parseBoolean(defaultValue); + } + } + + /** + * Checks if the current value held by this property is a valid boolean value. + * + * @return True if it is a boolean value + */ + public boolean isBooleanValue() + { + return ("true".equals(value.toLowerCase()) || "false".equals(value.toLowerCase())); + } + + /** + * Checks if the current value held by this property is a valid double value. + * @return True if the value can be converted to an double + */ + public boolean isDoubleValue() + { + try + { + Double.parseDouble(value); + return true; + } + catch (NumberFormatException e) + { + return false; + } + } + + /** + * Returns the value in this property as a double, + * if the value is not a valid double, it will return the + * provided default. + * + * @param _default The default to provide if the current value is not a valid double + * @return The value + */ + public double getDouble(double _default) + { + try + { + return Double.parseDouble(value); + } + catch (NumberFormatException e) + { + return _default; + } + } + + /** + * Returns the value in this property as a double, if the value is not a valid double, it will return the provided default. + * + * @return The value + */ + public double getDouble() + { + try + { + return Double.parseDouble(value); + } + catch (NumberFormatException e) + { + return Double.parseDouble(defaultValue); + } + } + + public String[] getStringList() + { + return values; + } + + /** + * Returns the integer value of all values that can + * be parsed in the list. + * + * @return Array of length 0 if none of the values could be parsed. + */ + public int[] getIntList() + { + ArrayList nums = new ArrayList(); + + for (String value : values) + { + try + { + nums.add(Integer.parseInt(value)); + } + catch (NumberFormatException e){} + } + + int[] primitives = new int[nums.size()]; + + for (int i = 0; i < nums.size(); i++) + { + primitives[i] = nums.get(i); + } + + return primitives; + } + + /** + * Checks if all of the current values stored in this property can be converted to an integer. + * @return True if the type of the Property is an Integer List + */ + public boolean isIntList() + { + if (isList && type == Type.INTEGER) + for (String value : values) + { + try + { + Integer.parseInt(value); + } + catch (NumberFormatException e) + { + return false; + } + } + return isList && type == Type.INTEGER; + } + + /** + * Returns the boolean value of all values that can + * be parsed in the list. + * + * @return Array of length 0 if none of the values could be parsed. + */ + public boolean[] getBooleanList() + { + ArrayList tmp = new ArrayList(); + for (String value : values) + { + try + { + tmp.add(Boolean.parseBoolean(value)); + } + catch (NumberFormatException e){} + } + + boolean[] primitives = new boolean[tmp.size()]; + + for (int i = 0; i < tmp.size(); i++) + { + primitives[i] = tmp.get(i); + } + + return primitives; + } + + /** + * Checks if all of current values stored in this property can be converted to a boolean. + * @return True if it is a boolean value + */ + public boolean isBooleanList() + { + if (isList && type == Type.BOOLEAN) + for (String value : values) + { + if (!"true".equalsIgnoreCase(value) && !"false".equalsIgnoreCase(value)) + { + return false; + } + } + + return isList && type == Type.BOOLEAN; + } + + /** + * Returns the double value of all values that can + * be parsed in the list. + * + * @return Array of length 0 if none of the values could be parsed. + */ + public double[] getDoubleList() + { + ArrayList tmp = new ArrayList(); + for (String value : values) + { + try + { + tmp.add(Double.parseDouble(value)); + } + catch (NumberFormatException e) {} + } + + double[] primitives = new double[tmp.size()]; + + for (int i = 0; i < tmp.size(); i++) + { + primitives[i] = tmp.get(i); + } + + return primitives; + } + + /** + * Checks if all of the current values stored in this property can be converted to a double. + * @return True if the type of the Property is a double List + */ + public boolean isDoubleList() + { + if (isList && type == Type.DOUBLE) + for (String value : values) + { + try + { + Double.parseDouble(value); + } + catch (NumberFormatException e) + { + return false; + } + } + + return isList && type == Type.DOUBLE; + } + + /** + * Gets the name/key for this Property. + * + * @return the Property name + */ + public String getName() + { + return name; + } + + /** + * Sets the name/key for this Property. + * + * @param name a name + */ + public void setName(String name) + { + this.name = name; + } + + /** + * Determines if this config value was just created, or if it was read from the config file. + * This is useful for mods who auto-assign their blocks to determine if the ID returned is + * a configured one, or a automatically generated one. + * + * @return True if this property was loaded from the config file with a value + */ + public boolean wasRead() + { + return wasRead; + } + + /** + * Gets the Property.Type enum value for this Property. + * + * @return the Property's type + */ + public Type getType() + { + return type; + } + + /** + * Returns whether or not this Property is a list/array. + * + * @return true if this Property is a list/array, false otherwise + */ + public boolean isList() + { + return isList; + } + + /** + * Gets the changed status of this Property. + * + * @return true if this Property has changed, false otherwise + */ + public boolean hasChanged(){ return changed; } + void resetChangedState(){ changed = false; } + + /** + * Sets the value of this Property to the provided String value. + */ + public ConfigProperty setValue(String value) + { + this.value = value; + changed = true; + return this; + } + + public void set(String value) + { + this.setValue(value); + } + + /** + * Sets the values of this Property to the provided String[] values. + */ + public ConfigProperty setValues(String[] values) + { + this.values = Arrays.copyOf(values, values.length); + changed = true; + return this; + } + + public void set(String[] values) + { + this.setValues(values); + } + + /** + * Sets the value of this Property to the provided int value. + */ + public ConfigProperty setValue(int value) + { + setValue(Integer.toString(value)); + return this; + } + + /** + * Sets the value of this Property to the provided boolean value. + */ + public ConfigProperty setValue(boolean value) + { + setValue(Boolean.toString(value)); + return this; + } + + /** + * Sets the value of this Property to the provided double value. + */ + public ConfigProperty setValue(double value) + { + setValue(Double.toString(value)); + return this; + } + + /** + * Sets the values of this Property to the provided boolean[] values. + */ + public ConfigProperty setValues(boolean[] values) + { + this.values = new String[values.length]; + for (int i = 0; i < values.length; i++) + this.values[i] = String.valueOf(values[i]); + changed = true; + return this; + } + + public void set(boolean[] values) + { + this.setValues(values); + } + + /** + * Sets the values of this Property to the provided int[] values. + */ + public ConfigProperty setValues(int[] values) + { + this.values = new String[values.length]; + for (int i = 0; i < values.length; i++) + this.values[i] = String.valueOf(values[i]); + changed = true; + return this; + } + + public void set(int[] values) + { + this.setValues(values); + } + + /** + * Sets the values of this Property to the provided double[] values. + */ + public ConfigProperty setValues(double[] values) + { + this.values = new String[values.length]; + for (int i = 0; i < values.length; i++) + this.values[i] = String.valueOf(values[i]); + changed = true; + return this; + } + + public void set(double[] values) + { + this.setValues(values); + } + public void set(int value){ set(Integer.toString(value)); } + public void set(long value){ set(Long.toString(value)); } + public void set(boolean value){ set(Boolean.toString(value)); } + public void set(double value){ set(Double.toString(value)); } + + public boolean hasSlidingControl() + { + return hasSlidingControl; + } + + public void setHasSlidingControl(boolean b) + { + hasSlidingControl=b; + } +} \ No newline at end of file diff --git a/src/main/java/info/loenwind/autoconfig/util/Lang.java b/src/main/java/info/loenwind/autoconfig/util/Lang.java index 689212c..ae7937b 100644 --- a/src/main/java/info/loenwind/autoconfig/util/Lang.java +++ b/src/main/java/info/loenwind/autoconfig/util/Lang.java @@ -1,9 +1,8 @@ package info.loenwind.autoconfig.util; +import net.minecraft.client.resources.I18n; import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.TextComponentString; -import net.minecraft.util.text.TextComponentTranslation; -import net.minecraft.util.text.translation.I18n; +import net.minecraft.util.text.TranslationTextComponent; public enum Lang { NETWORK_BAD_CONFIG("autoconfig.network.bad_config", @@ -24,17 +23,17 @@ private Lang(String key, String fallback) { } public String get() { - return I18n.canTranslate(key) ? I18n.translateToLocal(key) : fallback; + return I18n.hasKey(key) ? I18n.format(key) : fallback; } @SuppressWarnings("null") public String get(Object... params) { - return I18n.canTranslate(key) ? I18n.translateToLocalFormatted(key, params) : String.format(fallback, params); + return I18n.hasKey(key) ? I18n.format(key, params) : String.format(fallback, params); } @SuppressWarnings("null") public ITextComponent toChat(Object... params) { - return I18n.canTranslate(key) ? new TextComponentTranslation(key, params) : new TextComponentString(String.format(fallback, params)); + return I18n.hasKey(key) ? new TranslationTextComponent(key, params) : new TranslationTextComponent(String.format(fallback, params)); } } From bbb1f59678c1320e5dd29e699b8d22870d9fec3d Mon Sep 17 00:00:00 2001 From: HypherionMC Date: Thu, 19 Nov 2020 20:04:32 +0200 Subject: [PATCH 2/6] Port Network Packets --- .../loenwind/autoconfig/factory/Network.java | 31 +++++++---- .../autoconfig/factory/PacketConfigSync.java | 52 ++++++++----------- 2 files changed, 45 insertions(+), 38 deletions(-) diff --git a/src/main/java/info/loenwind/autoconfig/factory/Network.java b/src/main/java/info/loenwind/autoconfig/factory/Network.java index 3187321..7ec8f16 100644 --- a/src/main/java/info/loenwind/autoconfig/factory/Network.java +++ b/src/main/java/info/loenwind/autoconfig/factory/Network.java @@ -1,21 +1,34 @@ package info.loenwind.autoconfig.factory; -import info.loenwind.autoconfig.factory.PacketConfigSync.Handler; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraftforge.fml.common.network.simpleimpl.IMessage; -import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper; -import net.minecraftforge.fml.relauncher.Side; +import net.minecraft.entity.player.ServerPlayerEntity; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fml.network.NetworkDirection; +import net.minecraftforge.fml.network.NetworkRegistry; +import net.minecraftforge.fml.network.simple.SimpleChannel; class Network { - private static final SimpleNetworkWrapper INSTANCE = new SimpleNetworkWrapper("autoconfig"); + private static final String PROTOCOL_VERSION = "1"; + private static int ID = 0; + private static SimpleChannel INSTANCE; - public static void sendTo(IMessage message, EntityPlayerMP player) { - INSTANCE.sendTo(message, player); + public static void sendTo(Object packet, ServerPlayerEntity player) { + INSTANCE.sendTo(packet, player.connection.netManager, NetworkDirection.PLAY_TO_CLIENT); } public static void create() { - INSTANCE.registerMessage(Handler.class, PacketConfigSync.class, 0, Side.CLIENT); + INSTANCE = NetworkRegistry.newSimpleChannel( + new ResourceLocation("autoconfig", "confighandler"), + () -> PROTOCOL_VERSION, + PROTOCOL_VERSION::equals, + PROTOCOL_VERSION::equals + ); + + INSTANCE.messageBuilder(PacketConfigSync.class, ID++) + .encoder(PacketConfigSync::toBytes) + .decoder(PacketConfigSync::new) + .consumer(PacketConfigSync::handle) + .add(); } } diff --git a/src/main/java/info/loenwind/autoconfig/factory/PacketConfigSync.java b/src/main/java/info/loenwind/autoconfig/factory/PacketConfigSync.java index 052c5e6..6faae96 100644 --- a/src/main/java/info/loenwind/autoconfig/factory/PacketConfigSync.java +++ b/src/main/java/info/loenwind/autoconfig/factory/PacketConfigSync.java @@ -4,12 +4,12 @@ import io.netty.buffer.ByteBuf; import net.minecraft.client.Minecraft; -import net.minecraftforge.fml.common.network.ByteBufUtils; -import net.minecraftforge.fml.common.network.simpleimpl.IMessage; -import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; -import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; +import net.minecraft.network.PacketBuffer; +import net.minecraftforge.fml.network.NetworkEvent; -public class PacketConfigSync implements IMessage { +import java.util.function.Supplier; + +public class PacketConfigSync { protected @Nullable IValueFactory factory; protected @Nullable String modid, section; @@ -19,40 +19,34 @@ public PacketConfigSync() { this.factory = null; } + public PacketConfigSync(@Nullable PacketBuffer buf) { + modid = buf.readString(); + section = buf.readString(); + ByteBufAdapterRegistry.loadMapping(buf); + bufferCopy = buf.copy(); + } + PacketConfigSync(IValueFactory factory) { this.factory = factory; } - @SuppressWarnings("null") - @Override - public void toBytes(@Nullable ByteBuf buf) { - ByteBufUtils.writeUTF8String(buf, factory.getModid()); - ByteBufUtils.writeUTF8String(buf, factory.getSection()); + public void toBytes(@Nullable PacketBuffer buf) { + buf.writeString(factory.getModid()); + buf.writeString(factory.getSection()); ByteBufAdapterRegistry.saveMapping(buf); factory.save(buf); } - @SuppressWarnings("null") - @Override - public void fromBytes(@Nullable ByteBuf buf) { - modid = ByteBufUtils.readUTF8String(buf); - section = ByteBufUtils.readUTF8String(buf); - ByteBufAdapterRegistry.loadMapping(buf); - bufferCopy = buf.copy(); - } - public static class Handler implements IMessageHandler { - @SuppressWarnings("null") - @Override - public IMessage onMessage(@Nullable PacketConfigSync message, @Nullable MessageContext ctx) { - if (!Minecraft.getMinecraft().isIntegratedServerRunning()) { - FactoryManager.read(message.modid, message.section, message.bufferCopy); - } - if (message.bufferCopy != null) { - message.bufferCopy.release(); - } - return null; + public boolean handle(Supplier contextSupplier) { + if (!Minecraft.getInstance().isIntegratedServerRunning()) { + FactoryManager.read(modid, section, bufferCopy); + } + if (bufferCopy != null) { + bufferCopy.release(); + return true; } + return false; } } From 3fff95d393e2ddd115e9e438e7183edc58054dcb Mon Sep 17 00:00:00 2001 From: HypherionMC Date: Thu, 19 Nov 2020 20:37:40 +0200 Subject: [PATCH 3/6] More porting. Also added a Dummy Config storage --- .../loenwind/autoconfig/ConfigHandler.java | 16 ++++++---- .../autoconfig/factory/FactoryManager.java | 5 +-- .../loenwind/autoconfig/factory/IFactory.java | 2 ++ .../autoconfig/factory/IRootFactory.java | 2 ++ .../autoconfig/factory/SlaveFactory.java | 1 + .../autoconfig/factory/ValueFactory.java | 1 + .../autoconfig/util/Configuration.java | 31 +++++++++++++++++++ 7 files changed, 50 insertions(+), 8 deletions(-) create mode 100644 src/main/java/info/loenwind/autoconfig/util/Configuration.java diff --git a/src/main/java/info/loenwind/autoconfig/ConfigHandler.java b/src/main/java/info/loenwind/autoconfig/ConfigHandler.java index 505e74b..03cd247 100644 --- a/src/main/java/info/loenwind/autoconfig/ConfigHandler.java +++ b/src/main/java/info/loenwind/autoconfig/ConfigHandler.java @@ -6,10 +6,14 @@ import info.loenwind.autoconfig.factory.ByteBufAdapters; import info.loenwind.autoconfig.factory.IRootFactory; +import info.loenwind.autoconfig.util.Configuration; import info.loenwind.autoconfig.util.Log; import info.loenwind.autoconfig.util.NullHelper; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.config.ModConfig; +import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; +import net.minecraftforge.fml.loading.FMLPaths; public class ConfigHandler { @@ -18,18 +22,18 @@ public class ConfigHandler { protected final IRootFactory factory; - public ConfigHandler(FMLPreInitializationEvent event, IRootFactory factory) { + public ConfigHandler(FMLCommonSetupEvent event, IRootFactory factory) { this(event, factory, null); } - public ConfigHandler(FMLPreInitializationEvent event, IRootFactory factory, @Nullable String folder) { + public ConfigHandler(FMLCommonSetupEvent event, IRootFactory factory, @Nullable String folder) { this.factory = factory; ByteBufAdapters.NONE.getClass(); // trigger system init MinecraftForge.EVENT_BUS.register(this); if (folder != null) { - configDirectory = new File(event.getModConfigurationDirectory(), folder); + configDirectory = new File(FMLPaths.CONFIGDIR.get().toFile(), folder); } else { - configDirectory = NullHelper.notnullF(event.getModConfigurationDirectory(), "FMLPreInitializationEvent has no config folder"); + configDirectory = NullHelper.notnullF(FMLPaths.CONFIGDIR.get().toFile(), "FMLCommonSetupEvent has no config folder"); } if (!configDirectory.exists()) { configDirectory.mkdir(); @@ -54,8 +58,8 @@ public void syncConfig() { } @SubscribeEvent - public void onConfigChanged(OnConfigChangedEvent event) { - if (event.getModID().equals(factory.getModid())) { + public void onConfigChanged(ModConfig.ModConfigEvent event) { + if (event.getConfig().getModId().equals(factory.getModid())) { Log.info("Updating config..."); syncConfig(); } diff --git a/src/main/java/info/loenwind/autoconfig/factory/FactoryManager.java b/src/main/java/info/loenwind/autoconfig/factory/FactoryManager.java index 96c24fb..7543020 100644 --- a/src/main/java/info/loenwind/autoconfig/factory/FactoryManager.java +++ b/src/main/java/info/loenwind/autoconfig/factory/FactoryManager.java @@ -7,6 +7,7 @@ import info.loenwind.autoconfig.util.NullHelper; import io.netty.buffer.ByteBuf; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.player.PlayerEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; @@ -49,14 +50,14 @@ static void registerFactory(IValueFactory factory) { public static void onPlayerLoggon(final PlayerEvent.PlayerLoggedInEvent evt) { for (IValueFactory factory : factories.values()) { if (factory.needsSyncing()) { - Network.sendTo(new PacketConfigSync(factory), (PlayerEntity) NullHelper.notnullF(evt.getPlayer(), "PlayerLoggedInEvent without player")); + Network.sendTo(new PacketConfigSync(factory), (ServerPlayerEntity) NullHelper.notnullF(evt.getPlayer(), "PlayerLoggedInEvent without player")); Log.debug("Sent config to player " + evt.getPlayer().getDisplayName() + " for " + factory.getModid() + " (" + factory.getSection() + ")"); } } } @SubscribeEvent - public static void onPlayerLogout(final ClientDisconnectionFromServerEvent event) { + public static void onPlayerLogout(final PlayerEvent.PlayerLoggedOutEvent event) { for (IValueFactory factory : factories.values()) { factory.endServerOverride(); Log.debug("Removed server config override for " + factory.getModid() + " (" + factory.getSection() + ")"); diff --git a/src/main/java/info/loenwind/autoconfig/factory/IFactory.java b/src/main/java/info/loenwind/autoconfig/factory/IFactory.java index a87a1d5..f839173 100644 --- a/src/main/java/info/loenwind/autoconfig/factory/IFactory.java +++ b/src/main/java/info/loenwind/autoconfig/factory/IFactory.java @@ -1,5 +1,7 @@ package info.loenwind.autoconfig.factory; +import info.loenwind.autoconfig.util.Configuration; + public interface IFactory { IValueFactory section(String section); diff --git a/src/main/java/info/loenwind/autoconfig/factory/IRootFactory.java b/src/main/java/info/loenwind/autoconfig/factory/IRootFactory.java index 0afd52a..87cbb4d 100644 --- a/src/main/java/info/loenwind/autoconfig/factory/IRootFactory.java +++ b/src/main/java/info/loenwind/autoconfig/factory/IRootFactory.java @@ -1,6 +1,8 @@ package info.loenwind.autoconfig.factory; +import info.loenwind.autoconfig.util.Configuration; + public interface IRootFactory extends IFactory { void setConfig(Configuration config); diff --git a/src/main/java/info/loenwind/autoconfig/factory/SlaveFactory.java b/src/main/java/info/loenwind/autoconfig/factory/SlaveFactory.java index f3708f1..0c27833 100644 --- a/src/main/java/info/loenwind/autoconfig/factory/SlaveFactory.java +++ b/src/main/java/info/loenwind/autoconfig/factory/SlaveFactory.java @@ -8,6 +8,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; +import info.loenwind.autoconfig.util.Configuration; import io.netty.buffer.ByteBuf; import net.minecraft.fluid.Fluid; diff --git a/src/main/java/info/loenwind/autoconfig/factory/ValueFactory.java b/src/main/java/info/loenwind/autoconfig/factory/ValueFactory.java index 116b404..d916d11 100644 --- a/src/main/java/info/loenwind/autoconfig/factory/ValueFactory.java +++ b/src/main/java/info/loenwind/autoconfig/factory/ValueFactory.java @@ -6,6 +6,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; +import info.loenwind.autoconfig.util.Configuration; import info.loenwind.autoconfig.util.NullHelper; public class ValueFactory implements IRootFactory { diff --git a/src/main/java/info/loenwind/autoconfig/util/Configuration.java b/src/main/java/info/loenwind/autoconfig/util/Configuration.java new file mode 100644 index 0000000..26afb00 --- /dev/null +++ b/src/main/java/info/loenwind/autoconfig/util/Configuration.java @@ -0,0 +1,31 @@ +package info.loenwind.autoconfig.util; + +import java.io.File; + +public class Configuration { + + //TODO Dummy Config handler. Needs to be replaced with actual storage system + + public Configuration(File configFile) { + + } + + public boolean hasChanged() { + return false; + } + + + public void save() { + + } + + public ConfigProperty get(String section, String keyname, String defaultValue) { + + return new ConfigProperty("", "", ConfigProperty.Type.BOOLEAN); + } + + public ConfigProperty get(String section, String keyname, String[] defaultValue) { + + return new ConfigProperty("", "", ConfigProperty.Type.BOOLEAN); + } +} From 9746fd8656cccc0b10bc794833a136de9b6fd802 Mon Sep 17 00:00:00 2001 From: HypherionMC Date: Thu, 19 Nov 2020 21:30:31 +0200 Subject: [PATCH 4/6] Some more porting and a successful build --- .../factory/ByteBufAdapterRegistry.java | 9 +++++---- .../autoconfig/factory/ByteBufAdapters.java | 10 ++++++---- .../autoconfig/factory/FluidValue.java | 15 +++++++++++---- .../autoconfig/factory/IValueFactory.java | 1 + .../autoconfig/gui/ConfigElementCategory.java | 15 +++------------ .../autoconfig/gui/ConfigElementProperty.java | 15 ++++----------- .../loenwind/autoconfig/gui/ConfigFactory.java | 17 +++-------------- .../autoconfig/util/Configuration.java | 18 ++++++++++++++++-- 8 files changed, 49 insertions(+), 51 deletions(-) diff --git a/src/main/java/info/loenwind/autoconfig/factory/ByteBufAdapterRegistry.java b/src/main/java/info/loenwind/autoconfig/factory/ByteBufAdapterRegistry.java index 8bdf4ea..5bf2fb2 100644 --- a/src/main/java/info/loenwind/autoconfig/factory/ByteBufAdapterRegistry.java +++ b/src/main/java/info/loenwind/autoconfig/factory/ByteBufAdapterRegistry.java @@ -7,7 +7,8 @@ import info.loenwind.autoconfig.util.NullHelper; import io.netty.buffer.ByteBuf; -import net.minecraftforge.fml.common.network.ByteBufUtils; +import io.netty.buffer.ByteBufUtil; +import net.minecraft.network.PacketBuffer; public final class ByteBufAdapterRegistry { @@ -31,13 +32,13 @@ public static void saveMapping(ByteBuf buf) { synchronized (NAME2ID) { buf.writeByte(ID2ADAPTER.size()); for (IByteBufAdapter adapter : ID2ADAPTER) { - ByteBufUtils.writeUTF8String(buf, adapter.getName()); + ByteBufUtil.writeUtf8(buf, adapter.getName()); } } } // side-only: client - public static void loadMapping(ByteBuf buf) { + public static void loadMapping(PacketBuffer buf) { synchronized (NAME2ID) { int count = buf.readByte(); if (count != ID2ADAPTER.size()) { @@ -45,7 +46,7 @@ public static void loadMapping(ByteBuf buf) { } List> synced = new ArrayList<>(); for (int i = 0; i < count; i++) { - String name = ByteBufUtils.readUTF8String(buf); + String name = buf.readString(); Integer oldID = NAME2ID.get(name); if (oldID == null) { throw new RuntimeException("Server and client ByteBufAdapter lists are out of sync. Server has " + name + ", client doesn't know that one"); diff --git a/src/main/java/info/loenwind/autoconfig/factory/ByteBufAdapters.java b/src/main/java/info/loenwind/autoconfig/factory/ByteBufAdapters.java index 52607af..3569fe7 100644 --- a/src/main/java/info/loenwind/autoconfig/factory/ByteBufAdapters.java +++ b/src/main/java/info/loenwind/autoconfig/factory/ByteBufAdapters.java @@ -10,8 +10,9 @@ import info.loenwind.autoconfig.util.NullHelper; import io.netty.buffer.ByteBuf; import net.minecraft.fluid.Fluid; -import net.minecraftforge.fluids.Fluid; -import net.minecraftforge.fluids.FluidRegistry; +import net.minecraft.fluid.Fluids; +import net.minecraft.network.PacketBuffer; +import net.minecraft.util.ResourceLocation; import net.minecraftforge.registries.ForgeRegistries; public class ByteBufAdapters { @@ -253,7 +254,7 @@ public String getName() { @Override public void saveValue(ByteBuf buf, @Nonnull Fluid value) { - final byte[] vbytes = NullHelper.first(ForgeRegistries.FLUIDS.getKey(value), "").getBytes(Charset.forName("UTF-8")); + final byte[] vbytes = NullHelper.first(value.getRegistryName().toString(), "").getBytes(Charset.forName("UTF-8")); if (vbytes.length > 0x7F) { throw new RuntimeException("Fluid name too long"); } @@ -266,7 +267,8 @@ public void saveValue(ByteBuf buf, @Nonnull Fluid value) { final int len = buf.readByte(); final byte[] bytes = new byte[len]; buf.readBytes(bytes, 0, len); - return FluidRegistry.getFluid(new String(bytes, Charset.forName("UTF-8"))); + return ForgeRegistries.FLUIDS.getValue(ResourceLocation.tryCreate(new String(bytes, Charset.forName("UTF-8")))); + //return FluidRegistry.getFluid(new String(bytes, Charset.forName("UTF-8"))); } @Override diff --git a/src/main/java/info/loenwind/autoconfig/factory/FluidValue.java b/src/main/java/info/loenwind/autoconfig/factory/FluidValue.java index 96e65ec..31885b2 100644 --- a/src/main/java/info/loenwind/autoconfig/factory/FluidValue.java +++ b/src/main/java/info/loenwind/autoconfig/factory/FluidValue.java @@ -8,11 +8,18 @@ import info.loenwind.autoconfig.util.ConfigProperty; import info.loenwind.autoconfig.util.NullHelper; import net.minecraft.fluid.Fluid; +import net.minecraft.fluid.Fluids; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fml.ModContainer; +import net.minecraftforge.fml.ModLoader; +import net.minecraftforge.fml.ModLoadingContext; +import net.minecraftforge.fml.ModLoadingStage; import net.minecraftforge.fml.loading.FMLLoader; +import net.minecraftforge.registries.ForgeRegistries; class FluidValue extends AbstractValue { - private final static Fluid defaultFluidPlaceholder = new Fluid("", null, null); + private final static Fluid defaultFluidPlaceholder = Fluids.EMPTY; private final String defaultValueName; private @Nullable Fluid defaultFluid = null; @@ -26,18 +33,18 @@ protected FluidValue(IValueFactory owner, String section, String keyname, String @Override public Fluid get() { final String valueInConfig = getString(); // make sure the config value is registered with the config object - if (!FMLLoader.hasReachedState(LoaderState.INITIALIZATION)) { + if (ModLoadingContext.get().getActiveContainer().getCurrentState() != ModLoadingStage.CONSTRUCT) { return defaultValue; } if (defaultFluid == null) { - defaultFluid = FluidRegistry.getFluid(defaultValueName); + defaultFluid = ForgeRegistries.FLUIDS.getValue(ResourceLocation.tryCreate(defaultValueName)); } if (value == null || valueGeneration != owner.getGeneration()) { final Map serverConfig = owner.getServerConfig(); if (serverConfig != null && serverConfig.containsKey(keyname)) { value = (Fluid) serverConfig.get(keyname); } else { - value = FluidRegistry.getFluid(valueInConfig); + value = ForgeRegistries.FLUIDS.getValue(ResourceLocation.tryCreate(valueInConfig)); if (!owner.isInInit() && owner.getConfig().hasChanged()) { owner.getConfig().save(); } diff --git a/src/main/java/info/loenwind/autoconfig/factory/IValueFactory.java b/src/main/java/info/loenwind/autoconfig/factory/IValueFactory.java index 48b3c6a..9327634 100644 --- a/src/main/java/info/loenwind/autoconfig/factory/IValueFactory.java +++ b/src/main/java/info/loenwind/autoconfig/factory/IValueFactory.java @@ -8,6 +8,7 @@ import io.netty.buffer.ByteBuf; import net.minecraft.fluid.Fluid; + public interface IValueFactory extends IFactory { IValue make(String keyname, int defaultValue, String text); diff --git a/src/main/java/info/loenwind/autoconfig/gui/ConfigElementCategory.java b/src/main/java/info/loenwind/autoconfig/gui/ConfigElementCategory.java index a2f4be5..8424af5 100644 --- a/src/main/java/info/loenwind/autoconfig/gui/ConfigElementCategory.java +++ b/src/main/java/info/loenwind/autoconfig/gui/ConfigElementCategory.java @@ -6,17 +6,8 @@ import javax.annotation.Nullable; -import net.minecraftforge.common.config.ConfigCategory; -import net.minecraftforge.common.config.ConfigElement; -import net.minecraftforge.common.config.Property; -import net.minecraftforge.fml.client.config.ConfigGuiType; -import net.minecraftforge.fml.client.config.GuiConfigEntries.IConfigEntry; -import net.minecraftforge.fml.client.config.GuiEditArrayEntries.IArrayEntry; -import net.minecraftforge.fml.client.config.IConfigElement; - -/** - ** Forge's {@link ConfigElement} is written in a way to prevent sub-classing, so we had to copy it. - **/ +//TODO Config GUI +/* public class ConfigElementCategory implements IConfigElement { private ConfigCategory category; @@ -185,4 +176,4 @@ public void set(@Nullable Object[] aVal) { return null; } -} \ No newline at end of file +}*/ \ No newline at end of file diff --git a/src/main/java/info/loenwind/autoconfig/gui/ConfigElementProperty.java b/src/main/java/info/loenwind/autoconfig/gui/ConfigElementProperty.java index 40b309e..b0d2e44 100644 --- a/src/main/java/info/loenwind/autoconfig/gui/ConfigElementProperty.java +++ b/src/main/java/info/loenwind/autoconfig/gui/ConfigElementProperty.java @@ -8,16 +8,9 @@ import info.loenwind.autoconfig.factory.FactoryManager; import info.loenwind.autoconfig.util.Lang; import info.loenwind.autoconfig.util.NullHelper; -import net.minecraftforge.common.config.ConfigElement; -import net.minecraftforge.common.config.Property; -import net.minecraftforge.fml.client.config.ConfigGuiType; -import net.minecraftforge.fml.client.config.GuiConfigEntries.IConfigEntry; -import net.minecraftforge.fml.client.config.GuiEditArrayEntries.IArrayEntry; -import net.minecraftforge.fml.client.config.IConfigElement; - -/** - ** Forge's {@link ConfigElement} is written in a way to prevent sub-classing, so we had to copy it. - **/ + +//TODO Config GUI +/* public class ConfigElementProperty implements IConfigElement { private Property prop; @@ -270,4 +263,4 @@ public void set(@Nullable Object[] aVal) { return prop.getMaxValue(); } -} \ No newline at end of file +}*/ \ No newline at end of file diff --git a/src/main/java/info/loenwind/autoconfig/gui/ConfigFactory.java b/src/main/java/info/loenwind/autoconfig/gui/ConfigFactory.java index dc8eedd..a7f0dee 100644 --- a/src/main/java/info/loenwind/autoconfig/gui/ConfigFactory.java +++ b/src/main/java/info/loenwind/autoconfig/gui/ConfigFactory.java @@ -2,24 +2,13 @@ import java.util.ArrayList; import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - import javax.annotation.Nullable; import info.loenwind.autoconfig.factory.IRootFactory; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiScreen; -import net.minecraftforge.common.config.ConfigCategory; -import net.minecraftforge.common.config.Configuration; -import net.minecraftforge.fml.client.IModGuiFactory; -import net.minecraftforge.fml.client.config.DummyConfigElement.DummyCategoryElement; -import net.minecraftforge.fml.client.config.GuiConfig; -import net.minecraftforge.fml.client.config.IConfigElement; -public abstract class ConfigFactory implements IModGuiFactory { +//TODO Config GUI +/*public abstract class ConfigFactory implements IModGuiFactory { @Override public void initialize(@Nullable Minecraft minecraftInstance) { @@ -95,4 +84,4 @@ protected List getConfigElements(GuiScreen parent) { return result; } -} +}*/ diff --git a/src/main/java/info/loenwind/autoconfig/util/Configuration.java b/src/main/java/info/loenwind/autoconfig/util/Configuration.java index 26afb00..b09be9b 100644 --- a/src/main/java/info/loenwind/autoconfig/util/Configuration.java +++ b/src/main/java/info/loenwind/autoconfig/util/Configuration.java @@ -20,12 +20,26 @@ public void save() { } public ConfigProperty get(String section, String keyname, String defaultValue) { - - return new ConfigProperty("", "", ConfigProperty.Type.BOOLEAN); + return new ConfigProperty("", "", ConfigProperty.Type.STRING); } public ConfigProperty get(String section, String keyname, String[] defaultValue) { + return new ConfigProperty("", "", ConfigProperty.Type.STRING); + } + public ConfigProperty get(String section, String keyname, Boolean defaultValue) { return new ConfigProperty("", "", ConfigProperty.Type.BOOLEAN); } + + public ConfigProperty get(String section, String keyname, Double defaultValue, String comment) { + return new ConfigProperty("", "", ConfigProperty.Type.DOUBLE); + } + + public ConfigProperty get(String section, String keyname, double defaultValue) { + return new ConfigProperty("", "", ConfigProperty.Type.DOUBLE); + } + + public ConfigProperty get(String section, String keyname, int[] defaultValue) { + return new ConfigProperty("", "", ConfigProperty.Type.INTEGER); + } } From d6a8af547a919dd9edee6ff7665cd40ae2566072 Mon Sep 17 00:00:00 2001 From: HypherionMC Date: Thu, 19 Nov 2020 23:09:10 +0200 Subject: [PATCH 5/6] Add Temporary maven upload --- build.gradle | 9 +++++++++ gradle.properties | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/build.gradle b/build.gradle index 13d9505..c0bd167 100644 --- a/build.gradle +++ b/build.gradle @@ -171,6 +171,15 @@ publishing { } else { maven { url maven2_url } } + } + if (project.hasProperty('use_hypherion') && project.use_hypherion) { + maven { + url hypherion_mavenURL + credentials { + username System.getenv('MAVEN_USER') + password System.getenv('MAVEN_PASS') + } + } } else { mavenLocal() } diff --git a/gradle.properties b/gradle.properties index 6718526..18e5fc3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,3 +8,7 @@ mod_version=1.0 # Not made yet, does it need to be? projectId=999999 + +# Hypherion's Maven Stuff +use_hypherion=true +hypherion_mavenURL=http://35.193.236.134:8080/repository/hypmaven/ From c9a45a412492687b9b12898b0dab487995c1b037 Mon Sep 17 00:00:00 2001 From: Adriaan Date: Fri, 5 Mar 2021 13:55:37 +0200 Subject: [PATCH 6/6] Update HypherionMC Maven URL --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 18e5fc3..e9389a6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,4 +11,4 @@ projectId=999999 # Hypherion's Maven Stuff use_hypherion=true -hypherion_mavenURL=http://35.193.236.134:8080/repository/hypmaven/ +hypherion_mavenURL=https://maven.hypherionmc.me