From 8681fe703ae63773cf743c39a62ffed06c3a2c46 Mon Sep 17 00:00:00 2001 From: Shynixn Date: Fri, 22 Nov 2024 19:48:56 +0100 Subject: [PATCH 1/3] #632 Fixed riding packet network implementation. --- build.gradle.kts | 4 +- .../shynixn/petblocks/contract/Language.kt | 4 +- .../shynixn/petblocks/impl/PetEntityImpl.kt | 68 +++++++++++------ .../petblocks/impl/listener/PetListener.kt | 76 +++++-------------- 4 files changed, 70 insertions(+), 82 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index efaa2c461..aa3a71382 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -46,8 +46,8 @@ dependencies { // Custom dependencies implementation("com.github.shynixn.shygui:shygui:1.0.1") - implementation("com.github.shynixn.mcutils:common:2024.36") - implementation("com.github.shynixn.mcutils:packet:2024.47") + implementation("com.github.shynixn.mcutils:common:2024.37") + implementation("com.github.shynixn.mcutils:packet:2024.49") implementation("com.github.shynixn.mcutils:database:2024.8") implementation("com.github.shynixn.mcutils:pathfinder:2024.3") implementation("com.github.shynixn.mcutils:guice:2024.2") diff --git a/src/main/java/com/github/shynixn/petblocks/contract/Language.kt b/src/main/java/com/github/shynixn/petblocks/contract/Language.kt index bd16510ff..1173f57d2 100644 --- a/src/main/java/com/github/shynixn/petblocks/contract/Language.kt +++ b/src/main/java/com/github/shynixn/petblocks/contract/Language.kt @@ -4,7 +4,7 @@ import com.github.shynixn.mcutils.common.language.LanguageItem import com.github.shynixn.mcutils.common.language.LanguageProvider interface Language : LanguageProvider { - var playerNotFoundMessage: LanguageItem + var petNameChangeMessage: LanguageItem var templateNotFoundMessage: LanguageItem @@ -16,7 +16,7 @@ interface Language : LanguageProvider { var petDeletedMessage: LanguageItem - var petNameChangeMessage: LanguageItem + var playerNotFoundMessage: LanguageItem var petCalledMessage: LanguageItem diff --git a/src/main/java/com/github/shynixn/petblocks/impl/PetEntityImpl.kt b/src/main/java/com/github/shynixn/petblocks/impl/PetEntityImpl.kt index 8092de0b6..d3f28ccbb 100644 --- a/src/main/java/com/github/shynixn/petblocks/impl/PetEntityImpl.kt +++ b/src/main/java/com/github/shynixn/petblocks/impl/PetEntityImpl.kt @@ -9,6 +9,7 @@ import com.github.shynixn.mcutils.common.physic.PhysicObject import com.github.shynixn.mcutils.common.physic.PhysicObjectDispatcher import com.github.shynixn.mcutils.packet.api.PacketService import com.github.shynixn.mcutils.packet.api.RayTracingService +import com.github.shynixn.mcutils.packet.api.meta.enumeration.RidingMoveType import com.github.shynixn.mcutils.packet.api.packet.PacketOutEntityMount import com.github.shynixn.mcutils.pathfinder.api.PathfinderResult import com.github.shynixn.mcutils.pathfinder.api.PathfinderResultType @@ -59,6 +60,8 @@ class PetEntityImpl( private var cancellationTokenLongRunning = CancellationToken() private var lastRideUpdate = 0L private var lastSneakUpdate = 0L + private var ridingMoveType: RidingMoveType = RidingMoveType.STOP + var isBreakingBlock = false // Mover @@ -231,7 +234,7 @@ class PetEntityImpl( /** * Spawn is initiated. */ - fun onSpawn(player: Player){ + fun onSpawn(player: Player) { cancellationTokenLongRunning.isCancelled = true val spawnEvent = pet.template.events["spawn"] if (spawnEvent != null) { @@ -244,7 +247,7 @@ class PetEntityImpl( /** * Despawn is initiated. */ - fun onDespawn(player: Player){ + fun onDespawn(player: Player) { cancellationTokenLongRunning.isCancelled = true val despawnEvent = pet.template.events["despawn"] if (despawnEvent != null) { @@ -356,7 +359,7 @@ class PetEntityImpl( /** * Gets called when the player is riding the entity. */ - fun ride(player: Player, forward: Double, isJumping: Boolean, isSneaking: Boolean) { + fun ride(player: Player, moveType: RidingMoveType, isJumping: Boolean, isSneaking: Boolean) { cancellationTokenLongRunning.isCancelled = true val current = Date().time @@ -372,30 +375,42 @@ class PetEntityImpl( lastRideUpdate = current } - val isOnGround = if (isJumping) { - isOnGround(getLocation().toLocation()) - } else { - false + if (isJumping) { + if (isOnGround(getLocation().toLocation())) { + plugin.launch(physicObjectDispatcher) { + physicsComponent.motion.y = 1.0 + } + } + + return } - plugin.launch(physicObjectDispatcher) { - if (forward != 0.0) { - val movementVector = if (forward > 0.0) { - player.location.direction.normalize().multiply(0.5).toVector3d() - } else { - player.location.direction.normalize().multiply(-0.5).toVector3d() - } + if (this.ridingMoveType == RidingMoveType.STOP) { + this.ridingMoveType = moveType + plugin.launch(physicObjectDispatcher) { + while (!isDead && ridingMoveType != RidingMoveType.STOP) { + val movementVector = if (ridingMoveType == RidingMoveType.FORWARD) { + player.location.direction.normalize().multiply(0.5).toVector3d() + } else { + player.location.direction.normalize().multiply(-0.5).toVector3d() + } - physicsComponent.motion.x = movementVector.x - physicsComponent.motion.z = movementVector.z - } + physicsComponent.motion.x = movementVector.x + physicsComponent.motion.z = movementVector.z - if (isJumping && isOnGround) { - physicsComponent.motion.y = 1.0 + physicsComponent.position.pitch = 0.0 + physicsComponent.position.yaw = player.location.yaw.toDouble() + delay(5.ticks) + } } + } + + this.ridingMoveType = moveType - physicsComponent.position.pitch = 0.0 - physicsComponent.position.yaw = player.location.yaw.toDouble() + if (this.ridingMoveType == RidingMoveType.STOP) { + // Fast Stop. + physicsComponent.motion.x = 0.0 + physicsComponent.motion.z = 0.0 } if (isSneaking && current - lastSneakUpdate >= 200) { @@ -410,7 +425,12 @@ class PetEntityImpl( } private fun isOnGround(location: Location): Boolean { - val rayTraceResult = rayTracingService.rayTraceMotion(location.toVector3d(), Vector3d(0.0, -1.0, 0.0), petMeta.physics.collideWithWater, petMeta.physics.collideWithPassableBlocks) + val rayTraceResult = rayTracingService.rayTraceMotion( + location.toVector3d(), + Vector3d(0.0, -1.0, 0.0), + petMeta.physics.collideWithWater, + petMeta.physics.collideWithPassableBlocks + ) return rayTraceResult.hitBlock } @@ -496,7 +516,9 @@ class PetEntityImpl( val worldLocation = getLocation().toLocation() val rayTraceResult = rayTracingService.rayTraceMotion( worldLocation.toVector3d(), - worldLocation.direction.normalize().multiply(maxDistance).toVector3d(),petMeta.physics.collideWithWater, petMeta.physics.collideWithPassableBlocks + worldLocation.direction.normalize().multiply(maxDistance).toVector3d(), + petMeta.physics.collideWithWater, + petMeta.physics.collideWithPassableBlocks ) return rayTraceResult.block } diff --git a/src/main/java/com/github/shynixn/petblocks/impl/listener/PetListener.kt b/src/main/java/com/github/shynixn/petblocks/impl/listener/PetListener.kt index 94c6a6d79..6be68f497 100644 --- a/src/main/java/com/github/shynixn/petblocks/impl/listener/PetListener.kt +++ b/src/main/java/com/github/shynixn/petblocks/impl/listener/PetListener.kt @@ -9,9 +9,11 @@ import com.github.shynixn.mcutils.common.Version import com.github.shynixn.mcutils.common.physic.PhysicObjectService import com.github.shynixn.mcutils.packet.api.event.PacketAsyncEvent import com.github.shynixn.mcutils.packet.api.meta.enumeration.InteractionType -import com.github.shynixn.mcutils.packet.api.meta.enumeration.PacketVersion +import com.github.shynixn.mcutils.packet.api.meta.enumeration.RidingMoveType import com.github.shynixn.mcutils.packet.api.packet.PacketInInteractEntity -import com.github.shynixn.mcutils.packet.api.packet.PacketInSteerVehicle +import com.github.shynixn.mcutils.packet.api.packet.PacketInRideDismount +import com.github.shynixn.mcutils.packet.api.packet.PacketInRideJump +import com.github.shynixn.mcutils.packet.api.packet.PacketInRideMove import com.github.shynixn.petblocks.contract.PetActionExecutionService import com.github.shynixn.petblocks.contract.PetService import com.github.shynixn.petblocks.impl.PetEntityImpl @@ -19,7 +21,6 @@ import com.github.shynixn.petblocks.impl.service.PetActionExecutionServiceImpl import com.google.inject.Inject import kotlinx.coroutines.delay import org.bukkit.Bukkit -import org.bukkit.entity.Player import org.bukkit.event.EventHandler import org.bukkit.event.Listener import org.bukkit.event.player.PlayerJoinEvent @@ -36,7 +37,6 @@ class PetListener @Inject constructor( private val configurationService: ConfigurationService ) : Listener { private val petsToReceiveOnJoinKey = "pet.receivePetsOnJoin" - private val steerVehicleCache = HashMap() /** * Gets called when a player joins the server. @@ -78,7 +78,6 @@ class PetListener @Inject constructor( plugin.launch { petService.clearCache(event.player) } - steerVehicleCache.remove(event.player) } @EventHandler @@ -103,62 +102,29 @@ class PetListener @Inject constructor( fun onPacketEvent(event: PacketAsyncEvent) { val packet = event.packet - if (packet is PacketInSteerVehicle) { - val player = event.player + if (packet is PacketInRideJump) { + plugin.launch { + val physicObject = physicObjectService.findPhysicObjectById(packet.entityId) as PetEntityImpl? + physicObject?.ride(event.player, RidingMoveType.FORWARD, true, false) + } + return + } - if (packet.version == PacketVersion.V1) { - plugin.launch { - val physicObject = physicObjectService.findPhysicObjectById(packet.entityId) as PetEntityImpl? - physicObject?.ride(player, packet.forward, packet.isJumping, packet.isShift) - } - return + if (packet is PacketInRideDismount) { + plugin.launch { + val physicObject = physicObjectService.findPhysicObjectById(packet.entityId) as PetEntityImpl? + physicObject?.ride(event.player, RidingMoveType.STOP, false, true) } + return + } - if (packet.version == PacketVersion.V2) { + if (packet is PacketInRideMove) { + if (packet.moveType == RidingMoveType.FORWARD || packet.moveType == RidingMoveType.BACKWARD || packet.moveType == RidingMoveType.STOP) { plugin.launch { - val physicObject = - physicObjectService.findPhysicObjectById(packet.entityId) as PetEntityImpl? ?: return@launch - - if (steerVehicleCache.containsKey(player)) { - val vehicleDirection = steerVehicleCache[player] - - if (vehicleDirection == 1 && packet.isForwardMove) { - // Skip - } else if (vehicleDirection == 2 && packet.isForwardMove) { - // Skip - } else { - steerVehicleCache.remove(player) - } - } else { - if (packet.isForwardMove) { - steerVehicleCache[player] = 1 - plugin.launch { - while (player.isOnline && steerVehicleCache.contains(player) && physicObject.pet.isRiding()) { - physicObject.ride(player, 0.5, false, false) - delay(5.ticks) - } - } - } else if (packet.isBackWardMove) { - steerVehicleCache[player] = 2 - plugin.launch { - while (player.isOnline && steerVehicleCache.contains(player) && physicObject.pet.isRiding()) { - physicObject.ride(player, -0.5, false, false) - delay(5.ticks) - } - } - } - } - - if (packet.isShift) { - physicObject.ride(player, 0.0, false, true) - } - - if (packet.isJumping) { - physicObject.ride(player, 0.0, true, false) - } + val physicObject = physicObjectService.findPhysicObjectById(packet.entityId) as PetEntityImpl? + physicObject?.ride(event.player, packet.moveType, false, false) } } - return } From db289c10167013969df66757cde13c1edee43fb5 Mon Sep 17 00:00:00 2001 From: Shynixn Date: Fri, 22 Nov 2024 20:15:38 +0100 Subject: [PATCH 2/3] #627 Added riding speed property. --- docs/wiki/docs/commands.md | 12 ++++++ docs/wiki/docs/permission.md | 1 + .../petblocks/PetBlocksLanguageImpl.kt | 6 +++ .../shynixn/petblocks/contract/Language.kt | 4 ++ .../github/shynixn/petblocks/contract/Pet.kt | 5 +++ .../petblocks/entity/PhysicSettings.kt | 9 ++++- .../petblocks/enumeration/Permission.kt | 1 + .../shynixn/petblocks/impl/PetEntityImpl.kt | 38 +++++++++++-------- .../github/shynixn/petblocks/impl/PetImpl.kt | 13 ++++++- .../PetBlocksCommandExecutor.kt | 17 +++++++++ src/main/resources/lang/en_us.yml | 6 +++ src/main/resources/pets/pet_classic.yml | 2 + .../resources/pets/pet_flying_dolphin.yml | 2 + src/main/resources/pets/pet_mining.yml | 2 + 14 files changed, 99 insertions(+), 19 deletions(-) diff --git a/docs/wiki/docs/commands.md b/docs/wiki/docs/commands.md index 095726757..cf59fff5e 100644 --- a/docs/wiki/docs/commands.md +++ b/docs/wiki/docs/commands.md @@ -478,6 +478,18 @@ Changes the offset of the body of the entity to the ground. Useful when configur * Offset: A numeric comma value. e.g. 0.3, -0.3, 1.0 * Player: Optional player_name/player_UUID parameter targeting a player from the console or command block. +### /petblocks ridingspeed + +``` +/petblocks ridingspeed [player] +``` + +Changes the speed while riding a pet. + +* Name: Identifier of a pet +* Offset: A numeric comma value. e.g. 0.3, 0.5, 1.5 +* Player: Optional player_name/player_UUID parameter targeting a player from the console or command block. + ### /petblocks variable ``` diff --git a/docs/wiki/docs/permission.md b/docs/wiki/docs/permission.md index ebbd2cdd2..7856c92f3 100644 --- a/docs/wiki/docs/permission.md +++ b/docs/wiki/docs/permission.md @@ -68,6 +68,7 @@ The following permissions are available in PetBlocks. | petblocks.pet.entityType | Admin/User | Allows to use the /petblocks entitytype command | | petblocks.pet.entityVisibility | Admin/User | Allows to use the /petblocks entityvisible command | petblocks.pet.groundOffset | Admin/User | Allows to use the /petblocks groundOffset command +| petblocks.pet.ridingSpeed | Admin/User | Allows to use the /petblocks ridingspeed command | petblocks.pet.variable | Admin | Allows to use the /petblocks variable command | petblocks.pet.manipulateOther | Admin | Allows to manipulate the pets of other players. e.g. Changing skins, etc. | | petblocks.reload | Admin | Permission to use the /petblocks reload command. | diff --git a/src/main/java/com/github/shynixn/petblocks/PetBlocksLanguageImpl.kt b/src/main/java/com/github/shynixn/petblocks/PetBlocksLanguageImpl.kt index 5c11c964c..732d64a43 100644 --- a/src/main/java/com/github/shynixn/petblocks/PetBlocksLanguageImpl.kt +++ b/src/main/java/com/github/shynixn/petblocks/PetBlocksLanguageImpl.kt @@ -108,6 +108,12 @@ class PetBlocksLanguageImpl : Language, LanguageProviderImpl() { override var variableCommandHint = LanguageItem() override var variableChangedMessage = LanguageItem() override var velocityRelCommandHint = LanguageItem() + override var ridingSpeedChangedMessage = LanguageItem().also { + it.text = "[&9PetBlocks&f] The riding-speed of the pet has been changed." + } + override var ridingSpeedCommandHint = LanguageItem().also { + it.text = "Changes the speed while riding a pet." + } override val names: List get() = listOf("en_us", "es_es") diff --git a/src/main/java/com/github/shynixn/petblocks/contract/Language.kt b/src/main/java/com/github/shynixn/petblocks/contract/Language.kt index 1173f57d2..2faffb9ac 100644 --- a/src/main/java/com/github/shynixn/petblocks/contract/Language.kt +++ b/src/main/java/com/github/shynixn/petblocks/contract/Language.kt @@ -209,4 +209,8 @@ interface Language : LanguageProvider { var variableChangedMessage: LanguageItem var velocityRelCommandHint: LanguageItem + + var ridingSpeedChangedMessage: LanguageItem + + var ridingSpeedCommandHint: LanguageItem } diff --git a/src/main/java/com/github/shynixn/petblocks/contract/Pet.kt b/src/main/java/com/github/shynixn/petblocks/contract/Pet.kt index 6c9d28915..444367c5d 100644 --- a/src/main/java/com/github/shynixn/petblocks/contract/Pet.kt +++ b/src/main/java/com/github/shynixn/petblocks/contract/Pet.kt @@ -96,6 +96,11 @@ interface Pet { */ var groundOffset: Double + /** + * Riding speed. + */ + var ridingSpeed : Double + /** * Storage of arbitrary data in the pet. */ diff --git a/src/main/java/com/github/shynixn/petblocks/entity/PhysicSettings.kt b/src/main/java/com/github/shynixn/petblocks/entity/PhysicSettings.kt index 30d128656..a80bf932e 100644 --- a/src/main/java/com/github/shynixn/petblocks/entity/PhysicSettings.kt +++ b/src/main/java/com/github/shynixn/petblocks/entity/PhysicSettings.kt @@ -25,10 +25,15 @@ class PhysicSettings { /** * Collide With water. */ - var collideWithWater : Boolean = false + var collideWithWater: Boolean = false /** * Collide With passable Blocks. */ - var collideWithPassableBlocks : Boolean = false + var collideWithPassableBlocks: Boolean = false + + /** + * Riding speed of the pet. + */ + var ridingSpeed: Double = 0.5 } diff --git a/src/main/java/com/github/shynixn/petblocks/enumeration/Permission.kt b/src/main/java/com/github/shynixn/petblocks/enumeration/Permission.kt index a0cb394c6..ada7707e9 100644 --- a/src/main/java/com/github/shynixn/petblocks/enumeration/Permission.kt +++ b/src/main/java/com/github/shynixn/petblocks/enumeration/Permission.kt @@ -38,6 +38,7 @@ enum class Permission(val text: String) { ENTITYTYPE("petblocks.pet.entityType"), ENTITYVISIBILITY("petblocks.pet.entityVisibility"), GROUNDOFFSET("petblocks.pet.groundOffset"), + RIDINGSPEED("petblocks.pet.ridingSpeed"), VARIABLE("petblocks.pet.variable"), // Dynamic diff --git a/src/main/java/com/github/shynixn/petblocks/impl/PetEntityImpl.kt b/src/main/java/com/github/shynixn/petblocks/impl/PetEntityImpl.kt index d3f28ccbb..2b9ea1f43 100644 --- a/src/main/java/com/github/shynixn/petblocks/impl/PetEntityImpl.kt +++ b/src/main/java/com/github/shynixn/petblocks/impl/PetEntityImpl.kt @@ -362,25 +362,13 @@ class PetEntityImpl( fun ride(player: Player, moveType: RidingMoveType, isJumping: Boolean, isSneaking: Boolean) { cancellationTokenLongRunning.isCancelled = true - val current = Date().time - if (current - lastRideUpdate >= ridePositionUpdateMs) { - // Required so the position of the player stays in sync while packet riding. - packetService.setServerPlayerPosition(player, physicsComponent.position.toLocation()) - for (visiblePlayers in playerComponent.visiblePlayers) { - packetService.sendPacketOutEntityMount(visiblePlayers, PacketOutEntityMount().also { - it.entityId = entityComponent.entityId - it.passengers = listOf(player.entityId) - }) - } - lastRideUpdate = current - } - if (isJumping) { if (isOnGround(getLocation().toLocation())) { plugin.launch(physicObjectDispatcher) { physicsComponent.motion.y = 1.0 } } + synchronizeRidingState(player) return } @@ -388,11 +376,12 @@ class PetEntityImpl( if (this.ridingMoveType == RidingMoveType.STOP) { this.ridingMoveType = moveType plugin.launch(physicObjectDispatcher) { - while (!isDead && ridingMoveType != RidingMoveType.STOP) { + while (!isDead && ridingMoveType != RidingMoveType.STOP && player.isOnline) { + synchronizeRidingState(player) val movementVector = if (ridingMoveType == RidingMoveType.FORWARD) { - player.location.direction.normalize().multiply(0.5).toVector3d() + player.location.direction.normalize().multiply(petMeta.physics.ridingSpeed).toVector3d() } else { - player.location.direction.normalize().multiply(-0.5).toVector3d() + player.location.direction.normalize().multiply(petMeta.physics.ridingSpeed * -1).toVector3d() } physicsComponent.motion.x = movementVector.x @@ -413,6 +402,8 @@ class PetEntityImpl( physicsComponent.motion.z = 0.0 } + val current = System.currentTimeMillis() + if (isSneaking && current - lastSneakUpdate >= 200) { lastSneakUpdate = current val sneakEvent = pet.template.events["ridingSneak"] @@ -424,6 +415,21 @@ class PetEntityImpl( } } + private fun synchronizeRidingState(player: Player) { + val current = Date().time + if (current - lastRideUpdate >= ridePositionUpdateMs) { + // Required so the position of the player stays in sync while packet riding. + packetService.setServerPlayerPosition(player, physicsComponent.position.toLocation()) + for (visiblePlayers in playerComponent.visiblePlayers) { + packetService.sendPacketOutEntityMount(visiblePlayers, PacketOutEntityMount().also { + it.entityId = entityComponent.entityId + it.passengers = listOf(player.entityId) + }) + } + lastRideUpdate = current + } + } + private fun isOnGround(location: Location): Boolean { val rayTraceResult = rayTracingService.rayTraceMotion( location.toVector3d(), diff --git a/src/main/java/com/github/shynixn/petblocks/impl/PetImpl.kt b/src/main/java/com/github/shynixn/petblocks/impl/PetImpl.kt index 8b18c6215..0e0cc456a 100644 --- a/src/main/java/com/github/shynixn/petblocks/impl/PetImpl.kt +++ b/src/main/java/com/github/shynixn/petblocks/impl/PetImpl.kt @@ -40,7 +40,7 @@ class PetImpl( private var petEntity: PetEntityImpl? = null private var disposed = false private var templateCache: PetTemplate? = null - private var isWorldTransferActive : Boolean = false + private var isWorldTransferActive: Boolean = false init { plugin.launch(plugin.minecraftDispatcher + object : CoroutineTimings() {}) { @@ -295,6 +295,17 @@ class PetImpl( location = location // Triggers teleport. } + /** + * Riding speed. + */ + override var ridingSpeed: Double + get() { + return petMeta.physics.ridingSpeed + } + set(value) { + petMeta.physics.ridingSpeed = value + } + /** * Storage of arbitrary data in the pet. */ diff --git a/src/main/java/com/github/shynixn/petblocks/impl/commandexecutor/PetBlocksCommandExecutor.kt b/src/main/java/com/github/shynixn/petblocks/impl/commandexecutor/PetBlocksCommandExecutor.kt index cd6289ac0..d3e85c974 100644 --- a/src/main/java/com/github/shynixn/petblocks/impl/commandexecutor/PetBlocksCommandExecutor.kt +++ b/src/main/java/com/github/shynixn/petblocks/impl/commandexecutor/PetBlocksCommandExecutor.kt @@ -737,6 +737,18 @@ class PetBlocksCommandExecutor @Inject constructor( setGroundOffset(commandSender, petMustExist(player, name), offset) } } + subCommand("ridingspeed") { + permission(Permission.RIDINGSPEED) + toolTip { language.ridingSpeedCommandHint.text } + builder().argument("name").tabs(petNamesTabs).argument("speed").validator(mustBeDouble) + .tabs { listOf("") }.executePlayer(senderHasToBePlayer) { player, name, speed -> + setRidingSpeed(player, petMustExist(player, name), speed) + }.argument("player").validator(playerMustExist).tabs(onlinePlayerTabs) + .permission(manipulateOtherPermission).permissionMessage(manipulateOtherPermissionMessage) + .execute { commandSender, name, speed, player -> + setRidingSpeed(commandSender, petMustExist(player, name), speed) + } + } subCommand("snap") { permission(Permission.SNAP) toolTip { language.snapCommandHint.text } @@ -792,6 +804,11 @@ class PetBlocksCommandExecutor @Inject constructor( commandBuilder.build() } + private fun setRidingSpeed(sender: CommandSender, pet: Pet, speed: Double) { + pet.ridingSpeed = speed + language.sendMessage(language.ridingSpeedChangedMessage, sender, speed) + } + private suspend fun createPet( sender: CommandSender, player: Player, petName: String, petTemplate: PetTemplate ) { diff --git a/src/main/resources/lang/en_us.yml b/src/main/resources/lang/en_us.yml index 4878b2ad7..7e95f5b11 100644 --- a/src/main/resources/lang/en_us.yml +++ b/src/main/resources/lang/en_us.yml @@ -319,3 +319,9 @@ variableChangedMessage: velocityRelCommandHint: type: "CHAT" text: "Launches the pet into the current looking direction with the given multipliers." +ridingSpeedChangedMessage: + type: "CHAT" + text: "[&9PetBlocks&f] The riding-speed of the pet has been changed." +ridingSpeedCommandHint: + type: "CHAT" + text: "Changes the speed while riding a pet." diff --git a/src/main/resources/pets/pet_classic.yml b/src/main/resources/pets/pet_classic.yml index 594edd241..bb77c55fe 100644 --- a/src/main/resources/pets/pet_classic.yml +++ b/src/main/resources/pets/pet_classic.yml @@ -49,6 +49,8 @@ pet: collideWithWater: false # Should the pet run through blocks like cobweb? collideWithPassableBlocks: false + # The speed while riding a pet. + ridingSpeed: 0.5 # # Defines the action a pet should perform on certain events. diff --git a/src/main/resources/pets/pet_flying_dolphin.yml b/src/main/resources/pets/pet_flying_dolphin.yml index 9d35c7f45..59aa44cc0 100644 --- a/src/main/resources/pets/pet_flying_dolphin.yml +++ b/src/main/resources/pets/pet_flying_dolphin.yml @@ -49,6 +49,8 @@ pet: collideWithWater: false # Should the pet run through blocks like cobweb? collideWithPassableBlocks: false + # The speed while riding a pet. + ridingSpeed: 0.5 # # Defines the action a pet should perform on certain events. diff --git a/src/main/resources/pets/pet_mining.yml b/src/main/resources/pets/pet_mining.yml index 35c94a9ef..67ecc7e9e 100644 --- a/src/main/resources/pets/pet_mining.yml +++ b/src/main/resources/pets/pet_mining.yml @@ -49,6 +49,8 @@ pet: collideWithWater: false # Should the pet run through blocks like cobweb? collideWithPassableBlocks: false + # The speed while riding a pet. + ridingSpeed: 0.5 # # Defines the action a pet should perform on certain events. From 2cfd25c7d7472eadace64da7b5b76a1f14e55cbf Mon Sep 17 00:00:00 2001 From: Shynixn Date: Fri, 22 Nov 2024 20:44:18 +0100 Subject: [PATCH 3/3] #632 Fixed riding state and calling of ride command position. --- build.gradle.kts | 2 +- .../com/github/shynixn/petblocks/impl/PetEntityImpl.kt | 2 +- .../java/com/github/shynixn/petblocks/impl/PetImpl.kt | 9 ++++++++- src/main/resources/plugin-legacy.yml | 2 +- src/main/resources/plugin.yml | 2 +- 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index aa3a71382..baa29eac9 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,7 +9,7 @@ plugins { } group = "com.github.shynixn" -version = "9.16.0" +version = "9.17.0" repositories { mavenCentral() diff --git a/src/main/java/com/github/shynixn/petblocks/impl/PetEntityImpl.kt b/src/main/java/com/github/shynixn/petblocks/impl/PetEntityImpl.kt index 2b9ea1f43..26a62f4b4 100644 --- a/src/main/java/com/github/shynixn/petblocks/impl/PetEntityImpl.kt +++ b/src/main/java/com/github/shynixn/petblocks/impl/PetEntityImpl.kt @@ -376,7 +376,7 @@ class PetEntityImpl( if (this.ridingMoveType == RidingMoveType.STOP) { this.ridingMoveType = moveType plugin.launch(physicObjectDispatcher) { - while (!isDead && ridingMoveType != RidingMoveType.STOP && player.isOnline) { + while (!isDead && ridingMoveType != RidingMoveType.STOP && player.isOnline && pet.isRiding()) { synchronizeRidingState(player) val movementVector = if (ridingMoveType == RidingMoveType.FORWARD) { player.location.direction.normalize().multiply(petMeta.physics.ridingSpeed).toVector3d() diff --git a/src/main/java/com/github/shynixn/petblocks/impl/PetImpl.kt b/src/main/java/com/github/shynixn/petblocks/impl/PetImpl.kt index 0e0cc456a..ad64c801d 100644 --- a/src/main/java/com/github/shynixn/petblocks/impl/PetImpl.kt +++ b/src/main/java/com/github/shynixn/petblocks/impl/PetImpl.kt @@ -3,6 +3,7 @@ package com.github.shynixn.petblocks.impl import com.github.shynixn.mccoroutine.bukkit.CoroutineTimings import com.github.shynixn.mccoroutine.bukkit.launch import com.github.shynixn.mccoroutine.bukkit.minecraftDispatcher +import com.github.shynixn.mccoroutine.bukkit.ticks import com.github.shynixn.mcutils.common.* import com.github.shynixn.mcutils.common.item.Item import com.github.shynixn.mcutils.common.item.ItemService @@ -430,7 +431,13 @@ class PetImpl( call() petMeta.ridingState = PetRidingState.GROUND - petEntity?.updateRidingState() + + plugin.launch { + val location = player.location.toVector3d() + petEntity?.updateRidingState() + delay(3.ticks) + petEntity?.teleportInWorld(location) // Correct riding position. + } } /** diff --git a/src/main/resources/plugin-legacy.yml b/src/main/resources/plugin-legacy.yml index 489651070..b439cd989 100644 --- a/src/main/resources/plugin-legacy.yml +++ b/src/main/resources/plugin-legacy.yml @@ -1,5 +1,5 @@ name: PetBlocks -version: 9.16.0 +version: 9.17.0 author: Shynixn main: com.github.shynixn.petblocks.PetBlocksPlugin softdepend: [ PlaceholderAPI, HeadDatabase] diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index a77d4d261..0c53fc6cd 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: PetBlocks -version: 9.16.0 +version: 9.17.0 author: Shynixn main: com.github.shynixn.petblocks.PetBlocksPlugin softdepend: [ PlaceholderAPI, HeadDatabase]