Skip to content

Commit

Permalink
Merge pull request #10 from bluefireoly/scoreboard
Browse files Browse the repository at this point in the history
Add scoreboard class
  • Loading branch information
jakobkmar committed Jul 15, 2021
2 parents 0210e3a + f38df4f commit e43d72a
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 26 deletions.
2 changes: 1 addition & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
15 changes: 9 additions & 6 deletions buildSrc/src/main/kotlin/BuildConstants.kt
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
}
3 changes: 2 additions & 1 deletion buildSrc/src/main/kotlin/mod-publish-script.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -35,7 +36,7 @@ tasks {
uploadFile = tasks.named("remapJar").get()
addGameVersion(minecraftVersion)
addLoader("fabric")
releaseType = projectState
versionType = projectStateType
}

create("publishAndUploadMod") {
Expand Down
28 changes: 14 additions & 14 deletions fabrikmc-core/src/main/kotlin/net/axay/fabrik/core/Fabrik.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ inline fun itemStack(
* name of the item stack.
*/
fun ItemStack.setLore(text: Collection<Text>) {
getOrCreateSubTag("display").put(
getOrCreateSubNbt("display").put(
"Lore",
text.mapTo(NbtList()) { NbtString.of(Text.Serializer.toJson(it)) }
)
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Text>,
) {
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)
}
}
6 changes: 6 additions & 0 deletions fabrikmc-core/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
"description": "${description}",
"authors": ["${author}"],

"entrypoints": {
"main": [
"net.axay.fabrik.core.FabrikKt::init"
]
},

"depends": {
"fabric": "*",
"fabric-language-kotlin": "*",
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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
}
)
)
}
)

0 comments on commit e43d72a

Please sign in to comment.