hud: fix some bugs

This commit is contained in:
Bixilon 2021-11-02 19:21:13 +01:00
parent 4d904e92e3
commit c84619ffb3
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
10 changed files with 23 additions and 30 deletions

View File

@ -157,7 +157,7 @@ abstract class Entity(
fun getAttributeValue(name: ResourceLocation, baseValue: Double? = null): Double {
// ToDo: Check order and verify value
val attribute = attributes[name]
val realBaseValue = baseValue ?: attribute?.baseValue ?: 1.0
val realBaseValue = baseValue ?: attribute?.baseValue ?: entityType.attributes[name] ?: 1.0
var ret = realBaseValue
fun addToValue(modifier: EntityAttributeModifier, amplifier: Int) {

View File

@ -36,6 +36,7 @@ data class BlockEntityType(
companion object : ResourceLocationDeserializer<BlockEntityType> {
override fun deserialize(registries: Registries?, resourceLocation: ResourceLocation, data: Map<String, Any>): BlockEntityType? {
// ToDo: Fix resource location
check(registries != null)
val factory = DefaultBlockEntityMetaDataFactory[resourceLocation] ?: return null // ToDo

View File

@ -30,6 +30,7 @@ open class Container(
protected val slots: MutableMap<Int, ItemStack> = synchronizedMapOf()
var revision = 0L // ToDo: This has nothing todo with minecraft (1.17+)
@Synchronized set(value) {
// ToDo: Proper synchronize
if (++field != value) {
error("Can not set a custom revision!: $value, required: $field")
}

View File

@ -14,6 +14,7 @@ package de.bixilon.minosoft.data.scoreboard
import de.bixilon.minosoft.modding.event.events.scoreboard.ScoreTeamChangeEvent
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import de.bixilon.minosoft.util.KUtil.decide
import de.bixilon.minosoft.util.KUtil.synchronizedMapOf
import de.bixilon.minosoft.util.KUtil.toSynchronizedMap
@ -24,28 +25,21 @@ class ScoreboardManager(private val connection: PlayConnection) {
val positions: MutableMap<ScoreboardPositions, ScoreboardObjective> = synchronizedMapOf()
fun getTeamsOf(member: String): Set<Team> {
val teams: MutableSet<Team> = mutableSetOf()
for ((_, team) in this.teams) {
if (!team.members.contains(member)) {
fun getTeam(member: String): Team? {
for ((_, team) in this.teams.toSynchronizedMap()) {
if (member !in team.members) {
continue
}
teams += team
return team
}
return teams
return null
}
fun updateScoreTeams(team: Team, members: Set<String>, remove: Boolean = false, fireEvent: Boolean = true) {
for ((_, objective) in objectives.toSynchronizedMap()) {
for ((_, score) in objective.scores.toSynchronizedMap()) {
if (score.entity in members) {
if (remove) {
score.teams -= team
} else {
score.teams += team
}
score.team = remove.decide(null, team)
if (!fireEvent) {
continue
}

View File

@ -15,9 +15,10 @@ package de.bixilon.minosoft.data.scoreboard
class ScoreboardScore(
val entity: String,
var objective: ScoreboardObjective,
val teams: MutableSet<Team>,
var team: Team?,
var value: Int,
) : Comparable<ScoreboardScore> {
override fun toString(): String {
return "$entity=$value"
}

View File

@ -45,13 +45,13 @@ class ScoreboardHUDElement(hudRenderer: HUDRenderer) : LayoutedHUDElement<Scoreb
layout.updateScore(it.score)
})
connection.registerEvent(CallbackEventInvoker.of<ScoreTeamChangeEvent> {
val objective = layout.objective ?: return@of
layout.objective ?: return@of
layout.updateScore(it.score)
})
connection.registerEvent(CallbackEventInvoker.of<TeamUpdateEvent> {
val objective = layout.objective ?: return@of
for ((_, score) in objective.scores) {
if (it.team !in score.teams) {
if (it.team != score.team) {
continue
}
layout.updateScore(score)

View File

@ -1,7 +1,6 @@
package de.bixilon.minosoft.gui.rendering.gui.hud.elements.scoreboard
import de.bixilon.minosoft.data.scoreboard.ScoreboardScore
import de.bixilon.minosoft.data.scoreboard.Team
import de.bixilon.minosoft.data.text.ChatColors
import de.bixilon.minosoft.data.text.ChatComponent
import de.bixilon.minosoft.data.text.TextComponent
@ -43,16 +42,8 @@ class ScoreboardScoreElement(
}
override fun forceSilentApply() {
// ToDo: Can a score (entity; whatever) can have multiple teams?
var team: Team? = null
score.teams.iterator().apply {
if (!hasNext()) {
return@apply
}
team = next()
}
val entityName = ChatComponent.of(score.entity)
nameElement.text = team?.decorateName(entityName) ?: entityName
nameElement.text = score.team?.decorateName(entityName) ?: entityName
scoreElement.text = TextComponent(score.value).color(ChatColors.RED)

View File

@ -34,6 +34,11 @@ class ScoreboardSideElement(hudRenderer: HUDRenderer) : Element(hudRenderer) {
forceSilentApply()
}
init {
_prefMaxSize = Vec2i(MAX_SCOREBOARD_WIDTH, -1)
forceSilentApply()
}
override fun forceRender(offset: Vec2i, z: Int, consumer: GUIVertexConsumer, options: GUIVertexOptions?): Int {
recalculateSize()
backgroundElement.render(offset, z, consumer, options)
@ -120,5 +125,6 @@ class ScoreboardSideElement(hudRenderer: HUDRenderer) : Element(hudRenderer) {
const val MAX_SCORES = 15
const val MIN_WIDTH = 30
const val SCORE_HEIGHT = Font.TOTAL_CHAR_HEIGHT
const val MAX_SCOREBOARD_WIDTH = 200
}
}

View File

@ -110,7 +110,7 @@ class ChunkDataS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
for (i in 0 until blockEntitiesCount) {
val nbt = buffer.readNBT().asCompound()
val position = Vec3i(nbt["x"]!!.toInt(), nbt["y"]!!.toInt(), nbt["z"]!!.toInt())
val resourceLocation = ResourceLocation(nbt["id"].unsafeCast<String>()).fix()
val resourceLocation = ResourceLocation(nbt["id"].unsafeCast()).fix()
val type = buffer.connection.registries.blockEntityTypeRegistry[resourceLocation] ?: let {
Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.WARN) { "Unknown block entity: $resourceLocation" }
null

View File

@ -19,7 +19,6 @@ import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions
import de.bixilon.minosoft.util.KUtil.toSynchronizedSet
import de.bixilon.minosoft.util.logging.Log
import de.bixilon.minosoft.util.logging.LogLevels
import de.bixilon.minosoft.util.logging.LogMessageType
@ -34,7 +33,7 @@ class PutScoreboardScoreS2CP(val entity: String, val objective: String?, buffer:
override fun handle(connection: PlayConnection) {
check(objective != null) { "Can not update null objective!" }
val objective = connection.scoreboardManager.objectives[objective] ?: return
val score = ScoreboardScore(entity, objective, connection.scoreboardManager.getTeamsOf(entity).toSynchronizedSet(), value)
val score = ScoreboardScore(entity, objective, connection.scoreboardManager.getTeam(entity), value)
objective.scores[entity] = score
connection.fireEvent(ScoreboardScorePutEvent(connection, score))