mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-14 01:48:04 -04:00
improve tag reading
This commit is contained in:
parent
5fbe97c1ee
commit
6bec745340
@ -190,7 +190,7 @@ object DefaultEntityFactories {
|
|||||||
|
|
||||||
val tweakedFactory = ENTITY_FACTORY_MAP[tweakedResourceLocation] ?: throw UnknownEntityException("Can not find tweaked entity type: $tweakedResourceLocation for $factory")
|
val tweakedFactory = ENTITY_FACTORY_MAP[tweakedResourceLocation] ?: throw UnknownEntityException("Can not find tweaked entity type: $tweakedResourceLocation for $factory")
|
||||||
|
|
||||||
val tweakedEntityType = connection.mapping.entityRegistry[tweakedResourceLocation] ?: throw UnknownEntityException("Can not find tweaked entity type data in ${connection.version}: $tweakedResourceLocation for $factory")
|
val tweakedEntityType = connection.mapping.entityTypeRegistry[tweakedResourceLocation] ?: throw UnknownEntityException("Can not find tweaked entity type data in ${connection.version}: $tweakedResourceLocation for $factory")
|
||||||
return tweakedFactory.build(connection, tweakedEntityType, position, rotation)
|
return tweakedFactory.build(connection, tweakedEntityType, position, rotation)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ package de.bixilon.minosoft.data
|
|||||||
|
|
||||||
import de.bixilon.minosoft.data.mappings.ResourceLocation
|
import de.bixilon.minosoft.data.mappings.ResourceLocation
|
||||||
|
|
||||||
data class Tag(
|
data class Tag<T>(
|
||||||
val resourceLocation: ResourceLocation,
|
val resourceLocation: ResourceLocation,
|
||||||
val ids: IntArray,
|
val ids: Set<T>,
|
||||||
)
|
)
|
||||||
|
@ -37,7 +37,7 @@ open class Registry<T : RegistryItem>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
open operator fun get(id: Int): T {
|
open operator fun get(id: Int): T {
|
||||||
return idValueMap[id] ?: parentRegistry?.get(id)!!
|
return idValueMap[id] ?: parentRegistry?.get(id) ?: throw NullPointerException("Can not find item with id $id")
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun getId(value: T): Int {
|
open fun getId(value: T): Int {
|
||||||
|
@ -91,7 +91,7 @@ class VersionMapping {
|
|||||||
val blockStateIdMap: MutableMap<Int, BlockState> = mutableMapOf()
|
val blockStateIdMap: MutableMap<Int, BlockState> = mutableMapOf()
|
||||||
|
|
||||||
val entityMetaIndexMap: MutableMap<EntityMetaDataFields, Int> = mutableMapOf()
|
val entityMetaIndexMap: MutableMap<EntityMetaDataFields, Int> = mutableMapOf()
|
||||||
val entityRegistry: Registry<EntityType> = Registry()
|
val entityTypeRegistry: Registry<EntityType> = Registry()
|
||||||
|
|
||||||
val blockEntityTypeRegistry = BlockEntityTypeRegistry()
|
val blockEntityTypeRegistry = BlockEntityTypeRegistry()
|
||||||
val blockEntityMetaDataTypeRegistry: Registry<BlockEntityMetaType> = Registry()
|
val blockEntityMetaDataTypeRegistry: Registry<BlockEntityMetaType> = Registry()
|
||||||
@ -190,7 +190,7 @@ class VersionMapping {
|
|||||||
|
|
||||||
villagerProfessionRegistry.initialize(pixlyzerData["villager_professions"]?.asJsonObject, this, VillagerProfession)
|
villagerProfessionRegistry.initialize(pixlyzerData["villager_professions"]?.asJsonObject, this, VillagerProfession)
|
||||||
|
|
||||||
entityRegistry.initialize(pixlyzerData["entities"]?.asJsonObject, this, EntityType)
|
entityTypeRegistry.initialize(pixlyzerData["entities"]?.asJsonObject, this, EntityType)
|
||||||
|
|
||||||
blockEntityMetaDataTypeRegistry.initialize(pixlyzerData["block_entity_meta_data_types"]?.asJsonObject, this, BlockEntityMetaType, alternative = DefaultRegistries.BLOCK_ENTITY_META_TYPE_REGISTRY.forVersion(version))
|
blockEntityMetaDataTypeRegistry.initialize(pixlyzerData["block_entity_meta_data_types"]?.asJsonObject, this, BlockEntityMetaType, alternative = DefaultRegistries.BLOCK_ENTITY_META_TYPE_REGISTRY.forVersion(version))
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ class Player(
|
|||||||
val healthCondition = PlayerHealthCondition()
|
val healthCondition = PlayerHealthCondition()
|
||||||
val experienceCondition = PlayerExperienceCondition()
|
val experienceCondition = PlayerExperienceCondition()
|
||||||
var spawnPosition: Vec3i = VecUtil.EMPTY_VEC3I
|
var spawnPosition: Vec3i = VecUtil.EMPTY_VEC3I
|
||||||
val entity: PlayerEntity = PlayerEntity(connection, connection.mapping.entityRegistry[PlayerEntity.RESOURCE_LOCATION]!!, VecUtil.EMPTY_VEC3, EntityRotation(0.0, 0.0), account.username)
|
val entity: PlayerEntity = PlayerEntity(connection, connection.mapping.entityTypeRegistry[PlayerEntity.RESOURCE_LOCATION]!!, VecUtil.EMPTY_VEC3, EntityRotation(0.0, 0.0), account.username)
|
||||||
|
|
||||||
@Deprecated(message = "Will be replaced with some kind of teleport manager, ...")
|
@Deprecated(message = "Will be replaced with some kind of teleport manager, ...")
|
||||||
var isSpawnConfirmed = false
|
var isSpawnConfirmed = false
|
||||||
|
@ -61,9 +61,9 @@ class EntityObjectSpawnS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
|
|||||||
}
|
}
|
||||||
entity = if (buffer.versionId < ProtocolVersions.V_19W05A) {
|
entity = if (buffer.versionId < ProtocolVersions.V_19W05A) {
|
||||||
val entityResourceLocation = ENTITY_OBJECT_REGISTRY[type].resourceLocation
|
val entityResourceLocation = ENTITY_OBJECT_REGISTRY[type].resourceLocation
|
||||||
buffer.connection.mapping.entityRegistry[entityResourceLocation]!!.build(buffer.connection, position, rotation, null, buffer.versionId)!! // ToDo: Entity meta data tweaking
|
buffer.connection.mapping.entityTypeRegistry[entityResourceLocation]!!.build(buffer.connection, position, rotation, null, buffer.versionId)!! // ToDo: Entity meta data tweaking
|
||||||
} else {
|
} else {
|
||||||
buffer.connection.mapping.entityRegistry[type].build(buffer.connection, position, rotation, null, buffer.versionId)!!
|
buffer.connection.mapping.entityTypeRegistry[type].build(buffer.connection, position, rotation, null, buffer.versionId)!!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ class ExperienceOrbSpawnS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
|
|||||||
val entityId: Int = buffer.readEntityId()
|
val entityId: Int = buffer.readEntityId()
|
||||||
val entity: ExperienceOrb = ExperienceOrb(
|
val entity: ExperienceOrb = ExperienceOrb(
|
||||||
connection = buffer.connection,
|
connection = buffer.connection,
|
||||||
entityType = buffer.connection.mapping.entityRegistry[ExperienceOrb.RESOURCE_LOCATION]!!,
|
entityType = buffer.connection.mapping.entityTypeRegistry[ExperienceOrb.RESOURCE_LOCATION]!!,
|
||||||
position = if (buffer.versionId < ProtocolVersions.V_16W06A) {
|
position = if (buffer.versionId < ProtocolVersions.V_16W06A) {
|
||||||
Vec3(buffer.readFixedPointNumberInt(), buffer.readFixedPointNumberInt(), buffer.readFixedPointNumberInt())
|
Vec3(buffer.readFixedPointNumberInt(), buffer.readFixedPointNumberInt(), buffer.readFixedPointNumberInt())
|
||||||
} else {
|
} else {
|
||||||
|
@ -35,7 +35,7 @@ class GlobalEntitySpawnS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
|
|||||||
buffer.readPosition()
|
buffer.readPosition()
|
||||||
}
|
}
|
||||||
|
|
||||||
entity = LightningBolt(buffer.connection, buffer.connection.mapping.entityRegistry[LightningBolt.RESOURCE_LOCATION]!!, position)
|
entity = LightningBolt(buffer.connection, buffer.connection.mapping.entityTypeRegistry[LightningBolt.RESOURCE_LOCATION]!!, position)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun handle(connection: PlayConnection) {
|
override fun handle(connection: PlayConnection) {
|
||||||
|
@ -55,7 +55,7 @@ class MobSpawnS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
|
|||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
val entityType = buffer.connection.mapping.entityRegistry[typeId]
|
val entityType = buffer.connection.mapping.entityTypeRegistry[typeId]
|
||||||
entity = entityType.build(buffer.connection, position, rotation, metaData, buffer.versionId)!!
|
entity = entityType.build(buffer.connection, position, rotation, metaData, buffer.versionId)!!
|
||||||
entity.velocity = velocity
|
entity.velocity = velocity
|
||||||
metaData?.let {
|
metaData?.let {
|
||||||
|
@ -52,7 +52,7 @@ class PaintingSpawnS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
|
|||||||
position = buffer.readBlockPosition()
|
position = buffer.readBlockPosition()
|
||||||
direction = byId(buffer.readUnsignedByte())
|
direction = byId(buffer.readUnsignedByte())
|
||||||
}
|
}
|
||||||
entity = Painting(buffer.connection, buffer.connection.mapping.entityRegistry[Painting.RESOURCE_LOCATION]!!, position, direction, motive!!)
|
entity = Painting(buffer.connection, buffer.connection.mapping.entityTypeRegistry[Painting.RESOURCE_LOCATION]!!, position, direction, motive!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun handle(connection: PlayConnection) {
|
override fun handle(connection: PlayConnection) {
|
||||||
|
@ -68,7 +68,7 @@ class PlayerEntitySpawnS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
|
|||||||
}
|
}
|
||||||
entity = PlayerEntity(
|
entity = PlayerEntity(
|
||||||
connection = buffer.connection,
|
connection = buffer.connection,
|
||||||
entityType = buffer.connection.mapping.entityRegistry[PlayerEntity.RESOURCE_LOCATION]!!,
|
entityType = buffer.connection.mapping.entityTypeRegistry[PlayerEntity.RESOURCE_LOCATION]!!,
|
||||||
position = position,
|
position = position,
|
||||||
rotation = EntityRotation(yaw.toFloat(), pitch.toFloat(), 0.0f),
|
rotation = EntityRotation(yaw.toFloat(), pitch.toFloat(), 0.0f),
|
||||||
name = name,
|
name = name,
|
||||||
|
@ -23,23 +23,29 @@ import de.bixilon.minosoft.util.logging.LogLevels
|
|||||||
import de.bixilon.minosoft.util.logging.LogMessageType
|
import de.bixilon.minosoft.util.logging.LogMessageType
|
||||||
|
|
||||||
class TagsS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
|
class TagsS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
|
||||||
val tags: Map<ResourceLocation, List<Tag>>
|
val tags: Map<ResourceLocation, List<Tag<Any>>>
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val tags: MutableMap<ResourceLocation, List<Tag>> = mutableMapOf()
|
val tags: MutableMap<ResourceLocation, List<Tag<Any>>> = mutableMapOf()
|
||||||
if (buffer.versionId < ProtocolVersions.V_20W51A) {
|
if (buffer.versionId < ProtocolVersions.V_20W51A) {
|
||||||
tags[BLOCK_TAG_RESOURCE_LOCATION] = buffer.readTagArray().toList()
|
tags[BLOCK_TAG_RESOURCE_LOCATION] = buffer.readTagArray { buffer.connection.mapping.getBlockState(it)!! }
|
||||||
tags[ITEM_TAG_RESOURCE_LOCATION] = buffer.readTagArray().toList()
|
tags[ITEM_TAG_RESOURCE_LOCATION] = buffer.readTagArray { buffer.connection.mapping.itemRegistry[it] }
|
||||||
tags[FLUID_TAG_RESOURCE_LOCATION] = buffer.readTagArray().toList() // ToDo: when was this added? Was not available in 18w01
|
tags[FLUID_TAG_RESOURCE_LOCATION] = buffer.readTagArray { buffer.connection.mapping.fluidRegistry[it] } // ToDo: when was this added? Was not available in 18w01
|
||||||
if (buffer.versionId >= ProtocolVersions.V_18W43A) {
|
if (buffer.versionId >= ProtocolVersions.V_18W43A) {
|
||||||
tags[ENTITY_TYPE_TAG_RESOURCE_LOCATION] = buffer.readTagArray().toList()
|
tags[ENTITY_TYPE_TAG_RESOURCE_LOCATION] = buffer.readTagArray { buffer.connection.mapping.entityTypeRegistry[it] }
|
||||||
}
|
}
|
||||||
if (buffer.versionId >= ProtocolVersions.V_20W49A) {
|
if (buffer.versionId >= ProtocolVersions.V_20W49A) {
|
||||||
tags[GAME_EVENT_TAG_RESOURCE_LOCATION] = buffer.readTagArray().toList()
|
tags[GAME_EVENT_TAG_RESOURCE_LOCATION] = buffer.readTagArray { it }
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (i in 0 until buffer.readVarInt()) {
|
for (i in 0 until buffer.readVarInt()) {
|
||||||
tags[buffer.readResourceLocation()] = buffer.readTagArray().toList()
|
when (buffer.readResourceLocation()) {
|
||||||
|
BLOCK_TAG_RESOURCE_LOCATION -> buffer.readTagArray { buffer.connection.mapping.blockRegistry[it] }
|
||||||
|
ITEM_TAG_RESOURCE_LOCATION -> buffer.readTagArray { buffer.connection.mapping.itemRegistry[it] }
|
||||||
|
FLUID_TAG_RESOURCE_LOCATION -> buffer.readTagArray { buffer.connection.mapping.fluidRegistry[it] }
|
||||||
|
ENTITY_TYPE_TAG_RESOURCE_LOCATION -> buffer.readTagArray { buffer.connection.mapping.entityTypeRegistry[it] }
|
||||||
|
GAME_EVENT_TAG_RESOURCE_LOCATION -> buffer.readTagArray { it }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.tags = tags.toMap()
|
this.tags = tags.toMap()
|
||||||
|
@ -409,12 +409,18 @@ open class InByteBuffer {
|
|||||||
return String(Base64.getEncoder().encode(readRest()))
|
return String(Base64.getEncoder().encode(readRest()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun readTag(): Tag {
|
fun <T> readTag(idResolver: (Int) -> T): Tag<T> {
|
||||||
return Tag(readResourceLocation(), readVarIntArray())
|
val resourceLocation = readResourceLocation()
|
||||||
|
val ids = readVarIntArray()
|
||||||
|
val items: MutableSet<T> = mutableSetOf()
|
||||||
|
for (id in ids) {
|
||||||
|
items += idResolver(id)
|
||||||
|
}
|
||||||
|
return Tag(resourceLocation, items.toSet())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun readTagArray(length: Int = readVarInt()): Array<Tag> {
|
fun <T> readTagArray(length: Int = readVarInt(), idResolver: (Int) -> T): List<Tag<T>> {
|
||||||
return readArray(length) { readTag() }
|
return (readArray(length) { readTag(idResolver) }).toList()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <T> readOptional(reader: () -> T): T? {
|
fun <T> readOptional(reader: () -> T): T? {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user