Make underwater travel challenge account for displacement, and not distance

This commit is contained in:
DBotThePony 2024-01-04 16:57:10 +07:00
parent ebafdbc925
commit a72f2aabb2
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -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