From bbf445d82b84d76174e266781a956987ba23ebba Mon Sep 17 00:00:00 2001 From: Bixilon Date: Sun, 9 Apr 2023 19:34:38 +0200 Subject: [PATCH] particle data: sculk, shriek, vibration --- .../particle/data/SculkChargeParticleData.kt | 29 +++++++++++++++ .../particle/data/ShriekParticleData.kt | 28 +++++++++++++++ .../particle/data/VibrationParticleData.kt | 35 +++++++++++++++++++ .../packets/s2c/play/VibrationS2CP.kt | 2 +- .../protocol/buffers/play/PlayInByteBuffer.kt | 13 +++---- 5 files changed, 100 insertions(+), 7 deletions(-) create mode 100644 src/main/java/de/bixilon/minosoft/data/registries/particle/data/SculkChargeParticleData.kt create mode 100644 src/main/java/de/bixilon/minosoft/data/registries/particle/data/ShriekParticleData.kt create mode 100644 src/main/java/de/bixilon/minosoft/data/registries/particle/data/VibrationParticleData.kt diff --git a/src/main/java/de/bixilon/minosoft/data/registries/particle/data/SculkChargeParticleData.kt b/src/main/java/de/bixilon/minosoft/data/registries/particle/data/SculkChargeParticleData.kt new file mode 100644 index 000000000..67c6ff949 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/registries/particle/data/SculkChargeParticleData.kt @@ -0,0 +1,29 @@ +/* + * 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 . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ +package de.bixilon.minosoft.data.registries.particle.data + +import de.bixilon.minosoft.data.registries.particle.ParticleType +import de.bixilon.minosoft.protocol.protocol.buffers.play.PlayInByteBuffer + +class SculkChargeParticleData(val roll: Float, type: ParticleType) : ParticleData(type) { + + override fun toString(): String { + return "$type: $roll" + } + + companion object : ParticleDataFactory { + override fun read(buffer: PlayInByteBuffer, type: ParticleType): SculkChargeParticleData { + return SculkChargeParticleData(buffer.readFloat(), type) + } + } +} diff --git a/src/main/java/de/bixilon/minosoft/data/registries/particle/data/ShriekParticleData.kt b/src/main/java/de/bixilon/minosoft/data/registries/particle/data/ShriekParticleData.kt new file mode 100644 index 000000000..20979180d --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/registries/particle/data/ShriekParticleData.kt @@ -0,0 +1,28 @@ +/* + * 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 . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ +package de.bixilon.minosoft.data.registries.particle.data + +import de.bixilon.minosoft.data.registries.particle.ParticleType +import de.bixilon.minosoft.protocol.protocol.buffers.play.PlayInByteBuffer + +class ShriekParticleData(val delay: Int, type: ParticleType) : ParticleData(type) { + override fun toString(): String { + return "$type: $delay" + } + + companion object : ParticleDataFactory { + override fun read(buffer: PlayInByteBuffer, type: ParticleType): ShriekParticleData { + return ShriekParticleData(buffer.readVarInt(), type) + } + } +} diff --git a/src/main/java/de/bixilon/minosoft/data/registries/particle/data/VibrationParticleData.kt b/src/main/java/de/bixilon/minosoft/data/registries/particle/data/VibrationParticleData.kt new file mode 100644 index 000000000..7250ac858 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/registries/particle/data/VibrationParticleData.kt @@ -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 . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ +package de.bixilon.minosoft.data.registries.particle.data + +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 { + 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 arrival = buffer.readVarInt() + return VibrationParticleData(source, arrival, type) + } + } +} diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/VibrationS2CP.kt b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/VibrationS2CP.kt index ac9eec241..df0ee56da 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/VibrationS2CP.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/VibrationS2CP.kt @@ -29,7 +29,7 @@ class VibrationS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket { /** * @return Depends on vibration target type, if block: block postion, if entity: entity id */ - val targetData: Any = when (targetType.toString()) { + val targetData: Any = when (targetType.toString()) { // todo: combine with VibrationParticleData "minecraft:block" -> buffer.readBlockPosition() "minecraft:entity" -> buffer.readEntityId() else -> error("Unknown target type: $targetType") diff --git a/src/main/java/de/bixilon/minosoft/protocol/protocol/buffers/play/PlayInByteBuffer.kt b/src/main/java/de/bixilon/minosoft/protocol/protocol/buffers/play/PlayInByteBuffer.kt index 0ce6f8f00..a293f5522 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/protocol/buffers/play/PlayInByteBuffer.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/buffers/play/PlayInByteBuffer.kt @@ -16,17 +16,15 @@ import de.bixilon.kotlinglm.vec3.Vec3d import de.bixilon.kotlinglm.vec3.Vec3i import de.bixilon.kutil.json.JsonUtil.asJsonObject import de.bixilon.kutil.json.JsonUtil.toMutableJsonObject -import de.bixilon.minosoft.data.chat.signature.* +import de.bixilon.minosoft.data.chat.signature.ChatSignatureProperties +import de.bixilon.minosoft.data.chat.signature.MessageHeader import de.bixilon.minosoft.data.container.ItemStackUtil import de.bixilon.minosoft.data.container.stack.ItemStack import de.bixilon.minosoft.data.entities.entities.player.properties.PlayerProperties import de.bixilon.minosoft.data.entities.entities.player.properties.textures.PlayerTextures import de.bixilon.minosoft.data.registries.chat.ChatParameter import de.bixilon.minosoft.data.registries.particle.ParticleType -import de.bixilon.minosoft.data.registries.particle.data.BlockParticleData -import de.bixilon.minosoft.data.registries.particle.data.DustParticleData -import de.bixilon.minosoft.data.registries.particle.data.ItemParticleData -import de.bixilon.minosoft.data.registries.particle.data.ParticleData +import de.bixilon.minosoft.data.registries.particle.data.* 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.Registry @@ -117,9 +115,12 @@ class PlayInByteBuffer : InByteBuffer { } return when (type.identifier.toString()) { - "minecraft:block", "minecraft:falling_dust" -> BlockParticleData.read(this, type) + "minecraft:block", "minecraft:falling_dust", "minecraft:block_marker" -> BlockParticleData.read(this, type) "minecraft:dust" -> DustParticleData.read(this, type) "minecraft:item" -> ItemParticleData.read(this, type) + "minecraft:shriek" -> ShriekParticleData.read(this, type) + "minecraft:sculk_charge" -> SculkChargeParticleData.read(this, type) + "minecraft:vibration" -> VibrationParticleData.read(this, type) else -> ParticleData(type) } }