mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-15 18:34:56 -04:00
network: unify vibration source reading
This commit is contained in:
parent
fd3fa6f298
commit
93e956828c
@ -16,18 +16,15 @@ import de.bixilon.minosoft.data.registries.particle.ParticleType
|
||||
import de.bixilon.minosoft.protocol.protocol.buffers.play.PlayInByteBuffer
|
||||
|
||||
class VibrationParticleData(val source: Any, val arrival: Int, type: ParticleType) : ParticleData(type) {
|
||||
|
||||
override fun toString(): String {
|
||||
return "$type: $source in $arrival"
|
||||
}
|
||||
|
||||
companion object : ParticleDataFactory<VibrationParticleData> {
|
||||
|
||||
override fun read(buffer: PlayInByteBuffer, type: ParticleType): VibrationParticleData {
|
||||
val sourceType = buffer.readResourceLocation()
|
||||
val source: Any = when (sourceType.toString()) { // TODO: combine with VibrationS2CP
|
||||
"minecraft:block" -> buffer.readBlockPosition()
|
||||
"minecraft:entity" -> buffer.readEntityId()
|
||||
else -> error("Unknown target type: $sourceType")
|
||||
}
|
||||
val source = buffer.readVibrationSource()
|
||||
val arrival = buffer.readVarInt()
|
||||
return VibrationParticleData(source, arrival, type)
|
||||
}
|
||||
|
@ -13,7 +13,6 @@
|
||||
package de.bixilon.minosoft.protocol.packets.s2c.play
|
||||
|
||||
import de.bixilon.kotlinglm.vec3.Vec3i
|
||||
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
|
||||
import de.bixilon.minosoft.protocol.packets.factory.LoadPacket
|
||||
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket
|
||||
import de.bixilon.minosoft.protocol.protocol.buffers.play.PlayInByteBuffer
|
||||
@ -24,19 +23,13 @@ import de.bixilon.minosoft.util.logging.LogMessageType
|
||||
@LoadPacket
|
||||
class VibrationS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
|
||||
val sourcePosition: Vec3i = buffer.readBlockPosition()
|
||||
val targetType: ResourceLocation = buffer.readResourceLocation()
|
||||
|
||||
/**
|
||||
* @return Depends on vibration target type, if block: block postion, if entity: entity id
|
||||
*/
|
||||
val targetData: Any = when (targetType.toString()) { // todo: combine with VibrationParticleData
|
||||
"minecraft:block" -> buffer.readBlockPosition()
|
||||
"minecraft:entity" -> buffer.readEntityId()
|
||||
else -> error("Unknown target type: $targetType")
|
||||
}
|
||||
val arrivalTicks: Int = buffer.readVarInt()
|
||||
val target = buffer.readVibrationSource()
|
||||
val arrival: Int = buffer.readVarInt()
|
||||
|
||||
override fun log(reducedLog: Boolean) {
|
||||
Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Vibration signal (sourcePosition=$sourcePosition, targetType=$targetType, targetData=$targetData, arrivalTicks=$arrivalTicks)" }
|
||||
Log.log(
|
||||
LogMessageType.NETWORK_PACKETS_IN,
|
||||
level = LogLevels.VERBOSE
|
||||
) { "Vibration signal (sourcePosition=$sourcePosition, target=$target, arrival=$arrival)" }
|
||||
}
|
||||
}
|
||||
|
@ -334,4 +334,15 @@ class PlayInByteBuffer : InByteBuffer {
|
||||
fun readVelocity(): Vec3d {
|
||||
return Vec3d(readShort(), readShort(), readShort()) / ProtocolDefinition.VELOCITY_NETWORK_DIVIDER
|
||||
}
|
||||
|
||||
fun readVibrationSource(): Any {
|
||||
val type = readResourceLocation()
|
||||
val source: Any = when (type.toString()) { // TODO: dynamic, factories
|
||||
"minecraft:block" -> readBlockPosition()
|
||||
"minecraft:entity" -> readEntityId()
|
||||
else -> error("Unknown vibration source: $type")
|
||||
}
|
||||
|
||||
return source
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user