From a72f2aabb2f9a82d5070242d2110b541fa0f17d7 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Thu, 4 Jan 2024 16:57:10 +0700 Subject: [PATCH] Make underwater travel challenge account for displacement, and not distance --- .../otm/capability/MatteryPlayerCapability.kt | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/capability/MatteryPlayerCapability.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/capability/MatteryPlayerCapability.kt index cddfee6e0..8e6479d46 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/capability/MatteryPlayerCapability.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/capability/MatteryPlayerCapability.kt @@ -459,7 +459,8 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial var ticksIExist = 0 private set - private var lastOutsideLiquid = Vec3(0.0, 0.0, 0.0) + private var lastLiquidPosition = Vec3(0.0, 0.0, 0.0) + private var liquidDistanceTravelled = 0.0 private var wasInLiquid = false private var lastDimension = ResourceLocation("overworld") @@ -591,8 +592,9 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial savetables.int(::nextDischargeHurt) savetables.int(::nextHealTick) - savetables.vector(::lastOutsideLiquid) + savetables.vector(::lastLiquidPosition) savetables.codec(::lastDimension, ResourceLocation.CODEC) + savetables.double(::liquidDistanceTravelled) savetables.stateful(::exopackSlotModifier, "exoSuitSlotCountModifiers") savetables.stateful(::exopackContainer, "exoSuitContainer") @@ -664,7 +666,7 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial androidEnergy.batteryLevel = AndroidConfig.ANDROID_MAX_ENERGY androidEnergy.maxBatteryLevel = AndroidConfig.ANDROID_MAX_ENERGY - lastOutsideLiquid = ply.position() + lastLiquidPosition = ply.position() wasInLiquid = false if (ply is ServerPlayer) { @@ -719,7 +721,7 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial androidEnergy.maxBatteryLevel = AndroidConfig.ANDROID_MAX_ENERGY dropBattery() - lastOutsideLiquid = ply.position() + lastLiquidPosition = ply.position() wasInLiquid = false if (ply is ServerPlayer) { @@ -1193,31 +1195,38 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial if (ply.airSupply < ply.maxAirSupply) ply.airSupply = ply.maxAirSupply - if (ply.isSwimming && !hasFeature(AndroidFeatures.AIR_BAGS)) + if (ply.isSwimming && !hasFeature(AndroidFeatures.AIR_BAGS) && !ply.isCreative) ply.isSwimming = false if (ply is ServerPlayer) { if (ply.level().dimension().location() != lastDimension) { lastDimension = ply.level().dimension().location() wasInLiquid = false - lastOutsideLiquid = ply.position + lastLiquidPosition = ply.position + liquidDistanceTravelled = 0.0 } - if (ply.isUnderWater && !ply.isCreative) { + if (ply.isUnderWater) { if (!wasInLiquid) { wasInLiquid = true - lastOutsideLiquid = ply.position + liquidDistanceTravelled = 0.0 + lastLiquidPosition = ply.position } + + liquidDistanceTravelled += (ply.position - lastLiquidPosition).length() } else { if (wasInLiquid) { wasInLiquid = false - if (!hasFeature(AndroidFeatures.AIR_BAGS)) - AndroidTravelUnderwater.trigger(ply, (lastOutsideLiquid - ply.position).length()) + if (!hasFeature(AndroidFeatures.AIR_BAGS)) { + AndroidTravelUnderwater.trigger(ply, liquidDistanceTravelled) + } } - lastOutsideLiquid = ply.position + liquidDistanceTravelled = 0.0 } + + lastLiquidPosition = ply.position } val stats = ply.foodData