mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-19 04:15:14 -04:00
dynamic vibration sources
Done with factories now
This commit is contained in:
parent
1d5c27723c
commit
67722f8e78
@ -13,9 +13,14 @@
|
|||||||
package de.bixilon.minosoft.data.registries.particle.data
|
package de.bixilon.minosoft.data.registries.particle.data
|
||||||
|
|
||||||
import de.bixilon.minosoft.data.registries.particle.ParticleType
|
import de.bixilon.minosoft.data.registries.particle.ParticleType
|
||||||
|
import de.bixilon.minosoft.data.registries.particle.data.vibration.VibrationSource
|
||||||
import de.bixilon.minosoft.protocol.protocol.buffers.play.PlayInByteBuffer
|
import de.bixilon.minosoft.protocol.protocol.buffers.play.PlayInByteBuffer
|
||||||
|
|
||||||
class VibrationParticleData(val source: Any, val arrival: Int, type: ParticleType) : ParticleData(type) {
|
class VibrationParticleData(
|
||||||
|
val source: VibrationSource,
|
||||||
|
val arrival: Int,
|
||||||
|
type: ParticleType,
|
||||||
|
) : ParticleData(type) {
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return "$type: $source in $arrival"
|
return "$type: $source in $arrival"
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Minosoft
|
||||||
|
* Copyright (C) 2020-2023 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.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.bixilon.minosoft.data.registries.particle.data.vibration
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.data.registries.identified.Namespaces.minecraft
|
||||||
|
import de.bixilon.minosoft.data.world.positions.BlockPosition
|
||||||
|
import de.bixilon.minosoft.protocol.protocol.buffers.play.PlayInByteBuffer
|
||||||
|
|
||||||
|
class BlockSource(
|
||||||
|
val position: BlockPosition,
|
||||||
|
) : VibrationSource {
|
||||||
|
|
||||||
|
companion object : VibrationFactory<BlockSource> {
|
||||||
|
override val identifier = minecraft("block")
|
||||||
|
|
||||||
|
override fun read(buffer: PlayInByteBuffer): BlockSource {
|
||||||
|
val position = buffer.readBlockPosition()
|
||||||
|
|
||||||
|
return BlockSource(position)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Minosoft
|
||||||
|
* Copyright (C) 2020-2023 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.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.bixilon.minosoft.data.registries.particle.data.vibration
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.data.registries.identified.Namespaces.minecraft
|
||||||
|
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions.V_1_20_1
|
||||||
|
import de.bixilon.minosoft.protocol.protocol.buffers.play.PlayInByteBuffer
|
||||||
|
|
||||||
|
class EntitySource(
|
||||||
|
val entityId: Int,
|
||||||
|
val yOffset: Float = 0.0f,
|
||||||
|
) : VibrationSource {
|
||||||
|
|
||||||
|
companion object : VibrationFactory<EntitySource> {
|
||||||
|
override val identifier = minecraft("entity")
|
||||||
|
|
||||||
|
override fun read(buffer: PlayInByteBuffer): EntitySource {
|
||||||
|
val entityId = buffer.readEntityId()
|
||||||
|
val yOffset = if (buffer.versionId >= V_1_20_1) buffer.readFloat() else 0.0f // TODO: version guessed. Present in 1.20.2
|
||||||
|
|
||||||
|
return EntitySource(entityId, yOffset)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* Minosoft
|
||||||
|
* Copyright (C) 2020-2023 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.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.bixilon.minosoft.data.registries.particle.data.vibration
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.data.registries.identified.Identified
|
||||||
|
import de.bixilon.minosoft.protocol.protocol.buffers.play.PlayInByteBuffer
|
||||||
|
|
||||||
|
interface VibrationFactory<V : VibrationSource> : Identified {
|
||||||
|
|
||||||
|
fun read(buffer: PlayInByteBuffer): V
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
/*
|
||||||
|
* Minosoft
|
||||||
|
* Copyright (C) 2020-2023 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.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.bixilon.minosoft.data.registries.particle.data.vibration
|
||||||
|
|
||||||
|
interface VibrationSource
|
@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Minosoft
|
||||||
|
* Copyright (C) 2020-2023 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.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.bixilon.minosoft.data.registries.particle.data.vibration
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.data.registries.factory.DefaultFactory
|
||||||
|
import de.bixilon.minosoft.protocol.protocol.buffers.play.PlayInByteBuffer
|
||||||
|
|
||||||
|
object VibrationSources : DefaultFactory<VibrationFactory<*>>(
|
||||||
|
BlockSource,
|
||||||
|
EntitySource,
|
||||||
|
) {
|
||||||
|
|
||||||
|
fun read(buffer: PlayInByteBuffer): VibrationSource {
|
||||||
|
val type = buffer.readResourceLocation()
|
||||||
|
val factory = this[type] ?: throw IllegalArgumentException("Can not find vibration source: $type")
|
||||||
|
|
||||||
|
return factory.read(buffer)
|
||||||
|
}
|
||||||
|
}
|
@ -25,9 +25,6 @@ class VibrationS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
|
|||||||
val arrival: Int = buffer.readVarInt()
|
val arrival: Int = buffer.readVarInt()
|
||||||
|
|
||||||
override fun log(reducedLog: Boolean) {
|
override fun log(reducedLog: Boolean) {
|
||||||
Log.log(
|
Log.log(LogMessageType.NETWORK_IN, level = LogLevels.VERBOSE) { "Vibration signal (sourcePosition=$sourcePosition, target=$target, arrival=$arrival)" }
|
||||||
LogMessageType.NETWORK_IN,
|
|
||||||
level = LogLevels.VERBOSE
|
|
||||||
) { "Vibration signal (sourcePosition=$sourcePosition, target=$target, arrival=$arrival)" }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,8 @@ import de.bixilon.minosoft.data.entities.entities.player.properties.textures.Pla
|
|||||||
import de.bixilon.minosoft.data.registries.chat.ChatParameter
|
import de.bixilon.minosoft.data.registries.chat.ChatParameter
|
||||||
import de.bixilon.minosoft.data.registries.particle.ParticleType
|
import de.bixilon.minosoft.data.registries.particle.ParticleType
|
||||||
import de.bixilon.minosoft.data.registries.particle.data.*
|
import de.bixilon.minosoft.data.registries.particle.data.*
|
||||||
|
import de.bixilon.minosoft.data.registries.particle.data.vibration.VibrationSource
|
||||||
|
import de.bixilon.minosoft.data.registries.particle.data.vibration.VibrationSources
|
||||||
import de.bixilon.minosoft.data.registries.registries.registry.AbstractRegistry
|
import de.bixilon.minosoft.data.registries.registries.registry.AbstractRegistry
|
||||||
import de.bixilon.minosoft.data.registries.registries.registry.EnumRegistry
|
import de.bixilon.minosoft.data.registries.registries.registry.EnumRegistry
|
||||||
import de.bixilon.minosoft.data.registries.registries.registry.Registry
|
import de.bixilon.minosoft.data.registries.registries.registry.Registry
|
||||||
@ -375,15 +377,8 @@ class PlayInByteBuffer : InByteBuffer {
|
|||||||
return Vec3d(readShort(), readShort(), readShort()) / ProtocolDefinition.VELOCITY_NETWORK_DIVIDER
|
return Vec3d(readShort(), readShort(), readShort()) / ProtocolDefinition.VELOCITY_NETWORK_DIVIDER
|
||||||
}
|
}
|
||||||
|
|
||||||
fun readVibrationSource(): Any {
|
fun readVibrationSource(): VibrationSource {
|
||||||
val type = readResourceLocation()
|
return VibrationSources.read(this)
|
||||||
val source: Any = when (type.toString()) { // TODO: dynamic, factories
|
|
||||||
"minecraft:block" -> readBlockPosition()
|
|
||||||
"minecraft:entity" -> readEntityId()
|
|
||||||
else -> error("Unknown vibration source: $type")
|
|
||||||
}
|
|
||||||
|
|
||||||
return source
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun readLegacyBitSet(bytes: Int): BitSet {
|
fun readLegacyBitSet(bytes: Int): BitSet {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user