override gravity in entity when in spectator gamemode

This commit is contained in:
Bixilon 2021-05-01 14:02:01 +02:00
parent 02db2d7ba9
commit aa20dc3441
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
3 changed files with 13 additions and 5 deletions

View File

@ -37,7 +37,7 @@ class MultiAssetsManager(
throw IllegalArgumentException("Can not add ourself!") throw IllegalArgumentException("Can not add ourself!")
} }
for (namespace in assetsManager.namespaces) { for (namespace in assetsManager.namespaces) {
this.assetsManagers.getOrPut(namespace, { mutableListOf() }).add(assetsManager) this.assetsManagers.getOrPut(namespace) { mutableListOf() }.add(assetsManager)
} }
} }

View File

@ -136,9 +136,9 @@ abstract class Entity(
val isSilent: Boolean val isSilent: Boolean
get() = entityMetaData.sets.getBoolean(EntityMetaDataFields.ENTITY_SILENT) get() = entityMetaData.sets.getBoolean(EntityMetaDataFields.ENTITY_SILENT)
@EntityMetaDataFunction(name = "Has no gravity") @EntityMetaDataFunction(name = "Has gravity")
val hasNoGravity: Boolean open val hasGravity: Boolean
get() = entityMetaData.sets.getBoolean(EntityMetaDataFields.ENTITY_NO_GRAVITY) get() = !entityMetaData.sets.getBoolean(EntityMetaDataFields.ENTITY_NO_GRAVITY)
@get:EntityMetaDataFunction(name = "Pose") @get:EntityMetaDataFunction(name = "Pose")
val pose: Poses? val pose: Poses?
@ -275,7 +275,7 @@ abstract class Entity(
val newVelocity = Vec3(velocity) val newVelocity = Vec3(velocity)
val oldVelocity = Vec3(velocity) val oldVelocity = Vec3(velocity)
val deltaTime = deltaMillis.toFloat() / 1000.0f val deltaTime = deltaMillis.toFloat() / 1000.0f
if (! hasNoGravity && !isFlying) { if (hasGravity && !isFlying) {
newVelocity.y -= ProtocolDefinition.GRAVITY * deltaTime newVelocity.y -= ProtocolDefinition.GRAVITY * deltaTime
} }
newVelocity *= 0.25f.pow(deltaTime) // apply newVelocity *= 0.25f.pow(deltaTime) // apply

View File

@ -48,6 +48,14 @@ class PlayerEntity(
override val hasCollisions: Boolean override val hasCollisions: Boolean
get() = gamemode != Gamemodes.SPECTATOR get() = gamemode != Gamemodes.SPECTATOR
override val hasGravity: Boolean
get() {
if (gamemode == Gamemodes.SPECTATOR) {
return false
}
return super.hasGravity
}
public override val isFlying: Boolean public override val isFlying: Boolean
get() = !hasCollisions || gamemode == Gamemodes.CREATIVE get() = !hasCollisions || gamemode == Gamemodes.CREATIVE