Skip to content

Commit

Permalink
fix: make CLIMBABLE blocks calculate fallDistance
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Jan 14, 2024
1 parent fa76a00 commit c5dc501
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.ticxo.modelengine.api.model.bone.manager.BehaviorManager
import com.ticxo.modelengine.api.model.bone.manager.MountManager
import org.bukkit.Bukkit
import org.bukkit.Location
import org.bukkit.Tag
import org.bukkit.block.Block
import org.bukkit.block.data.Levelled
import org.bukkit.block.data.type.BubbleColumn
Expand Down Expand Up @@ -84,3 +85,5 @@ fun BukkitEntity.getMountManager() : MountManagerWithBehavior<*>? {
mountManager as BehaviorManager<*>
)
}

val Player.isInClimbable get() = location.block.type in Tag.CLIMBABLE.values
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import io.papermc.paper.event.entity.EntityMoveEvent
import org.bukkit.GameMode
import org.bukkit.Material
import org.bukkit.Particle
import org.bukkit.Tag
import org.bukkit.block.BlockFace
import org.bukkit.block.data.type.Bed
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
Expand Down Expand Up @@ -35,12 +37,12 @@ internal object MoveListener : Listener {

@EventHandler
fun EntityDamageEvent.onPlayerDamage() {
val player = entity as? Player ?: return
if (this is BoneHurtDamageEvent) return
if (cause != EntityDamageEvent.DamageCause.FALL) return

if (entity is Player && cause == EntityDamageEvent.DamageCause.FALL) {
isCancelled = true
(entity as Player).hurtBones(0f)
}
isCancelled = true
player.hurtBones(0f)
}

@EventHandler
Expand All @@ -51,11 +53,10 @@ internal object MoveListener : Listener {

@EventHandler
fun EntityMoveEvent.entityMove() {
if (entity.passengers.isNotEmpty()) {
entity.passengers.filterIsInstance<Player>().forEach { rider ->
rider.fallDistance = entity.fallDistance
rider.hurtBones(entity.fallDistance)
}
if (entity.passengers.isEmpty()) return
entity.passengers.filterIsInstance<Player>().forEach { rider ->
rider.fallDistance = entity.fallDistance
rider.hurtBones(entity.fallDistance)
}
}

Expand All @@ -64,15 +65,32 @@ internal object MoveListener : Listener {
if (player.gameMode == GameMode.CREATIVE) return
if (this.cause != PlayerTeleportEvent.TeleportCause.ENDER_PEARL && this.cause != PlayerTeleportEvent.TeleportCause.CHORUS_FRUIT) return
if (this.isCancelled) return //Cancels the falldamage if another plugin cancels the event.

val teleportDistance = player.location.y - to.toBlockLocation().y
if (teleportDistance <= 0) return
player.fallDistance = teleportDistance.toFloat()
player.hurtBones(player.fallDistance)
}

private val climbableMap = mutableMapOf<UUID, Float>()
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
fun PlayerMoveEvent.onScaleDownClimbable() {
if (!hasExplicitlyChangedBlock()) return
if (!player.isInClimbable) return

climbableMap.compute(player.uniqueId) { _, v -> (v ?: 0).toFloat() + 1 }
when (player.location.block.getRelative(BlockFace.DOWN).type) {
!in Tag.CLIMBABLE.values -> {
player.hurtBones(climbableMap[player.uniqueId] ?: 0f)
}
else -> {}
}
}

@EventHandler
fun PlayerMoveEvent.playerMove() {
if (player.gameMode != GameMode.SURVIVAL && player.gameMode != GameMode.ADVENTURE) return
if (!hasExplicitlyChangedBlock()) return

if (!player.isInsideVehicle)
player.hurtBones(player.fallDistance)
Expand Down Expand Up @@ -100,8 +118,7 @@ internal object MoveListener : Listener {
}
}
player.location.findLocationAround(radius = 1, scale = 0.30) {
val higherBlock = it.add(0.0, 4.0, 0.0).block
higherBlock.isBubbleColumn
it.clone().add(0.0, 4.0, 0.0).block.isBubbleColumn
}?.let {
if (player.maximumAir <= 0) {
player.remainingAir = player.remainingAir
Expand Down

0 comments on commit c5dc501

Please sign in to comment.