Don't tick hunger, breath and swimming if spectator

This commit is contained in:
DBotThePony 2022-10-10 18:05:43 +07:00
parent 313a14f8d9
commit 6f9c9edac1
Signed by: DBot
GPG Key ID: DCC23B5715498507
2 changed files with 26 additions and 21 deletions

View File

@ -625,17 +625,18 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial
}
if (isAndroid) {
if (ply.airSupply < ply.maxAirSupply)
if (!ply.isSpectator && ply.airSupply < ply.maxAirSupply)
ply.airSupply = ply.maxAirSupply
// TODO: Maybe passive drain?
// extractEnergyInner(BigDecimal.valueOf(new Random().nextDouble()), false);
if (ply.isSwimming && !hasFeature(AndroidFeatures.AIR_BAGS)) {
if (!ply.isSpectator && ply.isSwimming && !hasFeature(AndroidFeatures.AIR_BAGS)) {
ply.isSwimming = false
}
androidEnergy.tick()
if (!ply.isSpectator) {
val stats = ply.foodData
while (stats.foodLevel < 18 && androidEnergy.extractEnergyInner(ServerConfig.ANDROID_ENERGY_PER_HUNGER_POINT, true) >= ServerConfig.ANDROID_ENERGY_PER_HUNGER_POINT) {
@ -661,6 +662,7 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial
val extracted = androidEnergy.extractEnergyInner(ServerConfig.ANDROID_ENERGY_PER_HUNGER_POINT * (stats.exhaustionLevel / 4f), false)
stats.setExhaustion(stats.exhaustionLevel - (extracted / ServerConfig.ANDROID_ENERGY_PER_HUNGER_POINT).toFloat() * 4f)
}
}
for (feature in featureMap.values) {
feature.tickServer()

View File

@ -21,6 +21,9 @@ fun onMovementInputUpdate(event: MovementInputUpdateEvent) {
val ply = event.entity
val input = event.input
if (ply.isCreative || ply.isSpectator)
return
val cap = ply.matteryPlayer ?: return
if (cap.isAndroid) {