Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
RTAkland committed Aug 30, 2023
1 parent 7a05402 commit 0fbc1b5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
> 点击[这里](https://github.com/DangoTown/ViewDimension/releases/latest)快速下载最新版本的`ViewDimension`
# 原理
> 此Mod基于原版命令: `team` 但是使用的不是命令而是 命令后的API, 源代码非常简单只有一个文件, 如果你想对其
> 此Mod基于原版命令: `team` 但是使用的不是命令而是 命令后的API, 如果你想对其
> 继续开发请遵守[Apache-2.0](./LICENSE)协议开发, 并著名原作者信息
# 开源
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ org.gradle.jvmargs=-Xmx1G
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.20.1
yarn_mappings=1.20.1+build.10
loader_version=0.14.20
loader_version=0.14.21

# Mod Properties
mod_version = 0.0.1
Expand Down
43 changes: 31 additions & 12 deletions src/main/java/cn/rtast/viewdimension/ViewDimension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,55 @@ package cn.rtast.viewdimension

import net.fabricmc.api.DedicatedServerModInitializer
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents
import net.minecraft.scoreboard.ServerScoreboard
import net.minecraft.scoreboard.Team
import net.minecraft.text.MutableText
import net.minecraft.text.Text
import net.minecraft.util.Formatting

class ViewDimension : DedicatedServerModInitializer {

private var currentScoreboard: ServerScoreboard? = null

private var initializedMod = false

override fun onInitializeServer() {
ServerTickEvents.START_SERVER_TICK.register { tick ->
val scoreboard = tick.scoreboard
if (!scoreboard.teamNames.contains(Dimension.TheNether.id)) {
scoreboard.addTeam(Dimension.TheNether.id)
scoreboard.getTeam(Dimension.TheNether.id)!!.suffix = makeText("the_nether")
this.currentScoreboard = tick.scoreboard
if (!this.initializedMod) {
this.initializeMod()
this.initializedMod = true
}
if (!this.currentScoreboard!!.teamNames.contains(Dimension.TheNether.id)) {
this.currentScoreboard!!.addTeam(Dimension.TheNether.id)
this.currentScoreboard!!.getTeam(Dimension.TheNether.id)!!.suffix = makeText("the_nether")
}
if (!scoreboard.teamNames.contains(Dimension.TheEnd.id)) {
scoreboard.addTeam(Dimension.TheEnd.id)
scoreboard.getTeam(Dimension.TheEnd.id)!!.suffix = makeText("the_end")
if (!this.currentScoreboard!!.teamNames.contains(Dimension.TheEnd.id)) {
this.currentScoreboard!!.addTeam(Dimension.TheEnd.id)
this.currentScoreboard!!.getTeam(Dimension.TheEnd.id)!!.suffix = makeText("the_end")
}
if (!scoreboard.teamNames.contains(Dimension.Overworld.id)) {
scoreboard.addTeam(Dimension.Overworld.id)
scoreboard.getTeam(Dimension.Overworld.id)!!.suffix = makeText("overworld")
if (!this.currentScoreboard!!.teamNames.contains(Dimension.Overworld.id)) {
this.currentScoreboard!!.addTeam(Dimension.Overworld.id)
this.currentScoreboard!!.getTeam(Dimension.Overworld.id)!!.suffix = makeText("overworld")
}

val playerList = tick.playerManager.playerList
playerList.forEach { p ->
val currentDimension = p.world.dimensionKey.value.path
scoreboard.addPlayerToTeam(p.entityName.toString(), Team(scoreboard, currentDimension))
this.currentScoreboard!!.addPlayerToTeam(
p.entityName.toString(),
Team(this.currentScoreboard!!, currentDimension)
)
}
}
}

private fun initializeMod() {
for (i in Dimension.values().iterator()) {
this.currentScoreboard!!.removeTeam(Team(this.currentScoreboard, i.id))
}
}

private fun makeText(dimension: String): MutableText {
val header = Text.literal(" <").styled { it.withBold(true).withItalic(true).withColor(Formatting.GRAY) }
val dimensionText: Text = when (dimension) {
Expand All @@ -56,7 +75,7 @@ class ViewDimension : DedicatedServerModInitializer {
"the_nether" -> Text.literal("下界")
.styled { it.withBold(true).withItalic(true).withColor(Formatting.RED) }

else -> Text.translatable("末地")
else -> Text.literal("末地")
.styled { it.withBold(true).withItalic(true).withColor(Formatting.DARK_PURPLE) }
}
val footer = Text.literal("> ").styled { it.withBold(true).withItalic(true).withColor(Formatting.GRAY) }
Expand Down

0 comments on commit 0fbc1b5

Please sign in to comment.