mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-19 04:15:14 -04:00
load statistic registry, fix some bugs
This commit is contained in:
parent
68e52c5182
commit
e3ce5a6c68
@ -73,7 +73,7 @@ class Registries {
|
||||
val enchantmentRegistry: Registry<Enchantment> = register("enchantment", Registry(codec = Enchantment))
|
||||
val particleTypeRegistry: Registry<ParticleType> = register("particle_type", Registry(codec = ParticleType))
|
||||
val statusEffectRegistry: Registry<StatusEffect> = register("mob_effect", Registry(codec = StatusEffect))
|
||||
val statisticRegistry: Registry<Statistic> = register("custom_stat", Registry())
|
||||
val statisticRegistry: Registry<Statistic> = register("custom_stat", Registry(codec = Statistic))
|
||||
val biomeRegistry: Registry<Biome> = register("biome", Registry(codec = Biome))
|
||||
val dimensionRegistry: Registry<Dimension> = register("dimension_type", Registry(codec = Dimension))
|
||||
val materialRegistry: Registry<Material> = register("material", Registry(codec = Material))
|
||||
@ -196,6 +196,8 @@ class Registries {
|
||||
worker += Task(this::catVariants) { catVariants.rawUpdate(pixlyzerData["variant/cat"]?.toJsonObject(), this) }
|
||||
worker += Task(this::frogVariants) { frogVariants.rawUpdate(pixlyzerData["variant/frog"]?.toJsonObject(), this) }
|
||||
|
||||
worker += Task(this::statisticRegistry) { statisticRegistry.rawUpdate(pixlyzerData["statistics"]?.toJsonObject(), this) }
|
||||
|
||||
val inner = CountUpAndDownLatch(1, latch)
|
||||
worker.work(inner)
|
||||
inner.dec()
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2021 Moritz Zwerger
|
||||
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
@ -15,6 +15,9 @@ package de.bixilon.minosoft.data.registries.statistics
|
||||
|
||||
import de.bixilon.minosoft.data.registries.ResourceLocation
|
||||
|
||||
data class SubStatistic(
|
||||
val resourceLocation: ResourceLocation,
|
||||
)
|
||||
class CustomStatistic(
|
||||
resourceLocation: ResourceLocation,
|
||||
translationKey: ResourceLocation?,
|
||||
unit: StatisticUnits,
|
||||
val custom: Set<ResourceLocation>,
|
||||
) : Statistic(resourceLocation, translationKey, unit)
|
@ -12,18 +12,47 @@
|
||||
*/
|
||||
package de.bixilon.minosoft.data.registries.statistics
|
||||
|
||||
import de.bixilon.kutil.cast.CastUtil.unsafeCast
|
||||
import de.bixilon.minosoft.data.language.Translatable
|
||||
import de.bixilon.minosoft.data.registries.ResourceLocation
|
||||
import de.bixilon.minosoft.data.registries.registries.Registries
|
||||
import de.bixilon.minosoft.data.registries.registries.registry.RegistryItem
|
||||
import de.bixilon.minosoft.data.registries.registries.registry.codec.ResourceLocationCodec
|
||||
import de.bixilon.minosoft.util.KUtil.toResourceLocation
|
||||
|
||||
data class Statistic(
|
||||
open class Statistic(
|
||||
override val resourceLocation: ResourceLocation,
|
||||
override val translationKey: ResourceLocation?,
|
||||
val unit: StatisticUnits,
|
||||
@Deprecated("TODO") val subStatistics: Map<ResourceLocation, SubStatistic>,
|
||||
) : RegistryItem(), Translatable {
|
||||
|
||||
override fun toString(): String {
|
||||
return resourceLocation.full
|
||||
}
|
||||
|
||||
companion object : ResourceLocationCodec<Statistic> {
|
||||
override fun deserialize(registries: Registries?, resourceLocation: ResourceLocation, data: Map<String, Any>): Statistic {
|
||||
val translationKey = data["translation_id"]?.toResourceLocation()
|
||||
val unit = StatisticUnits[data["unit"]!!]!!
|
||||
|
||||
data["sub_statistics"]?.unsafeCast<Set<*>>()?.let {
|
||||
val custom: MutableSet<ResourceLocation> = mutableSetOf()
|
||||
for (value in it) {
|
||||
custom += value.toResourceLocation()
|
||||
}
|
||||
return CustomStatistic(
|
||||
resourceLocation = resourceLocation,
|
||||
translationKey = translationKey,
|
||||
unit = unit,
|
||||
custom = custom,
|
||||
)
|
||||
}
|
||||
|
||||
return Statistic(
|
||||
resourceLocation = resourceLocation,
|
||||
translationKey = translationKey,
|
||||
unit = unit,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2021 Moritz Zwerger
|
||||
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
@ -13,9 +13,18 @@
|
||||
|
||||
package de.bixilon.minosoft.data.registries.statistics
|
||||
|
||||
import de.bixilon.kutil.enums.EnumUtil
|
||||
import de.bixilon.kutil.enums.ValuesEnum
|
||||
|
||||
enum class StatisticUnits {
|
||||
BLOCK,
|
||||
ITEM,
|
||||
ENTITY_TYPE,
|
||||
CUSTOM,
|
||||
;
|
||||
|
||||
companion object : ValuesEnum<StatisticUnits> {
|
||||
override val VALUES: Array<StatisticUnits> = values()
|
||||
override val NAME_MAP: Map<String, StatisticUnits> = EnumUtil.getEnumValues(VALUES)
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,6 @@ package de.bixilon.minosoft.modding.event.events
|
||||
|
||||
import de.bixilon.kutil.cast.CastUtil.unsafeCast
|
||||
import de.bixilon.minosoft.data.entities.entities.Entity
|
||||
import de.bixilon.minosoft.data.entities.entities.LivingEntity
|
||||
import de.bixilon.minosoft.modding.event.EventInitiators
|
||||
import de.bixilon.minosoft.modding.event.events.connection.play.PlayConnectionEvent
|
||||
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||
@ -24,9 +23,9 @@ class CollectItemAnimationEvent(
|
||||
connection: PlayConnection,
|
||||
initiator: EventInitiators,
|
||||
val collectedEntity: Entity,
|
||||
val collector: LivingEntity,
|
||||
val collector: Entity,
|
||||
val count: Int,
|
||||
) : PlayConnectionEvent(connection, initiator), CancelableEvent {
|
||||
|
||||
constructor(connection: PlayConnection, packet: EntityCollectS2CP) : this(connection, EventInitiators.SERVER, connection.world.entities[packet.itemEntityId].unsafeCast<Entity>(), connection.world.entities[packet.collectorEntityId].unsafeCast<LivingEntity>(), packet.count)
|
||||
constructor(connection: PlayConnection, packet: EntityCollectS2CP) : this(connection, EventInitiators.SERVER, connection.world.entities[packet.itemEntityId].unsafeCast<Entity>(), connection.world.entities[packet.collectorEntityId].unsafeCast<Entity>(), packet.count)
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ class BlockDataS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
|
||||
val type = if (buffer.versionId >= V_21W37A) {
|
||||
buffer.connection.registries.blockEntityTypeRegistry[buffer.readVarInt()].resourceLocation
|
||||
} else {
|
||||
buffer.connection.registries.blockDataTypeRegistry[buffer.readUnsignedByte()].resourceLocation
|
||||
buffer.connection.registries.blockDataTypeRegistry.getOrNull(buffer.readUnsignedByte())?.resourceLocation
|
||||
}
|
||||
val nbt = buffer.readNBT().toJsonObject()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user