physics: use abilities walking speed

This commit is contained in:
Bixilon 2021-06-06 16:10:12 +02:00 committed by Lukas
parent 1824bbbe5c
commit 0a22ff34e0
3 changed files with 8 additions and 10 deletions

View File

@ -117,9 +117,8 @@ abstract class Entity(
activeStatusEffects.remove(effect) activeStatusEffects.remove(effect)
} }
fun getAttributeValue(attribute: ResourceLocation): Double { fun getAttributeValue(attribute: ResourceLocation, baseValue: Double = entityType.attributes[attribute] ?: 1.0): Double {
// ToDo: Check order and verify value // ToDo: Check order and verify value
val baseValue = entityType.attributes[attribute] ?: 1.0
var ret = baseValue var ret = baseValue
fun addToValue(statusEffectAttribute: StatusEffectAttribute, amplifier: Int) { fun addToValue(statusEffectAttribute: StatusEffectAttribute, amplifier: Int) {

View File

@ -19,6 +19,6 @@ data class Abilities(
var canFly: Boolean = false, var canFly: Boolean = false,
var canInstantBreak: Boolean = false, var canInstantBreak: Boolean = false,
var flyingSpeed: Double = 1.0, var flyingSpeed: Double = 0.05,
var walkingSpeed: Double = 1.0, var walkingSpeed: Double = 0.1,
) )

View File

@ -83,8 +83,8 @@ class LocalPlayerEntity(
private var flyingSpeed = 0.02 private var flyingSpeed = 0.02
val movementSpeed: Double private val walkingSpeed: Double
get() = getAttributeValue(DefaultStatusEffectAttributeNames.GENERIC_MOVEMENT_SPEED) get() = getAttributeValue(DefaultStatusEffectAttributeNames.GENERIC_MOVEMENT_SPEED, baseAbilities.walkingSpeed)
private var horizontalCollision = false private var horizontalCollision = false
private var verticalCollision = false private var verticalCollision = false
@ -103,13 +103,12 @@ class LocalPlayerEntity(
override val hasGravity: Boolean override val hasGravity: Boolean
get() = !baseAbilities.isFlying get() = !baseAbilities.isFlying
private val slowMovement: Boolean private val slowMovement: Boolean
get() = isSneaking // ToDo: Or should leave swimming pose get() = isSneaking // ToDo: Or should leave swimming pose
private val isUsingItem = false // ToDo: Not yet implemented private val isUsingItem = false // ToDo: Not yet implemented
val canSprint: Boolean private val canSprint: Boolean
get() = healthCondition.hunger >= PhysicsConstants.SPRINT_MINIMUM_HUNGER || baseAbilities.canFly || (gamemode == Gamemodes.CREATIVE || gamemode == Gamemodes.SPECTATOR) get() = healthCondition.hunger >= PhysicsConstants.SPRINT_MINIMUM_HUNGER || baseAbilities.canFly || (gamemode == Gamemodes.CREATIVE || gamemode == Gamemodes.SPECTATOR)
@ -195,7 +194,7 @@ class LocalPlayerEntity(
private fun slipperinessToMovementSpeed(slipperiness: Double): Double { private fun slipperinessToMovementSpeed(slipperiness: Double): Double {
if (onGround) { if (onGround) {
return movementSpeed * (0.21600002 / (slipperiness.pow(3))) return walkingSpeed * (0.21600002 / (slipperiness.pow(3)))
} }
return flyingSpeed return flyingSpeed
} }
@ -464,6 +463,6 @@ class LocalPlayerEntity(
sendMovementPackets() sendMovementPackets()
lastFovMultiplier = currentFovMultiplier lastFovMultiplier = currentFovMultiplier
currentFovMultiplier = MMath.clamp(1.0 + movementSpeed, 1.0, 1.5) currentFovMultiplier = MMath.clamp(1.0 + walkingSpeed, 1.0, 1.5)
} }
} }