diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 376a0910..88ebb819 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -12,5 +12,5 @@ dependencies { implementation(kotlin("gradle-plugin", "1.5.10")) implementation("net.fabricmc", "fabric-loom", "0.8-SNAPSHOT") implementation("gradle.plugin.com.matthewprenger:CurseGradle:1.4.0") - implementation("gradle.plugin.com.modrinth.minotaur:Minotaur:1.1.0") + implementation("gradle.plugin.com.modrinth.minotaur:Minotaur:1.2.1") } diff --git a/buildSrc/src/main/kotlin/BuildConstants.kt b/buildSrc/src/main/kotlin/BuildConstants.kt index e5b8aa4d..d0528838 100644 --- a/buildSrc/src/main/kotlin/BuildConstants.kt +++ b/buildSrc/src/main/kotlin/BuildConstants.kt @@ -1,7 +1,10 @@ +import com.modrinth.minotaur.request.VersionType + object BuildConstants { - const val fabrikVersion = "1.0.1-SNAPSHOT" + const val fabrikVersion = "1.1.0" val isSnapshot = fabrikVersion.endsWith("-SNAPSHOT") val projectState = if (isSnapshot) "beta" else "release" + val projectStateType = if (isSnapshot) VersionType.BETA else VersionType.RELEASE const val curseforgeId = "447425" const val githubRepo = "bluefireoly/fabrikmc" @@ -11,9 +14,9 @@ object BuildConstants { const val majorMinecraftVersion = "1.17" // check these values here: https://axay.net/fabric/gradlekts/latest - const val minecraftVersion = "1.17" - const val yarnMappingsVersion = "1.17+build.1:v2" - const val fabricLoaderVersion = "0.11.3" - const val fabricApiVersion = "0.34.9+1.17" - const val fabricLanguageKotlinVersion = "1.6.1+kotlin.1.5.10" + const val minecraftVersion = "1.17.1" + const val yarnMappingsVersion = "1.17.1+build.13:v2" + const val fabricLoaderVersion = "0.11.6" + const val fabricApiVersion = "0.37.0+1.17" + const val fabricLanguageKotlinVersion = "1.6.2+kotlin.1.5.20" } diff --git a/buildSrc/src/main/kotlin/mod-publish-script.gradle.kts b/buildSrc/src/main/kotlin/mod-publish-script.gradle.kts index 740da400..dd655957 100644 --- a/buildSrc/src/main/kotlin/mod-publish-script.gradle.kts +++ b/buildSrc/src/main/kotlin/mod-publish-script.gradle.kts @@ -4,6 +4,7 @@ import BuildConstants.githubRepo import BuildConstants.isSnapshot import BuildConstants.minecraftVersion import BuildConstants.projectState +import BuildConstants.projectStateType import com.matthewprenger.cursegradle.CurseProject import com.matthewprenger.cursegradle.CurseRelation import com.matthewprenger.cursegradle.CurseUploadTask @@ -35,7 +36,7 @@ tasks { uploadFile = tasks.named("remapJar").get() addGameVersion(minecraftVersion) addLoader("fabric") - releaseType = projectState + versionType = projectStateType } create("publishAndUploadMod") { diff --git a/fabrikmc-core/src/main/kotlin/net/axay/fabrik/core/Fabrik.kt b/fabrikmc-core/src/main/kotlin/net/axay/fabrik/core/Fabrik.kt index 619676c7..078720ed 100644 --- a/fabrikmc-core/src/main/kotlin/net/axay/fabrik/core/Fabrik.kt +++ b/fabrikmc-core/src/main/kotlin/net/axay/fabrik/core/Fabrik.kt @@ -5,21 +5,21 @@ import net.axay.fabrik.core.task.FabrikCoroutineManager import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents import net.minecraft.server.MinecraftServer -object Fabrik { - var currentServer: MinecraftServer? = null +/** + * Do not call this function, as it is the entry point of the Fabrik + * mod itself. + */ +fun init() { + logInfo("Initializing Fabrik due to init call") - /** - * You should call this function if you intend to - * use the Fabrik API. - */ - fun init() { - logInfo("Initializing Fabrik due to init call") + ServerLifecycleEvents.SERVER_STARTING.register { + Fabrik.currentServer = it + logInfo("Reached SERVER_STARTING state") + } - ServerLifecycleEvents.SERVER_STARTING.register { - currentServer = it - logInfo("Reached SERVER_STARTING state") - } + FabrikCoroutineManager.init() +} - FabrikCoroutineManager.init() - } +object Fabrik { + var currentServer: MinecraftServer? = null } diff --git a/fabrikmc-core/src/main/kotlin/net/axay/fabrik/core/item/ItemBuilder.kt b/fabrikmc-core/src/main/kotlin/net/axay/fabrik/core/item/ItemBuilder.kt index 593e1a2a..40e225a7 100644 --- a/fabrikmc-core/src/main/kotlin/net/axay/fabrik/core/item/ItemBuilder.kt +++ b/fabrikmc-core/src/main/kotlin/net/axay/fabrik/core/item/ItemBuilder.kt @@ -23,7 +23,7 @@ inline fun itemStack( * name of the item stack. */ fun ItemStack.setLore(text: Collection) { - getOrCreateSubTag("display").put( + getOrCreateSubNbt("display").put( "Lore", text.mapTo(NbtList()) { NbtString.of(Text.Serializer.toJson(it)) } ) diff --git a/fabrikmc-core/src/main/kotlin/net/axay/fabrik/core/scoreboard/Sideboard.kt b/fabrikmc-core/src/main/kotlin/net/axay/fabrik/core/scoreboard/Sideboard.kt new file mode 100644 index 00000000..bdff2b52 --- /dev/null +++ b/fabrikmc-core/src/main/kotlin/net/axay/fabrik/core/scoreboard/Sideboard.kt @@ -0,0 +1,31 @@ +package net.axay.fabrik.core.scoreboard + +import net.axay.fabrik.core.Fabrik +import net.minecraft.scoreboard.Scoreboard +import net.minecraft.scoreboard.ScoreboardCriterion +import net.minecraft.scoreboard.ServerScoreboard +import net.minecraft.text.Text + +class Sideboard( + name: String, + displayName: Text, + lines: List, +) { + companion object { + val sidebarId = Scoreboard.getDisplaySlotId("sidebar") + } + + private val scoreboard = ServerScoreboard(Fabrik.currentServer) + private val objective = scoreboard.addObjective(name, ScoreboardCriterion.DUMMY, displayName, ScoreboardCriterion.RenderType.INTEGER) + + init { + lines.forEachIndexed { index, line -> + val team = scoreboard.addTeam("team_$index") + team.prefix = line + scoreboard.addPlayerToTeam("§$index", team) + scoreboard.getPlayerScore("§$index", objective).score = lines.size - index + } + + scoreboard.setObjectiveSlot(sidebarId, objective) + } +} diff --git a/fabrikmc-core/src/main/resources/fabric.mod.json b/fabrikmc-core/src/main/resources/fabric.mod.json index b1f2a2c9..c03610a8 100644 --- a/fabrikmc-core/src/main/resources/fabric.mod.json +++ b/fabrikmc-core/src/main/resources/fabric.mod.json @@ -7,6 +7,12 @@ "description": "${description}", "authors": ["${author}"], + "entrypoints": { + "main": [ + "net.axay.fabrik.core.FabrikKt::init" + ] + }, + "depends": { "fabric": "*", "fabric-language-kotlin": "*", diff --git a/fabrikmc-testmod/src/main/kotlin/net/axay/fabrik/test/Manager.kt b/fabrikmc-testmod/src/main/kotlin/net/axay/fabrik/test/Manager.kt index a05eaee3..9063c015 100644 --- a/fabrikmc-testmod/src/main/kotlin/net/axay/fabrik/test/Manager.kt +++ b/fabrikmc-testmod/src/main/kotlin/net/axay/fabrik/test/Manager.kt @@ -1,12 +1,11 @@ package net.axay.fabrik.test -import net.axay.fabrik.core.Fabrik import net.axay.fabrik.test.commands.guiCommand +import net.axay.fabrik.test.commands.sideboardCommand import net.axay.fabrik.test.commands.textTestCommand fun init() { - Fabrik.init() - guiCommand textTestCommand + sideboardCommand } diff --git a/fabrikmc-testmod/src/main/kotlin/net/axay/fabrik/test/commands/SideboardCommand.kt b/fabrikmc-testmod/src/main/kotlin/net/axay/fabrik/test/commands/SideboardCommand.kt new file mode 100644 index 00000000..1e901e1d --- /dev/null +++ b/fabrikmc-testmod/src/main/kotlin/net/axay/fabrik/test/commands/SideboardCommand.kt @@ -0,0 +1,35 @@ +package net.axay.fabrik.test.commands + +import com.mojang.brigadier.arguments.StringArgumentType +import net.axay.fabrik.commands.* +import net.axay.fabrik.core.scoreboard.Sideboard +import net.axay.fabrik.core.text.literal +import net.axay.fabrik.core.text.literalText + +val sideboardCommand = command("sideboard", true) { + argument("example", StringArgumentType.string()) { + simpleSuggests { sideboardExamples.keys } + simpleExecutes { + sideboardExamples[it.getArgument("example")]?.value + } + } +} + +private val sideboardExamples = mapOf( + "simple" to lazy { + Sideboard( + "simple", + literalText("Simple Sideboard") { + color = 0x6DFF41 + }, + listOf( + "Hey wie,".literal, + "geht's?".literal, + " ".literal, + literalText("Farben gehen auch") { + color = 0x57FFF0 + } + ) + ) + } +)