Skip to content

Commit

Permalink
fix: inline value during compile rather than at runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
Sychic committed May 2, 2024
1 parent d605370 commit dda7481
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 25 deletions.
14 changes: 13 additions & 1 deletion mod/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import net.fabricmc.loom.task.RemapJarTask
import org.apache.tools.ant.filters.ReplaceTokens
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.security.MessageDigest

Expand Down Expand Up @@ -239,8 +240,19 @@ tasks {
isPreserveFileTimestamps = false
isReproducibleFileOrder = true
}
withType<JavaCompile> {
register<Sync>("processSource") {
from(sourceSets.main.get().java)
inputs.property("version", rootProject.version)
filter<ReplaceTokens>(
"tokens" to mapOf(
"version" to version
)
)
into("${layout.buildDirectory.get()}/src")
}
compileJava {
options.encoding = "UTF-8"
source = named("processSource").get().outputs.files.asFileTree
}
withType<KotlinCompile> {
kotlinOptions {
Expand Down
20 changes: 1 addition & 19 deletions mod/src/main/java/gg/skytils/skytilsmod/Reference.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,7 @@ public class Reference {
public static String dataUrl = "https://data.skytils.gg/";
public static final String MOD_ID = "skytils";
public static final String MOD_NAME = "Skytils";
@NotNull
public static final String VERSION = getVersion();
public static final String UNKNOWN_VERSION = "unknown";

private static String getVersion() {
URL url = Skytils.class.getResource("mcmod.info");
if (url == null) return UNKNOWN_VERSION;
try (InputStream input = url.openStream()) {
MetadataCollection metadataCollection = MetadataCollection.from(input, "skytils");
ModMetadata metadata = metadataCollection.getMetadataForId("skytils",
new HashMap<String, Object>() {{
put("name", "Skytils");
put("version", UNKNOWN_VERSION);
}});
return metadata.version;
} catch (IOException e) {
return UNKNOWN_VERSION;
}
}
public static final String VERSION = "@version@";

public static final int apiVersion = 5;
}
9 changes: 4 additions & 5 deletions mod/src/main/kotlin/gg/skytils/skytilsmod/Skytils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ class Skytils {
companion object : CoroutineScope {
const val MOD_ID = Reference.MOD_ID
const val MOD_NAME = Reference.MOD_NAME
@JvmField
val VERSION = Reference.VERSION
const val VERSION = Reference.VERSION

@JvmStatic
val mc: Minecraft by lazy {
Expand Down Expand Up @@ -260,9 +259,9 @@ class Skytils {

var domain = "api.skytils.gg"

val prefix = "§9§lSkytils §8»"
val successPrefix = "§a§lSkytils §8»"
val failPrefix = "§c§lSkytils (${Reference.VERSION}) §8»"
const val prefix = "§9§lSkytils §8»"
const val successPrefix = "§a§lSkytils §8»"
const val failPrefix = "§c§lSkytils (${Reference.VERSION}) §8»"

var trustClientTime = false
}
Expand Down

0 comments on commit dda7481

Please sign in to comment.