diff --git a/.gitignore b/.gitignore index c9a75934..4965c82d 100644 --- a/.gitignore +++ b/.gitignore @@ -38,6 +38,3 @@ options.txt usercache.json usernamecache.json *.txt - -versions/*/tmp.srg -versions/*/api/ diff --git a/README.md b/README.md index bb9927f1..436d2604 100644 --- a/README.md +++ b/README.md @@ -11,110 +11,46 @@ instead you simply have to describe _what_ you want. ## Dependency -It's recommended that you include [Essential](link eventually) instead of adding it yourself. - -In your repository block, add: - -Groovy -```groovy -maven { - url = "https://repo.essential.gg/repository/maven-public" -} -``` -Kotlin -```kotlin -maven(url = "https://repo.essential.gg/repository/maven-public") -``` - -To use the latest builds, use the following dependency: - -
Forge - ```kotlin -implementation("gg.essential:elementa-$mcVersion-$mcPlatform:$buildNumber") -``` -
-
Fabric - -Groovy -```groovy -modImplementation(include("gg.essential:elementa-$mcVersion-$mcPlatform:$buildNumber")) -``` -Kotlin -```kotlin -modImplementation(include("gg.essential:elementa-$mcVersion-$mcPlatform:$buildNumber")!!) +repository { + // All versions of Elementa and UniversalCraft are published to Essential's public maven repository. + // (if you're still using Groovy build scripts, replace `()` with `{}`) + maven(url = "https://repo.essential.gg/repository/maven-public") +} +dependencies { + // Add Elementa dependency. For the latest $elementaVersion, see the badge below this code snippet. + implementation("gg.essential:elementa:$elementaVersion") + + // Optionally, add some of the unstable Elementa features. + // Note that these MUST be relocated to your own package because future versions may contain breaking changes + // and therefore MUST NOT be simply included via Fabric's jar-in-jar mechanism. + implementation("gg.essential:elementa-unstable-layoutdsl:$elementaVersion") + + // Elementa itself is independent of Minecraft versions and mod loaders, instead it depends on UniversalCraft which + // provides bindings to specific Minecraft versions. + // As such, you must include the UniversalCraft version for the Minecraft version + mod loader you're targeting. + // For a list of all available platforms, see https://github.com/EssentialGG/UniversalCraft + // For your convenience, the latest $ucVersion is also included in a badge below this code snippet. + // (Note: if you are not using Loom, replace `modImplementation` with `implementation` or your equivalent) + modImplementation("gg.essential:universalcraft-1.8.9-forge:$ucVersion") + + // If you're using Fabric, you may use its jar-in-jar mechanism to bundle Elementa and UniversalCraft with your + // mod by additionally adding them to the `include` configuration like this (in place of the above): + implementation(include("gg.essential:elementa:$elementaVersion")!!) + modImplementation(include("gg.essential:universalcraft-1.8.9-forge:$ucVersion")) + // If you're using Forge, you must instead include them directly into your jar file and relocate them to your + // own package (this is important! otherwise you will be incompatible with other mods!) + // using e.g. https://gradleup.com/shadow/configuration/relocation/ + // For an example, read the IMPORTANT section below. +} ``` -
- -### Build Reference -
Build Reference - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
mcVersionmcPlatformbuildNumber
1.18.1fabric - 1.18.1-fabric -
1.18.1forge - 1.18.1-forge -
1.17.1fabric - 1.17.1-fabric -
1.17.1forge - 1.17.1-forge -
1.16.2forge - 1.16.2-forge -
1.12.2forge - 1.12.2-forge -
1.8.9forge1.8.9-forge
- -
- -If you were previously using v1.7.1 of Elementa and are now on the v2.0.0 builds, please refer to the -[migration](docs/migration.md) document to know what has changed. - -To learn about all the new features in v2.0.0, please read the [what's new](docs/whatsnew.md) document. +gg.essential:elementa +gg.essential:universalcraft-1.8.9-forge

IMPORTANT!

-If you are using forge, you must also relocate Elementa to avoid potential crashes with other mods. To do this, you will need to use the Shadow Gradle plugin. +If you are using Forge, you must also relocate Elementa to avoid incompatibility with other mods. +To do this, you may use the Shadow Gradle plugin:
Groovy Version @@ -191,6 +127,11 @@ In your dependencies block, add: implementation "club.sk1er:Elementa:1.7.1-$mcVersion" ``` +If you were previously using v1.7.1 of Elementa and are now on the v2.0.0 builds, please refer to the +[migration](docs/migration.md) document to know what has changed. + +To learn about all the new features in v2.0.0, please read the [what's new](docs/whatsnew.md) document. + ## Components All the drawing in Elementa is done via UIComponents. There is a root component named `Window` diff --git a/api/Elementa.api b/api/Elementa.api index 5d4bc35f..c079fd6d 100644 --- a/api/Elementa.api +++ b/api/Elementa.api @@ -2565,8 +2565,16 @@ public final class gg/essential/elementa/dsl/UtilitiesKt { public static final fun toConstraint (Ljava/awt/Color;)Lgg/essential/elementa/constraints/ConstantColorConstraint; public static final fun width (CF)F public static final fun width (Ljava/lang/String;FLgg/essential/elementa/font/FontProvider;)F + public static final synthetic fun width (Lnet/minecraft/class_2561;FLgg/essential/elementa/font/FontProvider;)F + public static final synthetic fun width (Lnet/minecraft/network/chat/Component;FLgg/essential/elementa/font/FontProvider;)F + public static final synthetic fun width (Lnet/minecraft/util/IChatComponent;FLgg/essential/elementa/font/FontProvider;)F + public static final synthetic fun width (Lnet/minecraft/util/text/ITextComponent;FLgg/essential/elementa/font/FontProvider;)F public static synthetic fun width$default (CFILjava/lang/Object;)F public static synthetic fun width$default (Ljava/lang/String;FLgg/essential/elementa/font/FontProvider;ILjava/lang/Object;)F + public static synthetic fun width$default (Lnet/minecraft/class_2561;FLgg/essential/elementa/font/FontProvider;ILjava/lang/Object;)F + public static synthetic fun width$default (Lnet/minecraft/network/chat/Component;FLgg/essential/elementa/font/FontProvider;ILjava/lang/Object;)F + public static synthetic fun width$default (Lnet/minecraft/util/IChatComponent;FLgg/essential/elementa/font/FontProvider;ILjava/lang/Object;)F + public static synthetic fun width$default (Lnet/minecraft/util/text/ITextComponent;FLgg/essential/elementa/font/FontProvider;ILjava/lang/Object;)F } public abstract class gg/essential/elementa/effects/Effect { diff --git a/build.gradle.kts b/build.gradle.kts index b69e96bf..c9aea799 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,10 +6,14 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { kotlin("jvm") version "1.9.23" id("org.jetbrains.kotlinx.binary-compatibility-validator") version "0.8.0" - id("org.jetbrains.dokka") version "1.9.20" apply false + id("org.jetbrains.dokka") version "1.9.20" id("gg.essential.defaults") + id("gg.essential.defaults.maven-publish") } +group = "gg.essential" +version = versionFromBuildIdAndBranch() + kotlin.jvmToolchain { (this as JavaToolchainSpec).languageVersion.set(JavaLanguageVersion.of(8)) } @@ -47,6 +51,7 @@ dependencies { internal(libs.dom4j) implementation(prebundle(internal)) + compileOnly(project(":mc-stubs")) // Depending on LWJGL3 instead of 2 so we can choose opengl bindings only compileOnly("org.lwjgl:lwjgl-opengl:3.3.1") // Depending on 1.8.9 for all of these because that's the oldest version we support @@ -56,8 +61,23 @@ dependencies { compileOnly("com.google.code.gson:gson:2.2.4") } +tasks.processResources { + inputs.property("project.version", project.version) + filesMatching("fabric.mod.json") { + expand("version" to project.version) + } +} + +tasks.jar { + dependsOn(internal) + from({ internal.map { zipTree(it) } }) +} + apiValidation { - ignoredProjects.addAll(listOf("platform", "statev2", "layoutdsl")) - ignoredPackages.add("com.example") + ignoredProjects.addAll(subprojects.map { it.name }) nonPublicMarkers.add("org.jetbrains.annotations.ApiStatus\$Internal") } + +publishing.publications.named("maven") { + artifactId = "elementa" +} diff --git a/versions/1.12.2-1.8.9.txt b/example/1.12.2-1.8.9.txt similarity index 100% rename from versions/1.12.2-1.8.9.txt rename to example/1.12.2-1.8.9.txt diff --git a/versions/1.15.2-1.12.2.txt b/example/1.15.2-1.12.2.txt similarity index 100% rename from versions/1.15.2-1.12.2.txt rename to example/1.15.2-1.12.2.txt diff --git a/versions/build.gradle.kts b/example/build.gradle.kts similarity index 53% rename from versions/build.gradle.kts rename to example/build.gradle.kts index 9fce3d75..b610de4e 100644 --- a/versions/build.gradle.kts +++ b/example/build.gradle.kts @@ -1,25 +1,14 @@ -import gg.essential.gradle.multiversion.excludeKotlinDefaultImpls -import gg.essential.gradle.multiversion.mergePlatformSpecifics import gg.essential.gradle.util.* plugins { kotlin("jvm") - id("org.jetbrains.dokka") id("gg.essential.multi-version") id("gg.essential.defaults") - id("gg.essential.defaults.maven-publish") } -group = "gg.essential" - java.withSourcesJar() -tasks.compileKotlin.setJvmDefault(if (platform.mcVersion >= 11400) "all" else "all-compatibility") loom.noServerRunConfigs() -val common by configurations.creating -configurations.compileClasspath { extendsFrom(common) } -configurations.runtimeClasspath { extendsFrom(common) } - dependencies { implementation(libs.kotlin.stdlib.jdk8) implementation(libs.kotlin.reflect) @@ -29,7 +18,7 @@ dependencies { exclude(group = "org.jetbrains.kotlin") } - common(project(":")) + implementation(project(":example:common")) if (platform.isFabric) { val fabricApiVersion = when(platform.mcVersion) { @@ -57,34 +46,3 @@ dependencies { } } } - -tasks.processResources { - filesMatching(listOf("fabric.mod.json")) { - filter { it.replace("\"com.example.examplemod.ExampleMod\"", "") } - } -} - -tasks.dokkaHtml { - moduleName.set("Elementa $name") -} - -tasks.jar { - dependsOn(common) - from({ common.map { zipTree(it) } }) - mergePlatformSpecifics() - - // We build the common module with legacy default impl for backwards compatibility, but we only need those for - // 1.12.2 and older. Newer versions have never shipped with legacy default impl. - if (platform.mcVersion >= 11400) { - excludeKotlinDefaultImpls() - } - - exclude("com/example/examplemod/**") - exclude("META-INF/mods.toml") - exclude("mcmod.info") - exclude("kotlin/**") -} - -tasks.named("sourcesJar") { - from(project(":").sourceSets.main.map { it.allSource }) -} diff --git a/example/common/build.gradle.kts b/example/common/build.gradle.kts new file mode 100644 index 00000000..1f228961 --- /dev/null +++ b/example/common/build.gradle.kts @@ -0,0 +1,23 @@ +import gg.essential.gradle.multiversion.StripReferencesTransform.Companion.registerStripReferencesAttribute + +plugins { + kotlin("jvm") + id("gg.essential.defaults") +} +repositories.mavenLocal() + +kotlin.jvmToolchain(8) + +val common = registerStripReferencesAttribute("common") { + excludes.add("net.minecraft") +} + +dependencies { + api(libs.kotlin.stdlib.jdk8) + + compileOnly(libs.versions.universalcraft.map { "gg.essential:universalcraft-1.8.9-forge:$it" }) { + attributes { attribute(common, true) } + } + + api(project(":")) +} diff --git a/src/main/java/com/example/examplemod/ComponentsGui.kt b/example/common/src/main/kotlin/com/example/examplemod/ComponentsGui.kt similarity index 100% rename from src/main/java/com/example/examplemod/ComponentsGui.kt rename to example/common/src/main/kotlin/com/example/examplemod/ComponentsGui.kt diff --git a/src/main/java/com/example/examplemod/ExampleGui.kt b/example/common/src/main/kotlin/com/example/examplemod/ExampleGui.kt similarity index 100% rename from src/main/java/com/example/examplemod/ExampleGui.kt rename to example/common/src/main/kotlin/com/example/examplemod/ExampleGui.kt diff --git a/src/main/java/com/example/examplemod/ExampleServerList.kt b/example/common/src/main/kotlin/com/example/examplemod/ExampleServerList.kt similarity index 100% rename from src/main/java/com/example/examplemod/ExampleServerList.kt rename to example/common/src/main/kotlin/com/example/examplemod/ExampleServerList.kt diff --git a/src/main/java/com/example/examplemod/ExamplesGui.kt b/example/common/src/main/kotlin/com/example/examplemod/ExamplesGui.kt similarity index 94% rename from src/main/java/com/example/examplemod/ExamplesGui.kt rename to example/common/src/main/kotlin/com/example/examplemod/ExamplesGui.kt index cd39cb25..d1dfebfb 100644 --- a/src/main/java/com/example/examplemod/ExamplesGui.kt +++ b/example/common/src/main/kotlin/com/example/examplemod/ExamplesGui.kt @@ -6,7 +6,7 @@ import gg.essential.elementa.components.* import gg.essential.elementa.constraints.* import gg.essential.elementa.constraints.animation.Animations import gg.essential.elementa.dsl.* -import gg.essential.elementa.impl.Platform.Companion.platform +import gg.essential.universal.UMinecraft import gg.essential.universal.UScreen import java.awt.Color @@ -39,7 +39,7 @@ class ExamplesGui : WindowScreen(ElementaVersion.V2) { } }.onMouseClick { try { - platform.currentScreen = action() + UMinecraft.currentScreenObj = action() } catch (e: Exception) { e.printStackTrace() } diff --git a/src/main/java/com/example/examplemod/JavaTestGui.java b/example/common/src/main/kotlin/com/example/examplemod/JavaTestGui.java similarity index 100% rename from src/main/java/com/example/examplemod/JavaTestGui.java rename to example/common/src/main/kotlin/com/example/examplemod/JavaTestGui.java diff --git a/src/main/java/com/example/examplemod/KtTestGui.kt b/example/common/src/main/kotlin/com/example/examplemod/KtTestGui.kt similarity index 100% rename from src/main/java/com/example/examplemod/KtTestGui.kt rename to example/common/src/main/kotlin/com/example/examplemod/KtTestGui.kt diff --git a/versions/mainProject b/example/mainProject similarity index 100% rename from versions/mainProject rename to example/mainProject diff --git a/versions/root.gradle.kts b/example/root.gradle.kts similarity index 65% rename from versions/root.gradle.kts rename to example/root.gradle.kts index cf9a6646..dac88a53 100644 --- a/versions/root.gradle.kts +++ b/example/root.gradle.kts @@ -2,11 +2,8 @@ import gg.essential.gradle.util.* plugins { id("gg.essential.multi-version.root") - id("gg.essential.multi-version.api-validation") } -version = versionFromBuildIdAndBranch() - preprocess { val forge11801 = createNode("1.18.1-forge", 11801, "srg") val fabric11801 = createNode("1.18.1-fabric", 11801, "yarn") @@ -14,7 +11,6 @@ preprocess { val fabric11701 = createNode("1.17.1-fabric", 11701, "yarn") val fabric11602 = createNode("1.16.2-fabric", 11602, "yarn") val forge11602 = createNode("1.16.2-forge", 11602, "srg") - val forge11502 = createNode("1.15.2-forge", 11502, "srg") val forge11202 = createNode("1.12.2-forge", 11202, "srg") val forge10809 = createNode("1.8.9-forge", 10809, "srg") @@ -23,13 +19,6 @@ preprocess { forge11701.link(fabric11701) fabric11701.link(fabric11602) fabric11602.link(forge11602) - forge11602.link(forge11502) - forge11502.link(forge11202, file("1.15.2-1.12.2.txt")) + forge11602.link(forge11202, file("1.15.2-1.12.2.txt")) forge11202.link(forge10809, file("1.12.2-1.8.9.txt")) } - -apiValidation { - ignoredProjects.addAll(subprojects.map { it.name }) - ignoredPackages.add("com.example") - nonPublicMarkers.add("org.jetbrains.annotations.ApiStatus\$Internal") -} diff --git a/versions/src/main/java/com/example/examplemod/ExampleMod.java b/example/src/main/java/com/example/examplemod/ExampleMod.java similarity index 100% rename from versions/src/main/java/com/example/examplemod/ExampleMod.java rename to example/src/main/java/com/example/examplemod/ExampleMod.java diff --git a/versions/src/main/resources/META-INF/mods.toml b/example/src/main/resources/META-INF/mods.toml similarity index 100% rename from versions/src/main/resources/META-INF/mods.toml rename to example/src/main/resources/META-INF/mods.toml diff --git a/example/src/main/resources/fabric.mod.json b/example/src/main/resources/fabric.mod.json new file mode 100644 index 00000000..11343b2f --- /dev/null +++ b/example/src/main/resources/fabric.mod.json @@ -0,0 +1,10 @@ +{ + "schemaVersion": 1, + "id": "examplemod", + "name": "Example Mod", + "version": "0", + "environment": "client", + "entrypoints": { + "client": ["com.example.examplemod.ExampleMod"] + } +} \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 0cbe6a10..ab068379 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -2,7 +2,7 @@ kotlin = "1.5.10" kotlinx-coroutines = "1.5.2" jetbrains-annotations = "23.0.0" -universalcraft = "211" +universalcraft = "349" commonmark = "0.17.1" dom4j = "2.1.1" diff --git a/mc-stubs/build.gradle.kts b/mc-stubs/build.gradle.kts new file mode 100644 index 00000000..d03e0f6f --- /dev/null +++ b/mc-stubs/build.gradle.kts @@ -0,0 +1,5 @@ +plugins { + `java-library` +} + +java.toolchain.languageVersion = JavaLanguageVersion.of(8) diff --git a/mc-stubs/src/main/java/net/minecraft/class_2561.java b/mc-stubs/src/main/java/net/minecraft/class_2561.java new file mode 100644 index 00000000..3ebbc08a --- /dev/null +++ b/mc-stubs/src/main/java/net/minecraft/class_2561.java @@ -0,0 +1,4 @@ +package net.minecraft; + +public class class_2561 { +} diff --git a/mc-stubs/src/main/java/net/minecraft/network/chat/Component.java b/mc-stubs/src/main/java/net/minecraft/network/chat/Component.java new file mode 100644 index 00000000..a9a957e3 --- /dev/null +++ b/mc-stubs/src/main/java/net/minecraft/network/chat/Component.java @@ -0,0 +1,4 @@ +package net.minecraft.network.chat; + +public class Component { +} diff --git a/mc-stubs/src/main/java/net/minecraft/util/IChatComponent.java b/mc-stubs/src/main/java/net/minecraft/util/IChatComponent.java new file mode 100644 index 00000000..102b0582 --- /dev/null +++ b/mc-stubs/src/main/java/net/minecraft/util/IChatComponent.java @@ -0,0 +1,4 @@ +package net.minecraft.util; + +public class IChatComponent { +} diff --git a/mc-stubs/src/main/java/net/minecraft/util/text/ITextComponent.java b/mc-stubs/src/main/java/net/minecraft/util/text/ITextComponent.java new file mode 100644 index 00000000..d792d8fa --- /dev/null +++ b/mc-stubs/src/main/java/net/minecraft/util/text/ITextComponent.java @@ -0,0 +1,4 @@ +package net.minecraft.util.text; + +public class ITextComponent { +} diff --git a/settings.gradle.kts b/settings.gradle.kts index 9fe07369..dcfc092c 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -10,6 +10,7 @@ pluginManagement { plugins { val egtVersion = "0.5.0" id("gg.essential.defaults") version egtVersion + id("gg.essential.defaults.maven-publish") version egtVersion id("gg.essential.multi-version.root") version egtVersion id("gg.essential.multi-version.api-validation") version egtVersion } @@ -17,18 +18,21 @@ pluginManagement { rootProject.name = "Elementa" -include(":platform") -project(":platform").apply { - projectDir = file("versions/") - buildFileName = "root.gradle.kts" -} + +include(":mc-stubs") + include(":unstable:statev2") include(":unstable:layoutdsl") + +include(":example") +project(":example").apply { + buildFileName = "root.gradle.kts" +} +include(":example:common") listOf( "1.8.9-forge", "1.12.2-forge", - "1.15.2-forge", "1.16.2-forge", "1.16.2-fabric", "1.17.1-fabric", @@ -36,9 +40,8 @@ listOf( "1.18.1-fabric", "1.18.1-forge", ).forEach { version -> - include(":platform:$version") - project(":platform:$version").apply { - projectDir = file("versions/$version") + include(":example:$version") + project(":example:$version").apply { buildFileName = "../build.gradle.kts" } } diff --git a/src/main/kotlin/gg/essential/elementa/components/SVGComponent.kt b/src/main/kotlin/gg/essential/elementa/components/SVGComponent.kt index d8284482..112b38a9 100644 --- a/src/main/kotlin/gg/essential/elementa/components/SVGComponent.kt +++ b/src/main/kotlin/gg/essential/elementa/components/SVGComponent.kt @@ -2,7 +2,6 @@ package gg.essential.elementa.components import gg.essential.elementa.UIComponent import gg.essential.elementa.components.image.ImageProvider -import gg.essential.elementa.impl.Platform.Companion.platform import gg.essential.elementa.svg.SVGParser import gg.essential.elementa.svg.data.SVG import gg.essential.universal.UGraphics @@ -33,7 +32,7 @@ class SVGComponent(private var svg: SVG) : UIComponent(), ImageProvider { } override fun drawImage(matrixStack: UMatrixStack, x: Double, y: Double, width: Double, height: Double, color: Color) { - if (platform.mcVersion >= 11700) { + if (UGraphics.isCoreProfile()) { // TODO heavily relies on legacy gl, at least need to use per-vertex color and convert lines/points to tris return } diff --git a/src/main/kotlin/gg/essential/elementa/components/UIShape.kt b/src/main/kotlin/gg/essential/elementa/components/UIShape.kt index 63ec770d..f71a69cc 100644 --- a/src/main/kotlin/gg/essential/elementa/components/UIShape.kt +++ b/src/main/kotlin/gg/essential/elementa/components/UIShape.kt @@ -2,7 +2,6 @@ package gg.essential.elementa.components import gg.essential.elementa.UIComponent import gg.essential.elementa.dsl.toConstraint -import gg.essential.elementa.impl.Platform.Companion.platform import gg.essential.universal.UGraphics import gg.essential.universal.UMatrixStack import org.lwjgl.opengl.GL11 @@ -52,7 +51,7 @@ open class UIShape @JvmOverloads constructor(color: Color = Color.WHITE) : UICom val worldRenderer = UGraphics.getFromTessellator() UGraphics.tryBlendFuncSeparate(770, 771, 1, 0) - if (platform.mcVersion >= 11700) { + if (UGraphics.isCoreProfile()) { worldRenderer.beginWithDefaultShader(UGraphics.DrawMode.TRIANGLE_FAN, UGraphics.CommonVertexFormats.POSITION_COLOR) } else { worldRenderer.begin(drawMode, UGraphics.CommonVertexFormats.POSITION_COLOR) diff --git a/src/main/kotlin/gg/essential/elementa/components/Window.kt b/src/main/kotlin/gg/essential/elementa/components/Window.kt index c85481b6..5dc9a471 100644 --- a/src/main/kotlin/gg/essential/elementa/components/Window.kt +++ b/src/main/kotlin/gg/essential/elementa/components/Window.kt @@ -7,7 +7,6 @@ import gg.essential.elementa.constraints.resolution.ConstraintResolver import gg.essential.elementa.constraints.resolution.ConstraintResolverV2 import gg.essential.elementa.effects.ScissorEffect import gg.essential.elementa.font.FontRenderer -import gg.essential.elementa.impl.Platform.Companion.platform import gg.essential.elementa.utils.elementaDev import gg.essential.elementa.utils.requireMainThread import gg.essential.universal.* @@ -111,7 +110,7 @@ class Window @JvmOverloads constructor( } catch (e: Throwable) { cancelDrawing = true - val guiName = platform.currentScreen?.javaClass?.simpleName ?: "" + val guiName = UMinecraft.currentScreenObj?.javaClass?.simpleName ?: "" when (e) { is StackOverflowError -> { println("Elementa: Cyclic constraint structure detected!") @@ -129,7 +128,7 @@ class Window @JvmOverloads constructor( ScissorEffect.currentScissorState = null GL11.glDisable(GL11.GL_SCISSOR_TEST) - platform.currentScreen = when { + UMinecraft.currentScreenObj = when { e is StackOverflowError && elementaDev -> { val cyclicNodes = when (System.getProperty("elementa.dev.cycle_resolver", "2")) { "2" -> ConstraintResolverV2(this).getCyclicNodes() diff --git a/src/main/kotlin/gg/essential/elementa/components/input/AbstractTextInput.kt b/src/main/kotlin/gg/essential/elementa/components/input/AbstractTextInput.kt index 83a8cded..7aff6519 100644 --- a/src/main/kotlin/gg/essential/elementa/components/input/AbstractTextInput.kt +++ b/src/main/kotlin/gg/essential/elementa/components/input/AbstractTextInput.kt @@ -6,7 +6,6 @@ import gg.essential.elementa.constraints.CenterConstraint import gg.essential.elementa.constraints.animation.Animations import gg.essential.elementa.dsl.* import gg.essential.elementa.effects.ScissorEffect -import gg.essential.elementa.impl.Platform.Companion.platform import gg.essential.elementa.utils.getStringSplitToWidth import gg.essential.universal.UDesktop import gg.essential.universal.UKeyboard diff --git a/src/main/kotlin/gg/essential/elementa/dsl/utilities.kt b/src/main/kotlin/gg/essential/elementa/dsl/utilities.kt index 7ab8563b..43536fdb 100644 --- a/src/main/kotlin/gg/essential/elementa/dsl/utilities.kt +++ b/src/main/kotlin/gg/essential/elementa/dsl/utilities.kt @@ -4,6 +4,7 @@ import gg.essential.elementa.constraints.* import gg.essential.elementa.font.DefaultFonts import gg.essential.elementa.font.FontProvider import gg.essential.universal.UGraphics +import gg.essential.universal.wrappers.message.UTextComponent import java.awt.Color fun Char.width(textScale: Float = 1f) = UGraphics.getCharWidth(this) * textScale @@ -44,3 +45,20 @@ operator fun Color.component1() = red operator fun Color.component2() = green operator fun Color.component3() = blue operator fun Color.component4() = alpha + +// Fabric +@Deprecated("Direct Minecraft dependency", level = DeprecationLevel.HIDDEN) +fun net.minecraft.class_2561.width(textScale: Float = 1f, fontProvider: FontProvider = DefaultFonts.VANILLA_FONT_RENDERER) = + UTextComponent.from(this)!!.text.width(textScale, fontProvider) +// Forge 1.8 +@Deprecated("Direct Minecraft dependency", level = DeprecationLevel.HIDDEN) +fun net.minecraft.util.IChatComponent.width(textScale: Float = 1f, fontProvider: FontProvider = DefaultFonts.VANILLA_FONT_RENDERER) = + UTextComponent.from(this)!!.text.width(textScale, fontProvider) +// Forge 1.12-1.16 +@Deprecated("Direct Minecraft dependency", level = DeprecationLevel.HIDDEN) +fun net.minecraft.util.text.ITextComponent.width(textScale: Float = 1f, fontProvider: FontProvider = DefaultFonts.VANILLA_FONT_RENDERER) = + UTextComponent.from(this)!!.text.width(textScale, fontProvider) +// Forge 1.17+ +@Deprecated("Direct Minecraft dependency", level = DeprecationLevel.HIDDEN) +fun net.minecraft.network.chat.Component.width(textScale: Float = 1f, fontProvider: FontProvider = DefaultFonts.VANILLA_FONT_RENDERER) = + UTextComponent.from(this)!!.text.width(textScale, fontProvider) diff --git a/src/main/kotlin/gg/essential/elementa/effects/StencilEffect.kt b/src/main/kotlin/gg/essential/elementa/effects/StencilEffect.kt index ac74d6bc..fea84db8 100644 --- a/src/main/kotlin/gg/essential/elementa/effects/StencilEffect.kt +++ b/src/main/kotlin/gg/essential/elementa/effects/StencilEffect.kt @@ -1,6 +1,6 @@ package gg.essential.elementa.effects -import gg.essential.elementa.impl.Platform.Companion.platform +import gg.essential.universal.UGraphics import gg.essential.universal.UMatrixStack import org.lwjgl.opengl.GL11.* @@ -9,6 +9,7 @@ import org.lwjgl.opengl.GL11.* * * In order to use, you must call [enableStencil] in mod initialization. */ +@Deprecated("Does not work on 1.14+") class StencilEffect : Effect() { override fun beforeDraw(matrixStack: UMatrixStack) { glEnable(GL_STENCIL_TEST) @@ -32,8 +33,9 @@ class StencilEffect : Effect() { /** * Must be called in mod initialization to use [StencilEffect] */ - @JvmStatic fun enableStencil() { //TODO wait for 1.15 to impl - platform.enableStencil() + @JvmStatic fun enableStencil() { + @Suppress("DEPRECATION") + UGraphics.enableStencil() } } } diff --git a/src/main/kotlin/gg/essential/elementa/impl/Platform.kt b/src/main/kotlin/gg/essential/elementa/impl/Platform.kt deleted file mode 100644 index 1fe62845..00000000 --- a/src/main/kotlin/gg/essential/elementa/impl/Platform.kt +++ /dev/null @@ -1,21 +0,0 @@ -package gg.essential.elementa.impl - -import org.jetbrains.annotations.ApiStatus -import java.util.* - -@ApiStatus.Internal -interface Platform { - val mcVersion: Int - - var currentScreen: Any? - - fun enableStencil() - - fun isCallingFromMinecraftThread(): Boolean - - @ApiStatus.Internal - companion object { - internal val platform: Platform = - ServiceLoader.load(Platform::class.java, Platform::class.java.classLoader).iterator().next() - } -} \ No newline at end of file diff --git a/src/main/kotlin/gg/essential/elementa/utils/invalidUsage.kt b/src/main/kotlin/gg/essential/elementa/utils/invalidUsage.kt index 5142e514..0b115781 100644 --- a/src/main/kotlin/gg/essential/elementa/utils/invalidUsage.kt +++ b/src/main/kotlin/gg/essential/elementa/utils/invalidUsage.kt @@ -1,6 +1,6 @@ package gg.essential.elementa.utils -import gg.essential.elementa.impl.Platform.Companion.platform +import gg.essential.universal.UMinecraft internal enum class InvalidUsageBehavior { IGNORE, @@ -39,5 +39,5 @@ internal fun requireState(state: Boolean, message: String) { /** Ensure a method can only be called from the main thread. Lack of this check does **not** imply thread-safety. */ internal fun requireMainThread(message: String = "This method is not thread-safe and must be called from the main thread. " + "Consider the thread-safety of the calling code and use Window.enqueueRenderOperation if applicable.") { - requireState(platform.isCallingFromMinecraftThread(), message) + requireState(UMinecraft.isCallingFromMinecraftThread(), message) } diff --git a/versions/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json similarity index 71% rename from versions/src/main/resources/fabric.mod.json rename to src/main/resources/fabric.mod.json index d00bdd1d..4f3cd859 100644 --- a/versions/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -4,9 +4,6 @@ "name": "Elementa", "version": "${version}", "environment": "client", - "entrypoints": { - "client": ["com.example.examplemod.ExampleMod"] - }, "custom": { "modmenu": { "badges": [ "library" ] diff --git a/versions/1.12.2-forge/.gitkeep b/versions/1.12.2-forge/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/versions/1.15.2-forge/.gitkeep b/versions/1.15.2-forge/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/versions/1.16.2-fabric/.gitkeep b/versions/1.16.2-fabric/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/versions/1.16.2-forge/.gitkeep b/versions/1.16.2-forge/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/versions/1.8.9-forge/.gitkeep b/versions/1.8.9-forge/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/versions/api/platform.api b/versions/api/platform.api deleted file mode 100644 index 6f3cc9cf..00000000 --- a/versions/api/platform.api +++ /dev/null @@ -1,19 +0,0 @@ -public final class gg/essential/elementa/dsl/UtilitiesKt_platform { - @1.8.9-forge - public static final fun width (Lnet/minecraft/util/IChatComponent;FLgg/essential/elementa/font/FontProvider;)F - @1.8.9-forge - public static synthetic fun width$default (Lnet/minecraft/util/IChatComponent;FLgg/essential/elementa/font/FontProvider;ILjava/lang/Object;)F - @1.17.1-forge,1.18.1-forge - public static final fun width (Lnet/minecraft/network/chat/Component;FLgg/essential/elementa/font/FontProvider;)F - @1.17.1-forge,1.18.1-forge - public static synthetic fun width$default (Lnet/minecraft/network/chat/Component;FLgg/essential/elementa/font/FontProvider;ILjava/lang/Object;)F - @1.16.2-fabric,1.17.1-fabric,1.18.1-fabric - public static final fun width (Lnet/minecraft/text/Text;FLgg/essential/elementa/font/FontProvider;)F - @1.16.2-fabric,1.17.1-fabric,1.18.1-fabric - public static synthetic fun width$default (Lnet/minecraft/text/Text;FLgg/essential/elementa/font/FontProvider;ILjava/lang/Object;)F - @1.12.2-forge,1.15.2-forge,1.16.2-forge - public static final fun width (Lnet/minecraft/util/text/ITextComponent;FLgg/essential/elementa/font/FontProvider;)F - @1.12.2-forge,1.15.2-forge,1.16.2-forge - public static synthetic fun width$default (Lnet/minecraft/util/text/ITextComponent;FLgg/essential/elementa/font/FontProvider;ILjava/lang/Object;)F -} - diff --git a/versions/gradle.properties b/versions/gradle.properties deleted file mode 100644 index edcf861e..00000000 --- a/versions/gradle.properties +++ /dev/null @@ -1 +0,0 @@ -baseArtifactId=elementa diff --git a/versions/src/main/java/gg/essential/elementa/dsl/utilities_platform.kt b/versions/src/main/java/gg/essential/elementa/dsl/utilities_platform.kt deleted file mode 100644 index 2d08f6f1..00000000 --- a/versions/src/main/java/gg/essential/elementa/dsl/utilities_platform.kt +++ /dev/null @@ -1,10 +0,0 @@ -@file:JvmName("UtilitiesKt_platform") -package gg.essential.elementa.dsl - -import gg.essential.elementa.font.DefaultFonts -import gg.essential.elementa.font.FontProvider -import gg.essential.universal.wrappers.message.UTextComponent -import net.minecraft.util.text.ITextComponent - -fun ITextComponent.width(textScale: Float = 1f, fontProvider: FontProvider = DefaultFonts.VANILLA_FONT_RENDERER) = - UTextComponent(this).formattedText.width(textScale, fontProvider) diff --git a/versions/src/main/java/gg/essential/elementa/impl/PlatformImpl.java b/versions/src/main/java/gg/essential/elementa/impl/PlatformImpl.java deleted file mode 100644 index faac816b..00000000 --- a/versions/src/main/java/gg/essential/elementa/impl/PlatformImpl.java +++ /dev/null @@ -1,59 +0,0 @@ -package gg.essential.elementa.impl; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.client.shader.Framebuffer; -import org.jetbrains.annotations.ApiStatus; -import org.jetbrains.annotations.Nullable; - -@ApiStatus.Internal -@SuppressWarnings("unused") // instantiated via reflection from Platform.Companion -public class PlatformImpl implements Platform { - - @Override - public int getMcVersion() { - //#if MC==11801 - //$$ return 11801; - //#elseif MC==11701 - //$$ return 11701; - //#elseif MC==11602 - //$$ return 11602; - //#elseif MC==11502 - //$$ return 11502; - //#elseif MC==11202 - return 11202; - //#elseif MC==10809 - //$$ return 10809; - //#endif - } - - @Nullable - @Override - public Object getCurrentScreen() { - return Minecraft.getMinecraft().currentScreen; - } - - @Override - public void setCurrentScreen(@Nullable Object screen) { - Minecraft.getMinecraft().displayGuiScreen((GuiScreen) screen); - } - - @Override - public void enableStencil() { - //#if MC<11500 - Framebuffer framebuffer = Minecraft.getMinecraft().getFramebuffer(); - if (!framebuffer.isStencilEnabled()) { - framebuffer.enableStencil(); - } - //#endif - } - - @Override - public boolean isCallingFromMinecraftThread() { - //#if MC>=11400 - //$$ return Minecraft.getInstance().isOnExecutionThread(); - //#else - return Minecraft.getMinecraft().isCallingFromMinecraftThread(); - //#endif - } -} diff --git a/versions/src/main/resources/META-INF/services/gg.essential.elementa.impl.Platform b/versions/src/main/resources/META-INF/services/gg.essential.elementa.impl.Platform deleted file mode 100644 index 16cfa331..00000000 --- a/versions/src/main/resources/META-INF/services/gg.essential.elementa.impl.Platform +++ /dev/null @@ -1 +0,0 @@ -gg.essential.elementa.impl.PlatformImpl